BufTools.AspNet.InMemoryEndpointTesting 1.0.1

Prefix Reserved
There is a newer version of this package available.
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                
#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                

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:

  1. Create an instance of a Browser class with any mocks to inject.
  2. Use the browser instance to build HTTP requests using fluent syntax and send them

Creating a browser

  1. 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
  1. 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

  1. To call an endpoint, start with CreateRequest and provide the route to the endpoint with no base url
  2. Use WithQueryParam to add any params that get appended to the route with a ?
  3. 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 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.

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.3 130 5/7/2024
1.0.2 661 1/23/2023
1.0.1 597 1/17/2023
1.0.0 603 1/17/2023