Skip to content

thenoobsbr/shouldly-extensions

TheNoobs.Extensions.Shouldly

A .NET library providing useful extension methods for the Shouldly assertion framework.

NuGet License .NET CodeQL - C#

Installation

Install via NuGet Package Manager:

dotnet add package TheNoobs.Extensions.Shouldly

Features

DateTime and DateTimeOffset Assertions

Allows 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.

License

This project is licensed under the MIT License.


Developed with love <3 by The Noobs.

About

Useful .NET extension methods to power up your Shouldly assertions.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors