Shouldly in C#
Assertions that read forward and fail with the actual values.
using Shouldly;
var response = new { Status = 200, Body = "pong", Elapsed = 18 };
// Shouldly reads assertion-first and fails with the actual values
response.Status.ShouldBe(200);
response.Body.ShouldStartWith("po");
response.Elapsed.ShouldBeLessThan(100);
var tags = new[] { "fast", "green" };
tags.ShouldContain("green");
Should.Throw<FormatException>(() => int.Parse("nope"));
How it works
ShouldBe,ShouldStartWithandShouldBeLessThanchain off values.- Collection and exception assertions follow the same shape.
- Failure messages quote your expression, not just two values.
Keywords and builtins used here
intnewusingvar
The run, in numbers
- Lines
- 12
- Characters to type
- 382
- Tokens
- 86
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 57 seconds.
Step 3 of 3 in Testing, step 12 of 16 in The open ecosystem.