UnitTestEx provides .NET testing extensions to the most popular testing frameworks (MSTest, NUnit and Xunit) specifically to improve the testing experience with ASP.NET controller, and Azure Function, execution including underlying HttpClientFactory mocking.
Enhancement: Any configuration specified as part of registering the HttpClient services from a Dependency Injection (DI) perspective is ignored by default when creating an HttpClient using the MockHttpClientFactory. This default behavior is intended to potentially minimize any side-effect behavior that may occur that is not intended for the unit testing. See README for more details on capabilities introduced; highlights are:
New MockHttpClient.WithConfigurations method indicates that the HttpMessageHandler and HttpClient configurations are to be used.
New MockHttpClient.WithoutMocking method indicates that the underlying HttpClient is not to be mocked; i.e. will result in an actual/real HTTP request to the specified endpoint. This will allow the mixing of real and mocked HTTP requests within the same test.
HttpClient
services from a Dependency Injection (DI) perspective is ignored by default when creating anHttpClient
using theMockHttpClientFactory
. This default behavior is intended to potentially minimize any side-effect behavior that may occur that is not intended for the unit testing. SeeREADME
for more details on capabilities introduced; highlights are:MockHttpClient.WithConfigurations
method indicates that theHttpMessageHandler
andHttpClient
configurations are to be used.MockHttpClient.WithoutMocking
method indicates that the underlyingHttpClient
is not to be mocked; i.e. will result in an actual/real HTTP request to the specified endpoint. This will allow the mixing of real and mocked HTTP requests within the same test.