From a2e180c76adbf1fa2b4dcc5c5bdf9c82576ae182 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 5 Oct 2023 14:00:30 +1100 Subject: [PATCH] Add capacity to order enumerables dusing serialization (#1013) --- docs/named-tuples.md | 4 +- docs/scrubbers.md | 12 +-- docs/serializer-settings.md | 86 +++++++++--------- src/Directory.Build.props | 2 +- ...izationTests.EnumerableOrder.verified.json | 5 ++ ...nTests.EnumerableOrderFluent.verified.json | 5 ++ ....OrderEnumerableByDescending.verified.json | 5 ++ ...EnumerableByDescendingFluent.verified.json | 5 ++ ...EnumerableByDescendingGlobal.verified.json | 11 +++ ...ests.OrderEnumerableByGlobal.verified.json | 11 +++ ...lizationTests.EnumerableOrder.verified.txt | 5 ++ ...onTests.EnumerableOrderFluent.verified.txt | 5 ++ ...s.OrderEnumerableByDescending.verified.txt | 5 ++ ...rEnumerableByDescendingFluent.verified.txt | 5 ++ ...rEnumerableByDescendingGlobal.verified.txt | 11 +++ ...Tests.OrderEnumerableByGlobal.verified.txt | 11 +++ .../Serialization/SerializationTests.cs | 87 +++++++++++++++++++ .../Serialization/CustomContractResolver.cs | 7 ++ .../Serialization/SerializationSettings.cs | 1 + ...lizationSettings_EnumerableInterceptors.cs | 13 +++ .../VerifierSettings_SerializationMaps.cs | 11 +++ .../VerifySettings_SerializationMaps.cs | 12 +++ src/Verify/SettingsTask_SerializationMaps.cs | 14 +++ 23 files changed, 281 insertions(+), 52 deletions(-) create mode 100644 src/StrictJsonTests/SerializationTests.EnumerableOrder.verified.json create mode 100644 src/StrictJsonTests/SerializationTests.EnumerableOrderFluent.verified.json create mode 100644 src/StrictJsonTests/SerializationTests.OrderEnumerableByDescending.verified.json create mode 100644 src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingFluent.verified.json create mode 100644 src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingGlobal.verified.json create mode 100644 src/StrictJsonTests/SerializationTests.OrderEnumerableByGlobal.verified.json create mode 100644 src/Verify.Tests/Serialization/SerializationTests.EnumerableOrder.verified.txt create mode 100644 src/Verify.Tests/Serialization/SerializationTests.EnumerableOrderFluent.verified.txt create mode 100644 src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescending.verified.txt create mode 100644 src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingFluent.verified.txt create mode 100644 src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingGlobal.verified.txt create mode 100644 src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByGlobal.verified.txt create mode 100644 src/Verify/Serialization/SerializationSettings_EnumerableInterceptors.cs diff --git a/docs/named-tuples.md b/docs/named-tuples.md index d4822b0023..4ac4ab07ae 100644 --- a/docs/named-tuples.md +++ b/docs/named-tuples.md @@ -19,7 +19,7 @@ Given a method that returns a named tuple: static (bool Member1, string Member2, string Member3) MethodWithNamedTuple() => (true, "A", "B"); ``` -snippet source | anchor +snippet source | anchor Can be verified: @@ -29,7 +29,7 @@ Can be verified: ```cs await VerifyTuple(() => MethodWithNamedTuple()); ``` -snippet source | anchor +snippet source | anchor Resulting in: diff --git a/docs/scrubbers.md b/docs/scrubbers.md index dacc9ed4c5..027be8bbe1 100644 --- a/docs/scrubbers.md +++ b/docs/scrubbers.md @@ -59,7 +59,7 @@ For example remove lines containing `text`: ```cs verifySettings.ScrubLines(line => line.Contains("text")); ``` -snippet source | anchor +snippet source | anchor @@ -74,7 +74,7 @@ For example remove lines containing `text1` or `text2` ```cs verifySettings.ScrubLinesContaining("text1", "text2"); ``` -snippet source | anchor +snippet source | anchor Case insensitive by default (StringComparison.OrdinalIgnoreCase). @@ -86,7 +86,7 @@ Case insensitive by default (StringComparison.OrdinalIgnoreCase). ```cs verifySettings.ScrubLinesContaining(StringComparison.Ordinal, "text1", "text2"); ``` -snippet source | anchor +snippet source | anchor @@ -101,7 +101,7 @@ For example converts lines to upper case: ```cs verifySettings.ScrubLinesWithReplace(line => line.ToUpper()); ``` -snippet source | anchor +snippet source | anchor @@ -114,7 +114,7 @@ Replaces `Environment.MachineName` with `TheMachineName`. ```cs verifySettings.ScrubMachineName(); ``` -snippet source | anchor +snippet source | anchor @@ -127,7 +127,7 @@ Replaces `Environment.UserName` with `TheUserName`. ```cs verifySettings.ScrubUserName(); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/serializer-settings.md b/docs/serializer-settings.md index ad764c6409..62c11fcdfa 100644 --- a/docs/serializer-settings.md +++ b/docs/serializer-settings.md @@ -93,7 +93,7 @@ var settings = new JsonSerializerSettings DefaultValueHandling = DefaultValueHandling.Ignore, }; ``` -snippet source | anchor +snippet source | anchor @@ -109,7 +109,7 @@ VerifierSettings .AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All); ``` -snippet source | anchor +snippet source | anchor @@ -129,7 +129,7 @@ public Task AddExtraSettings() return Verify("Value", settings); } ``` -snippet source | anchor +snippet source | anchor @@ -145,7 +145,7 @@ public Task AddExtraSettingsFluent() => _ => _.Error = (currentObject, originalObject, location, exception, handled) => Console.WriteLine(location.Member)); ``` -snippet source | anchor +snippet source | anchor @@ -165,7 +165,7 @@ To disable this behavior globally use: ```cs VerifierSettings.DontIgnoreEmptyCollections(); ``` -snippet source | anchor +snippet source | anchor @@ -187,7 +187,7 @@ var target = new GuidTarget await Verify(target); ``` -snippet source | anchor +snippet source | anchor Results in the following: @@ -212,7 +212,7 @@ Strings containing inline Guids can also be scrubbed. To enable this behavior, u ```cs VerifierSettings.ScrubInlineGuids(); ``` -snippet source | anchor +snippet source | anchor @@ -227,7 +227,7 @@ var settings = new VerifySettings(); settings.DontScrubGuids(); await Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Or with the fluent api: @@ -238,7 +238,7 @@ Or with the fluent api: await Verify(target) .DontScrubGuids(); ``` -snippet source | anchor +snippet source | anchor To disable this behavior globally use: @@ -248,7 +248,7 @@ To disable this behavior globally use: ```cs VerifierSettings.DontScrubGuids(); ``` -snippet source | anchor +snippet source | anchor @@ -312,7 +312,7 @@ var target = new DateTimeTarget await Verify(target); ``` -snippet source | anchor +snippet source | anchor Results in the following: @@ -350,7 +350,7 @@ settings.DontScrubDateTimes(); return Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Or using the fluent api use: @@ -366,7 +366,7 @@ var target = new return Verify(target) .DontScrubDateTimes(); ``` -snippet source | anchor +snippet source | anchor Or globally use: @@ -376,7 +376,7 @@ Or globally use: ```cs VerifierSettings.DontScrubDateTimes(); ``` -snippet source | anchor +snippet source | anchor @@ -399,7 +399,7 @@ public Task WithExtraDatetimeFormat() => date = "2022-11-08" }); ``` -snippet source | anchor +snippet source | anchor @@ -419,7 +419,7 @@ await Verify(target) .AddNamedDateTime(new(2030, 1, 2), "instanceNamedDateTime") .AddNamedDateTimeOffset(new DateTime(2030, 1, 2), "instanceNamedTimeOffset"); ``` -snippet source | anchor +snippet source | anchor @@ -437,7 +437,7 @@ public static void AddNamedDatesAndTimes() VerifierSettings.AddNamedDateTimeOffset(new(new(2030, 1, 1)), "namedDateTimeOffset"); } ``` -snippet source | anchor +snippet source | anchor @@ -571,7 +571,7 @@ public Task ScopedSerializerFluent() .AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All); } ``` -snippet source | anchor +snippet source | anchor Result: @@ -699,7 +699,7 @@ public Task IgnoreTypeFluent() .IgnoreMembersWithType(); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -709,7 +709,7 @@ Or globally: ```cs VerifierSettings.IgnoreMembersWithType(); ``` -snippet source | anchor +snippet source | anchor Result: @@ -846,7 +846,7 @@ public Task ScrubTypeFluent() .ScrubMembersWithType(); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -856,7 +856,7 @@ Or globally: ```cs VerifierSettings.ScrubMembersWithType(); ``` -snippet source | anchor +snippet source | anchor Result: @@ -935,7 +935,7 @@ public Task AddIgnoreInstanceFluent() .IgnoreInstance(_ => _.Property == "Ignore"); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -945,7 +945,7 @@ Or globally: ```cs VerifierSettings.IgnoreInstance(_ => _.Property == "Ignore"); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1007,7 +1007,7 @@ public Task AddScrubInstanceFluent() .ScrubInstance(_ => _.Property == "Ignore"); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1017,7 +1017,7 @@ Or globally: ```cs VerifierSettings.ScrubInstance(_ => _.Property == "Ignore"); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1062,7 +1062,7 @@ public Task WithObsoleteProp() return Verify(target); } ``` -snippet source | anchor +snippet source | anchor Result: @@ -1110,7 +1110,7 @@ public Task WithObsoletePropIncludedFluent() .IncludeObsoletes(); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1120,7 +1120,7 @@ Or globally: ```cs VerifierSettings.IncludeObsoletes(); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1181,7 +1181,7 @@ public Task IgnoreMemberByExpressionFluent() _ => _.PropertyThatThrows); } ``` -snippet source | anchor +snippet source | anchor Or globally @@ -1196,7 +1196,7 @@ VerifierSettings.IgnoreMembers( _ => _.GetOnlyProperty, _ => _.PropertyThatThrows); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1256,7 +1256,7 @@ public Task ScrubMemberByExpressionFluent() _ => _.PropertyThatThrows); } ``` -snippet source | anchor +snippet source | anchor Or globally @@ -1271,7 +1271,7 @@ VerifierSettings.ScrubMembers( _ => _.GetOnlyProperty, _ => _.PropertyThatThrows); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1350,7 +1350,7 @@ public Task IgnoreMemberByNameFluent() .IgnoreMember(_ => _.PropertyThatThrows); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1370,7 +1370,7 @@ VerifierSettings.IgnoreMember("Field"); // For a specific type with expression VerifierSettings.IgnoreMember(_ => _.PropertyThatThrows); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1445,7 +1445,7 @@ public Task ScrubMemberByNameFluent() .ScrubMember(_ => _.PropertyThatThrows); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1465,7 +1465,7 @@ VerifierSettings.ScrubMember("Field"); // For a specific type with expression VerifierSettings.ScrubMember(_ => _.PropertyThatThrows); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1516,7 +1516,7 @@ public Task CustomExceptionPropFluent() .IgnoreMembersThatThrow(); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1526,7 +1526,7 @@ Or globally: ```cs VerifierSettings.IgnoreMembersThatThrow(); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1563,7 +1563,7 @@ public Task ExceptionMessagePropFluent() .IgnoreMembersThatThrow(_ => _.Message == "Ignore"); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1573,7 +1573,7 @@ Or globally: ```cs VerifierSettings.IgnoreMembersThatThrow(_ => _.Message == "Ignore"); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1697,7 +1697,7 @@ public Task MemberConverterByExpression() return Verify(input); } ``` -snippet source | anchor +snippet source | anchor @@ -1748,7 +1748,7 @@ public Task DontSortDictionaries() .DontSortDictionaries(); } ``` -snippet source | anchor +snippet source | anchor diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 804dddc3b7..948d655521 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436;CS1573;NU1901;NU1902;NU1903 - 21.3.0 + 22.0.0 enable preview true diff --git a/src/StrictJsonTests/SerializationTests.EnumerableOrder.verified.json b/src/StrictJsonTests/SerializationTests.EnumerableOrder.verified.json new file mode 100644 index 0000000000..3de91790f6 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.EnumerableOrder.verified.json @@ -0,0 +1,5 @@ +[ + "a", + "b", + "c" +] \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.EnumerableOrderFluent.verified.json b/src/StrictJsonTests/SerializationTests.EnumerableOrderFluent.verified.json new file mode 100644 index 0000000000..3de91790f6 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.EnumerableOrderFluent.verified.json @@ -0,0 +1,5 @@ +[ + "a", + "b", + "c" +] \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescending.verified.json b/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescending.verified.json new file mode 100644 index 0000000000..3de91790f6 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescending.verified.json @@ -0,0 +1,5 @@ +[ + "a", + "b", + "c" +] \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingFluent.verified.json b/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingFluent.verified.json new file mode 100644 index 0000000000..76f9c07eeb --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingFluent.verified.json @@ -0,0 +1,5 @@ +[ + "c", + "b", + "a" +] \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingGlobal.verified.json b/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingGlobal.verified.json new file mode 100644 index 0000000000..e094c4f633 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.OrderEnumerableByDescendingGlobal.verified.json @@ -0,0 +1,11 @@ +[ + { + "value": "c" + }, + { + "value": "b" + }, + { + "value": "a" + } +] \ No newline at end of file diff --git a/src/StrictJsonTests/SerializationTests.OrderEnumerableByGlobal.verified.json b/src/StrictJsonTests/SerializationTests.OrderEnumerableByGlobal.verified.json new file mode 100644 index 0000000000..245f435bc4 --- /dev/null +++ b/src/StrictJsonTests/SerializationTests.OrderEnumerableByGlobal.verified.json @@ -0,0 +1,11 @@ +[ + { + "value": "a" + }, + { + "value": "c" + }, + { + "value": "b" + } +] \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.EnumerableOrder.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.EnumerableOrder.verified.txt new file mode 100644 index 0000000000..988751e7dc --- /dev/null +++ b/src/Verify.Tests/Serialization/SerializationTests.EnumerableOrder.verified.txt @@ -0,0 +1,5 @@ +[ + a, + b, + c +] \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.EnumerableOrderFluent.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.EnumerableOrderFluent.verified.txt new file mode 100644 index 0000000000..988751e7dc --- /dev/null +++ b/src/Verify.Tests/Serialization/SerializationTests.EnumerableOrderFluent.verified.txt @@ -0,0 +1,5 @@ +[ + a, + b, + c +] \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescending.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescending.verified.txt new file mode 100644 index 0000000000..988751e7dc --- /dev/null +++ b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescending.verified.txt @@ -0,0 +1,5 @@ +[ + a, + b, + c +] \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingFluent.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingFluent.verified.txt new file mode 100644 index 0000000000..f0f434fb2f --- /dev/null +++ b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingFluent.verified.txt @@ -0,0 +1,5 @@ +[ + c, + b, + a +] \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingGlobal.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingGlobal.verified.txt new file mode 100644 index 0000000000..f80d3a1fca --- /dev/null +++ b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByDescendingGlobal.verified.txt @@ -0,0 +1,11 @@ +[ + { + value: c + }, + { + value: b + }, + { + value: a + } +] \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByGlobal.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByGlobal.verified.txt new file mode 100644 index 0000000000..15ff4a4612 --- /dev/null +++ b/src/Verify.Tests/Serialization/SerializationTests.OrderEnumerableByGlobal.verified.txt @@ -0,0 +1,11 @@ +[ + { + value: a + }, + { + value: c + }, + { + value: b + } +] \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.cs b/src/Verify.Tests/Serialization/SerializationTests.cs index 6b30140872..15fbeb498f 100644 --- a/src/Verify.Tests/Serialization/SerializationTests.cs +++ b/src/Verify.Tests/Serialization/SerializationTests.cs @@ -43,6 +43,93 @@ public Task Tasks() }); } + + [ModuleInitializer] + public static void OrderEnumerableByGlobalInit() => + VerifierSettings.OrderEnumerableBy(_ => _.value); + + [Fact] + public Task OrderEnumerableByGlobal() => + Verify( + new List + { + new("a"), + new("c"), + new("b") + }); + + public record EnumerableOrderGlobalItem(string value); + + [ModuleInitializer] + public static void OrderEnumerableByDescendingGlobalInit() => + VerifierSettings.OrderEnumerableByDescending(_ => _.value); + + [Fact] + public Task OrderEnumerableByDescendingGlobal() => + Verify( + new List + { + new("a"), + new("c"), + new("b") + }); + + public record EnumerableOrderDescendingGlobalItem(string value); + + [Fact] + public Task EnumerableOrder() + { + var settings = new VerifySettings(); + settings.OrderEnumerableBy(_ => _); + return Verify( + new List + { + "a", + "c", + "b" + }, + settings); + } + + + [Fact] + public Task OrderEnumerableByDescending() + { + var settings = new VerifySettings(); + settings.OrderEnumerableBy(_ => _); + return Verify( + new List + { + "a", + "c", + "b" + }, + settings); + } + + [Fact] + public Task EnumerableOrderFluent() => + Verify( + new List + { + "a", + "c", + "b" + }) + .OrderEnumerableBy(_ => _); + + [Fact] + public Task OrderEnumerableByDescendingFluent() => + Verify( + new List + { + "a", + "c", + "b" + }) + .OrderEnumerableByDescending(_ => _); + + #region AddExtraDatetimeFormat [ModuleInitializer] diff --git a/src/Verify/Serialization/CustomContractResolver.cs b/src/Verify/Serialization/CustomContractResolver.cs index 462be5881e..acfd365dc3 100644 --- a/src/Verify/Serialization/CustomContractResolver.cs +++ b/src/Verify/Serialization/CustomContractResolver.cs @@ -194,6 +194,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ protected override JsonArrayContract CreateArrayContract(Type objectType) { var contract = base.CreateArrayContract(objectType); + contract.InterceptSerializeItem = item => { if (item is not null && @@ -205,6 +206,12 @@ protected override JsonArrayContract CreateArrayContract(Type objectType) return InterceptResult.Default; }; + if (contract.CollectionItemType != null && + settings.TryGetEnumerableInterceptors(contract.CollectionItemType, out var order)) + { + contract.InterceptSerializeItems = _ => order(_); + } + return contract; } } \ No newline at end of file diff --git a/src/Verify/Serialization/SerializationSettings.cs b/src/Verify/Serialization/SerializationSettings.cs index 346cfb2cee..877a3885be 100644 --- a/src/Verify/Serialization/SerializationSettings.cs +++ b/src/Verify/Serialization/SerializationSettings.cs @@ -58,6 +58,7 @@ public SerializationSettings(SerializationSettings settings) _ => _.Key, _ => _.Value.Clone()); scrubDateTimes = settings.scrubDateTimes; + enumerableInterceptors = new(settings.enumerableInterceptors); scrubGuids = settings.scrubGuids; includeObsoletes = settings.includeObsoletes; diff --git a/src/Verify/Serialization/SerializationSettings_EnumerableInterceptors.cs b/src/Verify/Serialization/SerializationSettings_EnumerableInterceptors.cs new file mode 100644 index 0000000000..39d036dc11 --- /dev/null +++ b/src/Verify/Serialization/SerializationSettings_EnumerableInterceptors.cs @@ -0,0 +1,13 @@ +partial class SerializationSettings +{ + Dictionary> enumerableInterceptors = new(); + + public void OrderEnumerableBy(Func keySelector) => + enumerableInterceptors[typeof(T)] = _ => _.Cast().OrderBy(keySelector); + + public void OrderEnumerableByDescending(Func keySelector) => + enumerableInterceptors[typeof(T)] = _ => _.Cast().OrderByDescending(keySelector); + + internal bool TryGetEnumerableInterceptors(Type memberType, [NotNullWhen(true)] out Func? order) => + enumerableInterceptors.TryGetValue(memberType, out order); +} \ No newline at end of file diff --git a/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs b/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs index 5e5c76018b..be4ac5133d 100644 --- a/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs +++ b/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs @@ -186,6 +186,17 @@ public static void ScrubInstance(Func shouldIgnore) serialization.ScrubInstance(shouldIgnore); } + public static void OrderEnumerableBy(Func keySelector) + { + InnerVerifier.ThrowIfVerifyHasBeenRun(); + serialization.OrderEnumerableBy(keySelector); + } + public static void OrderEnumerableByDescending(Func keySelector) + { + InnerVerifier.ThrowIfVerifyHasBeenRun(); + serialization.OrderEnumerableByDescending(keySelector); + } + public static void IgnoreInstance(Type type, ShouldIgnore shouldIgnore) { InnerVerifier.ThrowIfVerifyHasBeenRun(); diff --git a/src/Verify/Serialization/VerifySettings_SerializationMaps.cs b/src/Verify/Serialization/VerifySettings_SerializationMaps.cs index aae7721f94..64087463e8 100644 --- a/src/Verify/Serialization/VerifySettings_SerializationMaps.cs +++ b/src/Verify/Serialization/VerifySettings_SerializationMaps.cs @@ -156,6 +156,18 @@ public void ScrubInstance(Func shouldScrub) serialization.ScrubInstance(shouldScrub); } + public void OrderEnumerableBy(Func keySelector) + { + CloneSettings(); + serialization.OrderEnumerableBy(keySelector); + } + + public void OrderEnumerableByDescending(Func keySelector) + { + CloneSettings(); + serialization.OrderEnumerableByDescending(keySelector); + } + public void IgnoreInstance(Type type, ShouldIgnore shouldIgnore) { CloneSettings(); diff --git a/src/Verify/SettingsTask_SerializationMaps.cs b/src/Verify/SettingsTask_SerializationMaps.cs index 2cbda8de09..507a4b6875 100644 --- a/src/Verify/SettingsTask_SerializationMaps.cs +++ b/src/Verify/SettingsTask_SerializationMaps.cs @@ -23,6 +23,20 @@ public SettingsTask DontSortDictionaries() return this; } + [Pure] + public SettingsTask OrderEnumerableBy(Func keySelector) + { + CurrentSettings.OrderEnumerableBy(keySelector); + return this; + } + + [Pure] + public SettingsTask OrderEnumerableByDescending(Func keySelector) + { + CurrentSettings.OrderEnumerableByDescending(keySelector); + return this; + } + [Pure] public SettingsTask IncludeObsoletes() {