BufTools.AspNet.InMemoryEndpointTesting 1.0.3

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package BufTools.AspNet.InMemoryEndpointTesting --version 1.0.3
NuGet\Install-Package BufTools.AspNet.InMemoryEndpointTesting -Version 1.0.3
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.3" />
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.3
#r "nuget: BufTools.AspNet.InMemoryEndpointTesting, 1.0.3"
#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.3

// Install BufTools.AspNet.InMemoryEndpointTesting as a Cake Tool
#tool nuget:?package=BufTools.AspNet.InMemoryEndpointTesting&version=1.0.3

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

*** If using minimal hosting model(ie, Program instead of Startup), then you must make the Program class accessible by the Test project. Do so by adding this the .csproj file of the application under test:

  <ItemGroup>
    <InternalsVisibleTo Include="YourApi.Tests" />
  </ItemGroup>
  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 92 5/7/2024
1.0.2 632 1/23/2023
1.0.1 577 1/17/2023
1.0.0 579 1/17/2023

Added package signing