Skip to content

vmati/fluentassertions.json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build Coverage Status

"With Fluent Assertions, the assertions look beautiful, natural and most importantly, extremely readable" (by Girish)

Available extension methods

  • BeEquivalentTo()
  • ContainSingleElement()
  • ContainSubtree()
  • HaveCount()
  • HaveElement()
  • HaveValue()
  • MatchRegex()
  • NotBeEquivalentTo()
  • NotHaveElement()
  • NotHaveValue()
  • NotMatchRegex()

See "in-code" description for more information.

Usage

Be sure to include using FluentAssertions.Json; otherwise false positives may occur.

using FluentAssertions;
using FluentAssertions.Json;
using Newtonsoft.Json.Linq;

... 
var actual = JToken.Parse(@"{ ""key1"" : ""value"" }");
var expected = JToken.Parse(@"{ ""key2"" : ""value"" }");
actual.Should().BeEquivalentTo(expected);

You can also use IJsonAssertionOptions<> with Should().BeEquivalentTo() assertions, which contains helper methods that you can use to specify the way you want to compare specific data types.

Example:

using FluentAssertions;
using FluentAssertions.Json;
using Newtonsoft.Json.Linq;

... 
var actual = JToken.Parse(@"{ ""value"" : 1.5 }");
var expected = JToken.Parse(@"{ ""value"" : 1.4 }");
actual.Should().BeEquivalentTo(expected, options => options
                .Using<double>(d => d.Subject.Should().BeApproximately(d.Expectation, 0.1))
                .WhenTypeIs<double>());

About

NewtonSoft.Json extensions for FluentAssertions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 93.6%
  • PowerShell 3.6%
  • Shell 2.6%
  • Batchfile 0.2%