JoanComas.ScenarioUnitTesting.AspNetCore 1.2.6

dotnet add package JoanComas.ScenarioUnitTesting.AspNetCore --version 1.2.6                
NuGet\Install-Package JoanComas.ScenarioUnitTesting.AspNetCore -Version 1.2.6                
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="JoanComas.ScenarioUnitTesting.AspNetCore" Version="1.2.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JoanComas.ScenarioUnitTesting.AspNetCore --version 1.2.6                
#r "nuget: JoanComas.ScenarioUnitTesting.AspNetCore, 1.2.6"                
#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 JoanComas.ScenarioUnitTesting.AspNetCore as a Cake Addin
#addin nuget:?package=JoanComas.ScenarioUnitTesting.AspNetCore&version=1.2.6

// Install JoanComas.ScenarioUnitTesting.AspNetCore as a Cake Tool
#tool nuget:?package=JoanComas.ScenarioUnitTesting.AspNetCore&version=1.2.6                

Asp .NET Core Scenario Unit Testing

Based on the ScenarioUnitTesting, allows to instantiate a Controller (which won't be possilble with the Scenario class because of BindingInfo), just use the ControllerScenario instead.

Additionally, it has a ControllerContext property exposed to arrange it.

Finally, it makes sure that any DbContext uses an in-memory database, so that you don't have to arrange nor fake it to avoid a real database connection.

Usage

Example:

[Theory, AutoData]
public void ExampleTest(ControllerScenario<MyControllerClass> scenario)
{
    scenario.Dependency<IMyInterface>().GetSomething(true).Returns(123);
    scenario.ControllerContext().HttpContext.User.Identity?.Name.Returns("User1");

    scenario.When().DoSomething();

    scenario.Dependency<IMyInterface>()
        .Received()
        .GetSomething(true);
}

Important: If your Controller gets a DbContext injected, make sure that the types used in the DbSets have a primary key.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.2.6 118 8/15/2024
1.2.2 112 8/14/2024
1.1.8 194 8/29/2023
1.1.7 146 8/29/2023
1.1.6 161 8/29/2023
1.1.5 162 8/29/2023
1.1.4 156 8/29/2023
1.1.3 161 8/29/2023
1.1.1 167 8/29/2023
1.1.0 233 8/29/2023

Upgraded to .NET 8