diff --git a/docs/mdsource/serializer-settings.source.md b/docs/mdsource/serializer-settings.source.md index 0f4cf85906..a1c828ebf3 100644 --- a/docs/mdsource/serializer-settings.source.md +++ b/docs/mdsource/serializer-settings.source.md @@ -130,41 +130,6 @@ Or globally use: snippet: DontScrubDateTimesGlobal -## Numeric Ids are scrubbed - -By default numeric properties (`int`, `uint`, `long`, `ulong`, and their nullable counterparts) suffixed with `Id` are sanitized during verification. This is done by finding each id and taking a counter based that that specific id. That counter is then used replace the id values. This allows for repeatable tests when id are bing generated. - -snippet: NumericId - -Results in the following: - -snippet: SerializationTests.NumericIdScrubbing.verified.txt - - -### Convention - -A custom "is member a numeric Id" convention is supported. - -To define a convention use: - -snippet: TreatAsNumericId - -To define a convention globally use: - -snippet: TreatAsNumericIdGlobal - - -### Disable - -To disable use: - -snippet: DisableNumericId - -To disable this behavior globally use: - -snippet: DisableNumericIdGlobal - - ## Default Booleans are ignored By default values of `bool` and `bool?` are ignored during verification. So properties that equate to 'false' will not be written, diff --git a/docs/named-tuples.md b/docs/named-tuples.md index 7b83a6bb1e..85fad9309e 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 7c3aa439c6..4c683280e2 100644 --- a/docs/scrubbers.md +++ b/docs/scrubbers.md @@ -56,7 +56,7 @@ For example remove lines containing `text`: ```cs verifySettings.ScrubLines(line => line.Contains("text")); ``` -snippet source | anchor +snippet source | anchor @@ -71,7 +71,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). @@ -83,7 +83,7 @@ Case insensitive by default (StringComparison.OrdinalIgnoreCase). ```cs verifySettings.ScrubLinesContaining(StringComparison.Ordinal, "text1", "text2"); ``` -snippet source | anchor +snippet source | anchor @@ -98,7 +98,7 @@ For example converts lines to upper case: ```cs verifySettings.ScrubLinesWithReplace(line => line.ToUpper()); ``` -snippet source | anchor +snippet source | anchor @@ -111,7 +111,7 @@ Replaces `Environment.MachineName` with `TheMachineName`. ```cs verifySettings.ScrubMachineName(); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/serializer-settings.md b/docs/serializer-settings.md index 077c7bae70..9a44d314be 100644 --- a/docs/serializer-settings.md +++ b/docs/serializer-settings.md @@ -84,7 +84,7 @@ var settings = new JsonSerializerSettings Culture = CultureInfo.InvariantCulture }; ``` -snippet source | anchor +snippet source | anchor @@ -157,7 +157,7 @@ To disable this behavior globally use: ```cs VerifierSettings.DontIgnoreEmptyCollections(); ``` -snippet source | anchor +snippet source | anchor @@ -179,7 +179,7 @@ var target = new GuidTarget await Verify(target); ``` -snippet source | anchor +snippet source | anchor Results in the following: @@ -204,7 +204,7 @@ Strings containing inline Guids can also be scrubbed. To enable this behavior, u ```cs VerifierSettings.ScrubInlineGuids(); ``` -snippet source | anchor +snippet source | anchor @@ -219,7 +219,7 @@ var settings = new VerifySettings(); settings.DontScrubGuids(); await Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Or with the fluent api: @@ -230,7 +230,7 @@ Or with the fluent api: await Verify(target) .DontScrubGuids(); ``` -snippet source | anchor +snippet source | anchor To disable this behavior globally use: @@ -240,7 +240,7 @@ To disable this behavior globally use: ```cs VerifierSettings.DontScrubGuids(); ``` -snippet source | anchor +snippet source | anchor @@ -268,7 +268,7 @@ var target = new DateTimeTarget await Verify(target); ``` -snippet source | anchor +snippet source | anchor Results in the following: @@ -306,7 +306,7 @@ settings.DontScrubDateTimes(); return Verify(target, settings); ``` -snippet source | anchor +snippet source | anchor Or using the fluent api use: @@ -322,7 +322,7 @@ var target = new return Verify(target) .DontScrubDateTimes(); ``` -snippet source | anchor +snippet source | anchor Or globally use: @@ -332,117 +332,7 @@ Or globally use: ```cs VerifierSettings.DontScrubDateTimes(); ``` -snippet source | anchor - - - -## Numeric Ids are scrubbed - -By default numeric properties (`int`, `uint`, `long`, `ulong`, and their nullable counterparts) suffixed with `Id` are sanitized during verification. This is done by finding each id and taking a counter based that that specific id. That counter is then used replace the id values. This allows for repeatable tests when id are bing generated. - - - -```cs -[Fact] -public Task NumericIdScrubbing() -{ - var target = new - { - Id = 5, - OtherId = 5, - YetAnotherId = 4, - PossibleNullId = (int?) 5, - ActualNullId = (int?) null - }; - - return Verify(target); -} -``` -snippet source | anchor - - -Results in the following: - - - -```txt -{ - Id: Id_1, - OtherId: Id_1, - YetAnotherId: Id_2, - PossibleNullId: Id_1 -} -``` -snippet source | anchor - - - -### Convention - -A custom "is member a numeric Id" convention is supported. - -To define a convention use: - - - -```cs -[Fact] -public Task TreatAsNumericId() -{ - var target = new IdConventionTarget - { - TheProperty = 5 - }; - return Verify(target) - .TreatAsNumericId(member => member.Name == "TheProperty"); -} -``` -snippet source | anchor - - -To define a convention globally use: - - - -```cs -VerifierSettings.TreatAsNumericId(member => member.Name == "TheProperty"); -``` -snippet source | anchor - - - -### Disable - -To disable use: - - - -```cs -[Fact] -public Task NumericIdScrubbingDisabled() -{ - var target = new - { - Id = 5, - OtherId = 5, - YetAnotherId = 4, - PossibleNullId = (int?) 5, - ActualNullId = (int?) null - }; - return Verify(target).DontScrubNumericIds(); -} -``` -snippet source | anchor - - -To disable this behavior globally use: - - - -```cs -VerifierSettings.DontScrubNumericIds(); -``` -snippet source | anchor +snippet source | anchor @@ -457,7 +347,7 @@ To disable this behavior globally use: ```cs VerifierSettings.DontIgnoreFalse(); ``` -snippet source | anchor +snippet source | anchor @@ -613,7 +503,7 @@ public Task ScopedSerializerFluent() .AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All); } ``` -snippet source | anchor +snippet source | anchor Result: @@ -747,7 +637,7 @@ public Task IgnoreTypeFluent() }); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -757,7 +647,7 @@ Or globally: ```cs VerifierSettings.IgnoreMembersWithType(); ``` -snippet source | anchor +snippet source | anchor Result: @@ -828,7 +718,7 @@ public Task AddIgnoreInstanceFluent() .IgnoreInstance(x => x.Property == "Ignore"); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -838,7 +728,7 @@ Or globally: ```cs VerifierSettings.IgnoreInstance(x => x.Property == "Ignore"); ``` -snippet source | anchor +snippet source | anchor Result: @@ -881,7 +771,7 @@ public Task WithObsoleteProp() return Verify(target); } ``` -snippet source | anchor +snippet source | anchor Result: @@ -929,7 +819,7 @@ public Task WithObsoletePropIncludedFluent() .IncludeObsoletes(); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -939,7 +829,7 @@ Or globally: ```cs VerifierSettings.IncludeObsoletes(); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1004,7 +894,7 @@ public Task IgnoreMemberByExpressionFluent() }); } ``` -snippet source | anchor +snippet source | anchor Or globally @@ -1018,7 +908,7 @@ VerifierSettings.IgnoreMember(x => x.Field); VerifierSettings.IgnoreMember(x => x.GetOnlyProperty); VerifierSettings.IgnoreMember(x => x.PropertyThatThrows); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1096,7 +986,7 @@ public Task IgnoreMemberByNameFluent() }); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1116,7 +1006,7 @@ VerifierSettings.IgnoreMember("Field"); // For a specific type with expression VerifierSettings.IgnoreMember(_ => _.PropertyThatThrows); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1163,7 +1053,7 @@ public Task CustomExceptionPropFluent() .IgnoreMembersThatThrow(); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1173,7 +1063,7 @@ Or globally: ```cs VerifierSettings.IgnoreMembersThatThrow(); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1210,7 +1100,7 @@ public Task ExceptionMessagePropFluent() .IgnoreMembersThatThrow(x => x.Message == "Ignore"); } ``` -snippet source | anchor +snippet source | anchor Or globally: @@ -1220,7 +1110,7 @@ Or globally: ```cs VerifierSettings.IgnoreMembersThatThrow(x => x.Message == "Ignore"); ``` -snippet source | anchor +snippet source | anchor Result: @@ -1378,7 +1268,7 @@ public Task MemberConverterByExpression() return Verify(input); } ``` -snippet source | anchor +snippet source | anchor diff --git a/readme.md b/readme.md index 4f6fa62b0d..ca346fd663 100644 --- a/readme.md +++ b/readme.md @@ -309,7 +309,7 @@ public Task VerifyJsonJToken() return VerifyJson(target); } ``` -snippet source | anchor +snippet source | anchor Results in: diff --git a/src/Verify.Tests/Serialization/SerializationTests.NumericIdFirst.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.NumericIdFirst.verified.txt deleted file mode 100644 index fab6c4b9b3..0000000000 --- a/src/Verify.Tests/Serialization/SerializationTests.NumericIdFirst.verified.txt +++ /dev/null @@ -1,3 +0,0 @@ -{ - Id: Id_1 -} \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbing.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbing.verified.txt deleted file mode 100644 index 6cf8ec0bdb..0000000000 --- a/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbing.verified.txt +++ /dev/null @@ -1,6 +0,0 @@ -{ - Id: Id_1, - OtherId: Id_1, - YetAnotherId: Id_2, - PossibleNullId: Id_1 -} \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbingDisabled.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbingDisabled.verified.txt deleted file mode 100644 index 2eef80835f..0000000000 --- a/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbingDisabled.verified.txt +++ /dev/null @@ -1,6 +0,0 @@ -{ - Id: 5, - OtherId: 5, - YetAnotherId: 4, - PossibleNullId: 5 -} \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbingDisabledGlobal.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbingDisabledGlobal.verified.txt deleted file mode 100644 index 90c5e0bd80..0000000000 --- a/src/Verify.Tests/Serialization/SerializationTests.NumericIdScrubbingDisabledGlobal.verified.txt +++ /dev/null @@ -1,6 +0,0 @@ -{ - Id: 5, - OtherId: 5, - YetAnotherId: 4, - PossibleNullId: 5 -} \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.NumericIdSecond.verified.txt b/src/Verify.Tests/Serialization/SerializationTests.NumericIdSecond.verified.txt deleted file mode 100644 index fab6c4b9b3..0000000000 --- a/src/Verify.Tests/Serialization/SerializationTests.NumericIdSecond.verified.txt +++ /dev/null @@ -1,3 +0,0 @@ -{ - Id: Id_1 -} \ No newline at end of file diff --git a/src/Verify.Tests/Serialization/SerializationTests.cs b/src/Verify.Tests/Serialization/SerializationTests.cs index ad3edc9c88..9e8a1d3113 100644 --- a/src/Verify.Tests/Serialization/SerializationTests.cs +++ b/src/Verify.Tests/Serialization/SerializationTests.cs @@ -315,101 +315,6 @@ void AddExtraSettingsGlobal() #endregion } - #region TreatAsNumericId - - [Fact] - public Task TreatAsNumericId() - { - var target = new IdConventionTarget - { - TheProperty = 5 - }; - return Verify(target) - .TreatAsNumericId(member => member.Name == "TheProperty"); - } - - #endregion - - //TOFO: move to diff project - //[Fact] - public Task TreatAsNumericIdGlobal() - { - #region TreatAsNumericIdGlobal - - VerifierSettings.TreatAsNumericId(member => member.Name == "TheProperty"); - - #endregion - - var target = new IdConventionTarget - { - TheProperty = 5 - }; - return Verify(target); - } - - public class IdConventionTarget - { - public int TheProperty { get; set; } - } - - //TODO: move to diff project - public Task NumericIdScrubbingDisabledGlobal() - { - #region DisableNumericIdGlobal - - VerifierSettings.DontScrubNumericIds(); - - #endregion - - return Verify( - new - { - Id = 5, - OtherId = 5, - YetAnotherId = 4, - PossibleNullId = (int?) 5, - ActualNullId = (int?) null - }); - } - - - #region DisableNumericId - - [Fact] - public Task NumericIdScrubbingDisabled() - { - var target = new - { - Id = 5, - OtherId = 5, - YetAnotherId = 4, - PossibleNullId = (int?) 5, - ActualNullId = (int?) null - }; - return Verify(target).DontScrubNumericIds(); - } - - #endregion - - #region NumericId - - [Fact] - public Task NumericIdScrubbing() - { - var target = new - { - Id = 5, - OtherId = 5, - YetAnotherId = 4, - PossibleNullId = (int?) 5, - ActualNullId = (int?) null - }; - - return Verify(target); - } - - #endregion - [Fact] public void SettingsIsCloned() { diff --git a/src/Verify/Serialization/Converters/IdConverter.cs b/src/Verify/Serialization/Converters/IdConverter.cs deleted file mode 100644 index b03eef2b7a..0000000000 --- a/src/Verify/Serialization/Converters/IdConverter.cs +++ /dev/null @@ -1,12 +0,0 @@ -class IdConverter : - WriteOnlyJsonConverter -{ - public override bool CanConvert(Type objectType) => - true; - - public override void Write(VerifyJsonWriter writer, object value) - { - var id = writer.Counter.NextIdString(value); - writer.WriteValue(id); - } -} \ No newline at end of file diff --git a/src/Verify/Serialization/CustomContractResolver.cs b/src/Verify/Serialization/CustomContractResolver.cs index cb2d4eb716..a092e34d1a 100644 --- a/src/Verify/Serialization/CustomContractResolver.cs +++ b/src/Verify/Serialization/CustomContractResolver.cs @@ -129,21 +129,6 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ property.ShouldSerialize = shouldSerialize; } - var underlyingType = Nullable.GetUnderlyingType(memberType) ?? memberType; - if ( - underlyingType == typeof(int) || - underlyingType == typeof(long) || - underlyingType == typeof(uint) || - underlyingType == typeof(ulong) - ) - { - if (settings.scrubNumericIds && settings.isNumericId(member)) - { - property.Converter = new IdConverter(); - return property; - } - } - property.ValueProvider = new CustomValueProvider(valueProvider, memberType, settings.ignoreMembersThatThrow, VerifierSettings.GetMemberConverter(member)); return property; diff --git a/src/Verify/Serialization/IsNumericId.cs b/src/Verify/Serialization/IsNumericId.cs deleted file mode 100644 index 89962818da..0000000000 --- a/src/Verify/Serialization/IsNumericId.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace VerifyTests; - -public delegate bool IsNumericId(MemberInfo member); \ No newline at end of file diff --git a/src/Verify/Serialization/SerializationSettings.cs b/src/Verify/Serialization/SerializationSettings.cs index cd3526fc8a..cf9717a8df 100644 --- a/src/Verify/Serialization/SerializationSettings.cs +++ b/src/Verify/Serialization/SerializationSettings.cs @@ -62,10 +62,8 @@ public SerializationSettings(SerializationSettings settings) x => x.Key, x => x.Value.Clone()); scrubDateTimes = settings.scrubDateTimes; - scrubNumericIds = settings.scrubNumericIds; scrubGuids = settings.scrubGuids; includeObsoletes = settings.includeObsoletes; - isNumericId = settings.isNumericId; jsonSettings = BuildSettings(); } @@ -80,16 +78,6 @@ public void DontScrubGuids() => public void DontScrubDateTimes() => scrubDateTimes = false; - internal bool scrubNumericIds = true; - - internal IsNumericId isNumericId = member => member.Name.EndsWith("Id"); - - public void TreatAsNumericId(IsNumericId isNumericId) => - this.isNumericId = isNumericId; - - public void DontScrubNumericIds() => - scrubNumericIds = false; - JsonSerializerSettings BuildSettings() { #region defaultSerialization diff --git a/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs b/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs index 9e1388feaf..8e6a0a5939 100644 --- a/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs +++ b/src/Verify/Serialization/VerifierSettings_SerializationMaps.cs @@ -20,12 +20,6 @@ public static void DontScrubGuids() => public static void DontScrubDateTimes() => serialization.DontScrubDateTimes(); - public static void DontScrubNumericIds() => - serialization.DontScrubNumericIds(); - - public static void TreatAsNumericId(IsNumericId isNumericId) => - serialization.TreatAsNumericId(isNumericId); - public static void IncludeObsoletes() => serialization.IncludeObsoletes(); diff --git a/src/Verify/Serialization/VerifySettings_SerializationMaps.cs b/src/Verify/Serialization/VerifySettings_SerializationMaps.cs index 5d35eeb8c0..99f4a35cd9 100644 --- a/src/Verify/Serialization/VerifySettings_SerializationMaps.cs +++ b/src/Verify/Serialization/VerifySettings_SerializationMaps.cs @@ -11,12 +11,6 @@ public void DontScrubDateTimes() => public void IgnoreStackTrack() => ModifySerialization(_ => _.IgnoreMember("StackTrace")); - public void DontScrubNumericIds() => - ModifySerialization(_ => _.DontScrubNumericIds()); - - public void TreatAsNumericId(IsNumericId isNumericId) => - ModifySerialization(_ => _.TreatAsNumericId(isNumericId)); - public void IncludeObsoletes() => ModifySerialization(_ => _.IncludeObsoletes()); diff --git a/src/Verify/SettingsTask_SerializationMaps.cs b/src/Verify/SettingsTask_SerializationMaps.cs index df2c461a62..f626d90f6f 100644 --- a/src/Verify/SettingsTask_SerializationMaps.cs +++ b/src/Verify/SettingsTask_SerializationMaps.cs @@ -8,12 +8,6 @@ public SettingsTask DontScrubGuids() => public SettingsTask DontScrubDateTimes() => ModifySerialization(_ => _.DontScrubDateTimes()); - public SettingsTask DontScrubNumericIds() => - ModifySerialization(_ => _.DontScrubNumericIds()); - - public SettingsTask TreatAsNumericId(IsNumericId isNumericId) => - ModifySerialization(_ => _.TreatAsNumericId(isNumericId)); - public SettingsTask IncludeObsoletes() => ModifySerialization(_ => _.IncludeObsoletes());