ApiTestHelper 1.0.2

dotnet add package ApiTestHelper --version 1.0.2                
NuGet\Install-Package ApiTestHelper -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ApiTestHelper" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ApiTestHelper --version 1.0.2                
#r "nuget: ApiTestHelper, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ApiTestHelper as a Cake Addin
#addin nuget:?package=ApiTestHelper&version=1.0.2

// Install ApiTestHelper as a Cake Tool
#tool nuget:?package=ApiTestHelper&version=1.0.2                

ApiTest

We test our code, but how to deal with APIs? Should we hope that everything works, or can we check if everything works? This is a simple helper that can let you run an API in a controlled environment.

Usage example:

IConfiguration configuration = new ConfigurationBuilder()
	.AddInMemoryCollection(new Dictionary<string, string>
						   {
							   {"key1", "value1"},
							   {"key2", "value2"}
						   })
	.Build();
	
using var host = ApiTestHelper.GetTestHost<Startup>(configuration, ServicesConfiguration);
var response = host.GetHttpResponseMessage("/Get", ApiTestHelper.HttpVerbs.Get)
	.EnsureSuccessStatusCode();

Instances can be replaced directly in the test, by passing something like:

void ServicesConfiguration(IServiceCollection services)
{
    services.Replace<IConfigReader, ConfigReaderMock>();
    services.Replace<IDbConnectionFactory, DbConnectionFactoryMock>();
    services.Replace<IDbRepository, FakeDbRepository>();
    services.Replace<IMemoryCache, FakeMemoryCache>();
}

Feel free to contribute to this project. https://github.com/jonnidip/ApiTest

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 415 6/25/2021
1.0.1 378 5/20/2021
1.0.0 328 5/18/2021