Skip to content

mwpowellhtx/Validate.Fluently

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Validate Fluently - Fluent Validation

We add Fluent extension methods building on the Validation project.

NuGet package Validation NuGet package

This project is available as the Validate.Fluently NuGet package.

Fluent Philosophy

Couple of operational notes. We make assumptions about:

  1. Names. Specify names such as Arguments and so forth at key moments.
  2. Messages. We approach this issue using delegated callbacks. We want to avoid things such as string formatting and interpolation until the last possible moment.
  3. Conditions. We approach this issue also using delegated callbacks, for the same reasons.
  4. Values. Whenever possible, we provide the extension method anchor values, objects, etc, for the delegated conditions. When validation passes you can leverage Fluent style with the return value.

In general, the approach we took with this is simple, for you to be able to validate your bits early and often, then keep on composing your phrases, sentences, and the rest of your code, with as minimal impact as possible.

Some Examples

We can validate some basic Requirements, which end up throwing System.ArgumentException.

arg1.RequiresNotNull(nameof(arg1));
arg2.RequiresNotNullOrEmpty(nameof(arg2));

Fluent state validation via the Verification throws System.InvalidOperationException

condition.VerifyOperation(() => "some error occurred.");

Internal integrity checks occur via the Assumptions and throws a Validation.InternalErrorException. Testing this one can be tricky, however; we recommend simply looking for instances deriving from Exception.

condition.AssumesTrue(() => "some error");

Warning signs that should not throw an Exception via the Reporting class.

condition.ReportIfNot(() => "some error");

About

Extends the Validation project in Fluent style.

Resources

License

Stars

Watchers

Forks

Packages

No packages published