Releases: Adolfok3/Fresp
Releases · Adolfok3/Fresp
Release list
3.1.1
[3.1.1]
Fixed
- Disposal of the original response when replaced by a
FromResponsefake. When aFromResponsehandler returned a newHttpResponseMessage, the original response (and itsHttpContent) was abandoned without being disposed, leaving underlying resources alive until garbage collection. The original response is now disposed as soon as it is replaced (unless the fake returns the same instance). See #8.- Thanks to @rodri-oliveira-dev for reporting the issue. 🙏
3.1.0
3.1.0
Added
FakeHttpClientfactory for unit testing. New public static classFakeHttpClientthat creates anHttpClient(FakeHttpClient.Create) or its underlyingHttpMessageHandler(FakeHttpClient.CreateHandler) already wired with fake responses — with no need for dependency injection,IHostEnvironment, orIHttpClientBuilder. This makes it possible to fake external APIs consumed through anHttpClientdirectly in unit tests, instead of mocking the API interface.- Fakes are enabled by default in the factory.
- Fakes are configured exactly like during application execution: all
FromRequest/FromResponsemethods (sync and async) and the class-basedIFakeResponseFrom*interfaces are supported. - Optional
serviceProviderparameter, passed through to the fake handlers so fakes can resolve services via DI. When omitted, an empty provider (that always returnsnull) is used. - Optional
defaultResponseparameter that simulates the "real" external API response when noFromRequestfake matches — enablingFromResponsefakes and status-code assertions. - Requests that don't match any fake throw a descriptive
InvalidOperationExceptionby default, so unexpected calls fail tests loudly. - Verified to work with typed clients, a mocked
IHttpClientFactory, and Refit-generated clients.
Documentation
- Added a "Using Fresp in unit tests" section to the README covering the
FakeHttpClientfactory, dependency injection, unmatched-request behavior, usage with a mockedIHttpClientFactory, and Refit integration.
Changed
- Updated dependencies:
- .NET 10 target:
Microsoft.Extensions.HttpandMicrosoft.Extensions.Hosting.Abstractions10.0.2→10.0.11. - .NET 9 target:
Microsoft.Extensions.HttpandMicrosoft.Extensions.Hosting.Abstractions9.0.11→9.0.19. - .NET 8 target: unchanged (
8.0.1).
- .NET 10 target:
Notes
- No breaking changes. Existing application-execution usage (
AddFakeHandleronIHttpClientBuilder) is unchanged.