Qowaiv.Validation.TestTools 2.0.0

dotnet add package Qowaiv.Validation.TestTools --version 2.0.0                
NuGet\Install-Package Qowaiv.Validation.TestTools -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Qowaiv.Validation.TestTools" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Qowaiv.Validation.TestTools --version 2.0.0                
#r "nuget: Qowaiv.Validation.TestTools, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Qowaiv.Validation.TestTools as a Cake Addin
#addin nuget:?package=Qowaiv.Validation.TestTools&version=2.0.0

// Install Qowaiv.Validation.TestTools as a Cake Tool
#tool nuget:?package=Qowaiv.Validation.TestTools&version=2.0.0                

Qowaiv.Validation Test Tools

These test tools help to write meaningful tests and assert the state of a Result or Result<T>. The syntax is inspired by FluentAssertions.

These assertions could look like this:

Result.For(17).Should().BeValid()
    .WithoutMessages()
    .Value.Should().Be(17); 

Where the chain after .Value exposes the value.

Other options for .IsValid() are:

Result.For(17).Shoud().BeValid()
    .WithMessage(ValidationMessage.Warn("Are you sure?"))
    .Value.Should().Be(17);

and

Result.For(17).Should().BeValid()
    .WithMessages(/* ... */)
    .Value.Should().Be(17);

Obviously, you can also check for invalidness:

Result.For(17).Should().BeInvalid(); 

In that case you do not have the option of .WithoutMessages(), obviously, as Result is defined to be invalid bases on containing at least one error message. Furthermore, it does not exposes the .Value as that is not accessible for an invalid result.

All (except for the .Value) is also applicable for the non-generic Result.

Validate with

There is also some syntactic sugar for testing validators on a model of choice:

var model = new MyModel();

Result<MyModel> result = model.ValidateWith(new ValidatorForMyModel());

And this result can be changed with the assertions described on top:

var model = new MyModel();
model.ValidateWith(new ValidatorForMyModel()).Should().BeValid();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 313 2/25/2025
1.0.0 1,907 11/19/2024
0.3.0 27,280 3/7/2023
0.2.1 10,383 4/13/2022
0.1.1 12,602 9/10/2021
0.1.0 472 8/31/2021
0.0.3 1,449 6/4/2021
0.0.2 2,056 2/2/2021
0.0.1 3,038 11/1/2019

v2.0.0
- Drop FluentAssertions depedency. (BREAKING)
- API change: model.ShouldBeValidFor<Validator>() => model.ValidateWith<Validator>().Should().BeValid() (BREAKING)
- Drop .NET standard 2.0. (BREAKING)
v1.0.0
- Add .NET 9.0 target.
- Drop .NET 5.0, NET6.0, NET7.0 targets. (BREAKING)
- Drop public Diagnostics.Contracts. BREAKING)
v0.3.0
- Support .NET 7.0. #62
v0.2.1
- Nullable anotations. #48
v0.1.1
- Use FluentAssertions to validate Result and Result<T> (#37)
v0.1.0
- Qowaiv.Validation.Abstractions dependency
v0.0.3
- FluentValidation 10.2.0 dependency.
v0.0.2
- ValidationMessageAssert.IsValid() returns the model (#20)