BufTools.AspNet.InMemoryEndpointTesting
1.0.1
Prefix Reserved
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package BufTools.AspNet.InMemoryEndpointTesting --version 1.0.1
NuGet\Install-Package BufTools.AspNet.InMemoryEndpointTesting -Version 1.0.1
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="BufTools.AspNet.InMemoryEndpointTesting" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BufTools.AspNet.InMemoryEndpointTesting --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BufTools.AspNet.InMemoryEndpointTesting, 1.0.1"
#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 BufTools.AspNet.InMemoryEndpointTesting as a Cake Addin #addin nuget:?package=BufTools.AspNet.InMemoryEndpointTesting&version=1.0.1 // Install BufTools.AspNet.InMemoryEndpointTesting as a Cake Tool #tool nuget:?package=BufTools.AspNet.InMemoryEndpointTesting&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AspNet In-Memory Endpoint Testing
This lets you easily startup your ASP WebApi in-memory from a unit test, call endpoints, and get a response back to Assert on.
It allows injecting mocks, is ultra fast, and all with two lines of code!
example:
var browser = new Browser<Program>(c =>
{
c.UseDependency(_userServiceMock.Object);
c.UseDependency(_validationMock.Object);
});
var result = await browser.CreateRequest("/api/v1/example")
.WithQueryParam("string_param", myString)
.WithQueryParam("int_param", myInt)
.GetAsync();
Getting Started
The general approach is to:
- Create an instance of a Browser class with any mocks to inject.
- Use the browser instance to build HTTP requests using fluent syntax and send them
Creating a browser
- When new'ing up a browser, you need to choose the program type that starts the application.
Options are:
- Program : choose this if not using a Startup.cs file
- Startup : chose this if using a Startup.cs file
- Inject dependencies
Use the configurator to inject classes in place of those thave have already been registered to act as replacements.
Example
Example usage with Progam as the type and two mocks injected
var browser = new Browser<Program>(c =>
{
c.UseDependency(_userServiceMock.Object);
c.UseDependency(_validationMock.Object);
});
Call an Endpoint
- To call an endpoint, start with CreateRequest and provide the route to the endpoint with no base url
- Use WithQueryParam to add any params that get appended to the route with a ?
- Call GetAsync (or Put, Post, Delete) to send the request and get a response back
var result = await browser.CreateRequest("/api/v1/example")
.WithQueryParam("string_param", myString)
.WithQueryParam("int_param", myInt)
.GetAsync();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.Mvc.Testing (>= 3.1.32)
- Microsoft.AspNetCore.TestHost (>= 3.1.32)
- Microsoft.TestPlatform.TestHost (>= 17.4.1)
-
net6.0
- Microsoft.AspNetCore.Mvc.Testing (>= 6.0.13)
- Microsoft.AspNetCore.TestHost (>= 6.0.13)
- Microsoft.TestPlatform.TestHost (>= 17.4.1)
-
net7.0
- Microsoft.AspNetCore.Mvc.Testing (>= 7.0.2)
- Microsoft.AspNetCore.TestHost (>= 7.0.2)
- Microsoft.TestPlatform.TestHost (>= 17.4.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.