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
<PackageReference Include="JoanComas.ScenarioUnitTesting.AspNetCore" Version="1.2.6" />
paket add JoanComas.ScenarioUnitTesting.AspNetCore --version 1.2.6
#r "nuget: JoanComas.ScenarioUnitTesting.AspNetCore, 1.2.6"
// 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 | Versions 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. |
-
net8.0
- EntityFrameworkCore.AutoFixture (>= 2.1.0)
- JoanComas.ScenarioUnitTesting (>= 1.1.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Upgraded to .NET 8