Ensure.That is a simple guard clause argument validation lib, that helps you with validation of your arguments.
Ensure.That is distributed via NuGet and since
v5.0.0 it's being built using DotNetCore and targes the frameworks:
Samples (two different APIs)
Samples below just list one validation method, but the API contains validation methods for e.g.:
- Collections (arrays, lists, collections, dictionaries)
Using static simple methods
This flavour was added in the
v5.0.0 release and this is my prefered way, because it has less overhead (read more below).
EnsureArg.IsNotNullOrWhiteSpace(myString); EnsureArg.IsNotNullOrWhiteSpace(myString, nameof(myArg));
Using extension methods
This is the initial way of doing validation, but this IS NOT my prefered way. Why? Well because it will
create a new instance of
Param<T> wrapping the value being passed, so that the context-aware extension
methods can target correct type.
Ensure.That(myString).IsNotNullOrWhiteSpace(); Ensure.That(myString, nameof(myArg)).IsNotNullOrWhiteSpace();
Ensure .That(myString, nameof(myString)) .WithExtraMessageOf(p => "Some more details") .IsNotNullOrWhiteSpace();
Ensure .That(myString, nameof(myString)) .WithException(param => new Exception()) .IsNotNullOrEmpty();
Turn On/Off - default is On
Could be used with different profiles. Like
#if RELEASE Ensure.Off() #endif
Get up and running with the source code
The main solution is maintained using Visual Studio 2015.
Unit-tests are written using
xUnit and there are no integration tests, hence you should just be able to:
Run the tests: