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
- Host: GitHub
- URL: https://github.com/verifytests/verify.assertions
- Owner: VerifyTests
- License: mit
- Created: 2024-07-28T06:54:37.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-20T22:40:39.000Z (over 1 year ago)
- Last Synced: 2024-12-22T18:40:12.087Z (over 1 year ago)
- Language: C#
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.txt
Awesome Lists containing this project
README
#
Verify.Assertions
[](https://github.com/orgs/VerifyTests/discussions)
[](https://ci.appveyor.com/project/SimonCropp/Verify-Assertions)
[](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/).