Relaxdays.TestUtilities.Scenarios 1.2.0

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

// Install Relaxdays.TestUtilities.Scenarios as a Cake Tool
#tool nuget:?package=Relaxdays.TestUtilities.Scenarios&version=1.2.0                

Relaxdays.Scenarios.TestUtilities

Overview

This project is focused around a wrapper type designated to produce clearer unit test output by letting users provide a description for test methods parameters. It works with MSTest, NUnit and XUnit. While these test frameworks also provide ways to achieve more readable unit test output, the Scenario type introduced in this project has some extra features.

ℹ A discussion of Scenario pros and cons and comparison with the builtin mechanisms will be added at a later point.

Usage

Basic

Creating a scenario with a description is simple:

// Create a scenario wrapping a player and set it's description to the player's name
var playerScenario = new Player("Ryu").AsScenario(player => player.Name);

// Create a scenario wrapping a preset bonus stage and give it a description that is meaningful in the context of our
// test (i.e., the stage is only for one player)
var stageScenario = BonusStages.DestroyCar.AsScenario("Single player stage (Bonus Stage: Destroy Car)");

We can use scenarios created this way as inputs to our unit tests:

[TestCaseSource(typeof(Stages), nameof(Stages.All))]
public void A_match_has_three_rounds(Scenario<Stage> stage)
{
    // ...
}

If we then run our unit tests and one fails, we get useful information from the descriptions provided, which might help us diagonse what's causing the issue more easily:

Failed A_match_has_three_rounds ("Single player stage (Bonus Stage: Destroy Car)")

Here we can see at a glance that our test failed because the input stage is actually a bonus stage, which does not have three rounds.

Advanced

Various methods are provided for fluent (non-mutating) transformation and combination of scenarios:

// Transform a scenario's data (halfing health of an existing player scenario) and adjust description accordingly
var playerWithHalfHealthScenario = playerScenario
    .WithTransformedData(player => player with { Health = player.Health / 2 })
    // We could also use the more specific .WithDescriptionAppendage("with half health") here
    .WithTransformedDescription(description => $"{description} with half health")

// Combine two scenarios by pairing them up, more generally, result data and description selectors can also be provided
var playerAndStage = playerScenario.CombinedWith(stageScenario);
Product Compatible and additional computed target framework versions.
.NET 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. 
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.0 4,358 11/20/2023
1.1.0 1,433 3/7/2023