Extends Verify to allow assertion callbacks. This enables using assertion libraries to interrogate during serialization. The primary use case for this is when the data structures being verified are either complex or large.
See Milestones for release notes.
https://nuget.org/packages/Verify.Assertions/
[ModuleInitializer]
public static void Init() =>
VerifyAssertions.Initialize();
Once enable, any assertion library can be used.
The below examples are simplistic for illustrating the usage. In a real world scenario, if data structures being verified are small, then the assertion can happen before or after the the Verify with no need to assert during serialization.
[Fact]
public async Task XunitUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert<Nested>(
_ => Assert.Equal("value", _.Property));
}
[Test]
public async Task NUnitUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert<Nested>(
_ => Assert.That(_.Property, Is.EqualTo("value")));
}
[Fact]
public async Task FluentAssertionsUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert<Nested>(
_ => _.Property.Should().Be("value"));
}
[Fact]
public async Task ShouldlyUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert<Nested>(
_ => _.Property.ShouldBe("value"));
}
Assertions can be added globally.
[ModuleInitializer]
public static void AddSharedAssert() =>
VerifyAssertions
.Assert<SharedNested>(
_ => Assert.Equal("value", _.Property));
[Fact]
public async Task SharedAssert()
{
var nested = new SharedNested(Property: "value");
var target = new SharedTarget(nested);
await Verify(target);
}
Approval designed by Danang Marhendra from The Noun Project.