A .NET library providing useful extension methods for the Shouldly assertion framework.
Install via NuGet Package Manager:
dotnet add package TheNoobs.Extensions.ShouldlyAllows you to assert that a DateTime or DateTimeOffset is close to an expected value, within a specified TimeSpan precision. This is particularly useful for scenarios where you need to check timestamps generated around the same time, but which may differ by a few milliseconds.
using TheNoobs.Extensions.Shouldly;
// ...
var now = DateTime.UtcNow;
var result = someService.DoSomething(now);
// Assert that the result date is close to 'now' (e.g., within a 1-second margin of error)
result.Date.ShouldBeCloseTo(now, TimeSpan.FromSeconds(1));The ShouldBeCloseTo extension method integrates seamlessly with Shouldly, throwing a ShouldAssertException if the duration between the target and the expected date exceeds the specified precision. It also returns the target value, allowing you to chain additional assertions.
This project is licensed under the MIT License.
Developed with love <3 by The Noobs.