An open API service indexing awesome lists of open source software.

https://github.com/verifytests/verify.assertions

Extends Verify to allow an assertion callbacks
https://github.com/verifytests/verify.assertions

Last synced: 4 months ago
JSON representation

Extends Verify to allow an assertion callbacks

Awesome Lists containing this project

README

          

# Verify.Assertions

[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true&label=)](https://github.com/orgs/VerifyTests/discussions)
[![Build status](https://ci.appveyor.com/api/projects/status/6stx39bhogfbgnpi?svg=true)](https://ci.appveyor.com/project/SimonCropp/Verify-Assertions)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.Assertions.svg)](https://www.nuget.org/packages/Verify.Assertions/)

Extends [Verify](https://github.com/VerifyTests/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](../../milestones?state=closed) for release notes.**

## NuGet package

https://nuget.org/packages/Verify.Assertions/

## Enable


```cs
[ModuleInitializer]
public static void Init() =>
VerifyAssertions.Initialize();
```
snippet source | anchor

## Usage

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.

### [Xunit](https://xunit.net/)


```cs
[Fact]
public async Task XunitUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert(
_ => Assert.Equal("value", _.Property));
}
```
snippet source | anchor

### [NUnit](https://docs.nunit.org/articles/nunit/writing-tests/assertions/assertions.html)


```cs
[Test]
public async Task NUnitUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert(
_ => Assert.That(_.Property, Is.EqualTo("value")));
}
```
snippet source | anchor

### [FluentAssertions](https://fluentassertions.com/)


```cs
[Fact]
public async Task FluentAssertionsUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert(
_ => _.Property.Should().Be("value"));
}
```
snippet source | anchor

### [Shouldly](https://github.com/shouldly/shouldly)


```cs
[Fact]
public async Task ShouldlyUsage()
{
var nested = new Nested(Property: "value");
var target = new Target(nested);
await Verify(target)
.Assert(
_ => _.Property.ShouldBe("value"));
}
```
snippet source | anchor

## Shared Assertions

Assertions can be added globally.


```cs
[ModuleInitializer]
public static void AddSharedAssert() =>
VerifyAssertions
.Assert(
_ => Assert.Equal("value", _.Property));

[Fact]
public async Task SharedAssert()
{
var nested = new SharedNested(Property: "value");
var target = new SharedTarget(nested);
await Verify(target);
}
```
snippet source | anchor

## Icon

[Approval](https://thenounproject.com/term/correct/6480102/) designed by [Danang Marhendra](https://thenounproject.com/creator/masart/) from [The Noun Project](https://thenounproject.com/).