Skip to content

Conversation

raffreitas
Copy link

@raffreitas raffreitas commented Sep 1, 2025

What does this PR do?

This PR introduces a new Mockaco module, providing HTTP mock server capabilities for integration testing.

Why is it important?

Mockaco (official project) is a popular HTTP mock server that's widely used in .NET integration testing scenarios. This module fills a gap in the Testcontainers.NET ecosystem by providing:

  1. Mock verification capabilities: Developers can verify that their applications made the expected HTTP calls during tests
  2. Integration testing support: Enables testing of HTTP client behavior without relying on external services
  3. Test isolation: Each test can have its own mock server instance with independent verification data
  4. Developer productivity: Simplifies setup and teardown of HTTP mocks in containerized test environments

The verification functionality is particularly valuable for testing:

  • API integrations
  • HTTP client implementations
  • Service-to-service communication
  • Request/response validation in microservices

Template-based configuration: Mockaco uses JSON template files to define mock endpoints, providing flexibility and easy maintenance of mock definitions.

How to test this PR

  1. Build the solution:

    .\build.ps1
  2. Run specific Mockaco tests:

    dotnet test tests/Testcontainers.Mockaco.Tests/ -v normal
  3. Create a template file (required for Mockaco to work):

     // ./templates/ping-pong.json
     {
       "request": {
         "method": "GET",
         "route": "ping"
       },
       "response": {
         "status": "OK",
         "body": {
           "response": "pong"
         }
       }
     }
  4. Test verification functionality:

    // Example usage from the test suite
    var container = new MockacoBuilder()
        .WithTemplatesPath("./templates")
        .Build();
    await container.StartAsync();
    
    // Make HTTP calls to the mock server
    var httpClient = new HttpClient();
    await httpClient.GetAsync(container.GetBaseAddress() + "/ping");
    
    // Verify the calls were made
    var verification = await container.GetVerifyAsync("/ping");
    Assert.NotNull(verification);
    Assert.Equal("/ping", verification.Route);
    Assert.Contains("pong", verification.Body)
  5. Check documentation:
    Review docs/modules/mockaco.md for usage examples and template setup
    Verify examples work with the implementation

- Add MockacoContainer with GetVerifyAsync method for verification retrieval
- Include MockacoVerificationResponse and MockacoHeader classes
- Add comprehensive test suite with 16 tests covering all functionality
- Add complete module documentation following project standards
- Support .NET Standard 2.0/2.1, .NET 8.0/9.0 compatibility

The Mockaco module provides HTTP mock server capabilities with
verification support for testing HTTP interactions and validating
mock behavior in integration tests.
Copy link

netlify bot commented Sep 1, 2025

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit da1566b
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/68dd9ae8e61d3300088f50ec
😎 Deploy Preview https://deploy-preview-1521--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@raffreitas raffreitas changed the title feat: add Mockaco module with verification support feat: add Mockaco module Sep 1, 2025
@HofmeisterAn HofmeisterAn added module An official Testcontainers module enhancement New feature or request labels Sep 21, 2025
@HofmeisterAn HofmeisterAn force-pushed the develop branch 3 times, most recently from 4900ecd to 8fa5f1b Compare October 3, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module An official Testcontainers module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants