FluentCases is a small .NET library for writing tests in a Given / When / Then style with a fluent API.
The library wraps a test context and lets you express arrange, act, and assert steps as a readable chain:
using FluentCases;
ShoppingBasket basket = new();
Case
.Given(basket, x => x.StartEmpty())
.When(x => x.AddItem(price: 12.50m))
.Then(x => x.TotalShouldBe(12.50m))
.And(x => x.ItemCountShouldBe(1));The current API supports:
Case.Given(context, arrange)Case.Given(create, arrange)When(act)Then(assert)And(assert)
fluentcases/
├── src/FluentCases
└── tests/FluentCases.Tests
src/FluentCasescontains the library code.tests/FluentCases.Testscontains the xUnit test project and usage examples.
- Library:
netstandard2.0 - Tests:
net10.0
dotnet build src/FluentCases/FluentCases.csprojdotnet test tests/FluentCases.Tests/FluentCases.Tests.csproj- The fluent chain executes each step immediately.
Given,When,Then, andAndall validate null delegates.Case.Given(create, arrange)also guards against a null context returned by the factory.