guibranco / GuiStracini.Mandae

🇧🇷🚚 Mandaê API .NET client wrapper
https://guibranco.github.io/GuiStracini.Mandae/
MIT License
2 stars 0 forks source link

[FEATURE] Increase unit and integration test coverage #114

Open guibranco opened 10 months ago

guibranco commented 10 months ago

Description

The current C# HTTP client library needs improved test coverage to ensure robustness and catch edge cases. This includes both unit tests and integration tests that cover a wider range of scenarios.

Objective

Tasks

  1. Unit Tests:

    • Use XUnit for writing the test cases.
    • Use NSubstitute for mocking internal dependencies.
    • Use FluentAssertions for asserting results and better readability.
    • Utilize Snapshooter for snapshot testing and result comparisons to ensure consistent responses over time.
  2. Integration Tests:

    • Use WireMock to mock HTTP requests and simulate different responses from external services (success, failures, timeouts).
    • Write integration tests that simulate real-world scenarios with the library making requests to mocked endpoints.

Requirements:

Test Strategy:

Example:

public class HttpClientTests
{
    private readonly IExternalService _mockService = Substitute.For<IExternalService>();

    [Fact]
    public async Task Should_Return_Correct_Response_On_Success()
    {
        // Arrange
        var expectedResponse = new ApiResponse { ... };
        var client = new HttpClient(_mockService);

        _mockService
            .GetAsync(Arg.Any<string>())
            .Returns(Task.FromResult(expectedResponse));

        // Act
        var result = await client.GetDataAsync();

        // Assert
        result.Should().BeEquivalentTo(expectedResponse);
        Snapshot.Match(result);  // Snapshooter for result comparison
    }
}

Additional Notes:

Deliverables:

gitauto-ai[bot] commented 3 weeks ago

Sorry, we have an error. Please try again.

Have feedback or need help? Feel free to email info@gitauto.ai.