Skip to content

Commit 424b09e

Browse files
committed
rename prop IsStrictlyOrdered, tests + reorder test's methods
1 parent 8e6e591 commit 424b09e

4 files changed

Lines changed: 37 additions & 32 deletions

File tree

Src/FluentAssertions.Json/Common/JTokenExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ namespace FluentAssertions.Json.Common
55
{
66
internal static class JTokenExtensions
77
{
8+
/// <summary>
9+
/// Recursively sorts the properties of JObject instances by name and
10+
/// the elements of JArray instances by their string representation,
11+
/// producing a normalized JToken for consistent comparison
12+
/// </summary>
813
public static JToken Normalize(this JToken token)
914
{
1015
return token switch

Src/FluentAssertions.Json/JTokenDifferentiator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Difference FindFirstDifference(JToken actual, JToken expected)
4141
return new Difference(DifferenceKind.ExpectedIsNull, path);
4242
}
4343

44-
if (options.IsStrictOrdering is false)
44+
if (!options.IsStrictlyOrdered)
4545
{
4646
actual = actual.Normalize();
4747
expected = expected.Normalize();

Src/FluentAssertions.Json/JsonAssertionOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public JsonAssertionOptions(EquivalencyOptions<T> equivalencyAssertionOptions) :
1414
{
1515
}
1616

17-
internal bool IsStrictOrdering { get; private set; } = true;
17+
internal bool IsStrictlyOrdered { get; private set; } = true;
1818

1919
public new IJsonAssertionRestriction<T, TProperty> Using<TProperty>(Action<IAssertionContext<TProperty>> action)
2020
{
@@ -23,7 +23,7 @@ public JsonAssertionOptions(EquivalencyOptions<T> equivalencyAssertionOptions) :
2323

2424
public new IJsonAssertionOptions<T> WithoutStrictOrdering()
2525
{
26-
IsStrictOrdering = false;
26+
IsStrictlyOrdered = false;
2727
return this;
2828
}
2929
}

Tests/FluentAssertions.Json.Specs/WithoutStrictOrderingSpecs.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,61 @@ namespace FluentAssertions.Json.Specs
99
public class WithoutStrictOrderingSpecs
1010
{
1111
[Theory]
12-
[MemberData(nameof(Should_HandleJToken_WhenNeedToIgnoreOrdering_SampleData))]
13-
public void Should_HandleJToken_WhenNeedToIgnoreOrdering(string json1, string json2)
12+
[MemberData(nameof(When_ignoring_ordering_BeEquivalentTo_should_succeed_sample_data))]
13+
public void When_ignoring_ordering_BeEquivalentTo_should_succeed(string subject, string expectation)
1414
{
1515
// Arrange
16-
var j1 = JToken.Parse(json1);
17-
var j2 = JToken.Parse(json2);
16+
var subjectJToken = JToken.Parse(subject);
17+
var expectationJToken = JToken.Parse(expectation);
1818

1919
// Act
20-
j1.Should().BeEquivalentTo(j2, opt => opt.WithoutStrictOrdering());
20+
subjectJToken.Should().BeEquivalentTo(expectationJToken, opt => opt.WithoutStrictOrdering());
2121

2222
// Assert
2323
}
2424

25-
[Theory]
26-
[MemberData(nameof(Should_DoNotHandleJToken_WhenNoNeedToIgnoreOrdering_SampleData))]
27-
public void Should_DoNotHandleJToken_WhenNoNeedToIgnoreOrdering(string json1, string json2)
28-
{
29-
// Arrange
30-
var j1 = JToken.Parse(json1);
31-
var j2 = JToken.Parse(json2);
32-
33-
// Act
34-
var action = new Func<AndConstraint<JTokenAssertions>>(() => j1.Should().BeEquivalentTo(j2));
35-
36-
// Assert
37-
action.Should().Throw<XunitException>();
38-
}
39-
40-
public static IEnumerable<object[]> Should_DoNotHandleJToken_WhenNoNeedToIgnoreOrdering_SampleData()
25+
public static IEnumerable<object[]> When_ignoring_ordering_BeEquivalentTo_should_succeed_sample_data()
4126
{
4227
yield return new object[] { @"{""ids"":[1,2,3]}", @"{""ids"":[3,2,1]}" };
28+
yield return new object[] { @"{""ids"":[1,2,3]}", @"{""ids"":[1,2,3]}" };
29+
yield return new object[] { @"{""type"":2,""name"":""b""}", @"{""name"":""b"",""type"":2}" };
4330
yield return new object[] { @"{""names"":[""a"",""b""]}", @"{""names"":[""b"",""a""]}" };
4431
yield return new object[]
4532
{
4633
@"{""vals"":[{""type"":1,""name"":""a""},{""name"":""b"",""type"":2}]}",
4734
@"{""vals"":[{""type"":2,""name"":""b""},{""name"":""a"",""type"":1}]}"
4835
};
36+
yield return new object[]
37+
{
38+
@"{""vals"":[{""type"":1,""name"":""a""},{""name"":""b"",""type"":2}]}",
39+
@"{""vals"":[{""name"":""a"",""type"":1},{""type"":2,""name"":""b""}]}"
40+
};
4941
}
5042

51-
public static IEnumerable<object[]> Should_HandleJToken_WhenNeedToIgnoreOrdering_SampleData()
43+
[Theory]
44+
[MemberData(nameof(When_not_ignoring_ordering_BeEquivalentTo_should_throw_sample_data))]
45+
public void When_not_ignoring_ordering_BeEquivalentTo_should_throw(string subject, string expectation)
46+
{
47+
// Arrange
48+
var subjectJToken = JToken.Parse(subject);
49+
var expectationJToken = JToken.Parse(expectation);
50+
51+
// Act
52+
var action = new Func<AndConstraint<JTokenAssertions>>(() => subjectJToken.Should().BeEquivalentTo(expectationJToken));
53+
54+
// Assert
55+
action.Should().Throw<XunitException>();
56+
}
57+
58+
public static IEnumerable<object[]> When_not_ignoring_ordering_BeEquivalentTo_should_throw_sample_data()
5259
{
5360
yield return new object[] { @"{""ids"":[1,2,3]}", @"{""ids"":[3,2,1]}" };
54-
yield return new object[] { @"{""ids"":[1,2,3]}", @"{""ids"":[1,2,3]}" };
55-
yield return new object[] { @"{""type"":2,""name"":""b""}", @"{""name"":""b"",""type"":2}" };
5661
yield return new object[] { @"{""names"":[""a"",""b""]}", @"{""names"":[""b"",""a""]}" };
5762
yield return new object[]
5863
{
5964
@"{""vals"":[{""type"":1,""name"":""a""},{""name"":""b"",""type"":2}]}",
6065
@"{""vals"":[{""type"":2,""name"":""b""},{""name"":""a"",""type"":1}]}"
6166
};
62-
yield return new object[]
63-
{
64-
@"{""vals"":[{""type"":1,""name"":""a""},{""name"":""b"",""type"":2}]}",
65-
@"{""vals"":[{""name"":""a"",""type"":1},{""type"":2,""name"":""b""}]}"
66-
};
6767
}
6868
}
6969
}

0 commit comments

Comments
 (0)