Skip to content

fluentassertions/fluentassertions.json

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 10.0.3 to 13.0.1.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](JamesNK/Newtonsoft.Json@10.0.3...13.0.1)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
c543cec

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
Src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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>());