Skip to content

Commit cb9f087

Browse files
authored
add ScrubUserName (#558)
1 parent 7adb38e commit cb9f087

File tree

12 files changed

+82
-24
lines changed

12 files changed

+82
-24
lines changed

docs/mdsource/scrubbers.source.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ Replaces `Environment.MachineName` with `TheMachineName`.
7878
snippet: ScrubMachineName
7979

8080

81+
### ScrubUserName
82+
83+
Replaces `Environment.UserName` with `TheUserName`.
84+
85+
snippet: ScrubUserName
86+
87+
8188
### AddScrubber
8289

8390
Adds a scrubber with full control over the text via a `Func`

docs/named-tuples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Given a method that returns a named tuple:
1919
static (bool Member1, string Member2, string Member3) MethodWithNamedTuple() =>
2020
(true, "A", "B");
2121
```
22-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L949-L954' title='Snippet source file'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Start of snippet'>anchor</a></sup>
22+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L960-L965' title='Snippet source file'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Start of snippet'>anchor</a></sup>
2323
<!-- endSnippet -->
2424

2525
Can be verified:
@@ -29,7 +29,7 @@ Can be verified:
2929
```cs
3030
await VerifyTuple(() => MethodWithNamedTuple());
3131
```
32-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L942-L946' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifytuple' title='Start of snippet'>anchor</a></sup>
32+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L953-L957' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifytuple' title='Start of snippet'>anchor</a></sup>
3333
<!-- endSnippet -->
3434

3535
Resulting in:

docs/scrubbers.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ verifySettings.ScrubMachineName();
115115
<!-- endSnippet -->
116116

117117

118+
### ScrubUserName
119+
120+
Replaces `Environment.UserName` with `TheUserName`.
121+
122+
<!-- snippet: ScrubUserName -->
123+
<a id='snippet-scrubusername'></a>
124+
```cs
125+
verifySettings.ScrubUserName();
126+
```
127+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L834-L838' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubusername' title='Start of snippet'>anchor</a></sup>
128+
<!-- endSnippet -->
129+
130+
118131
### AddScrubber
119132

120133
Adds a scrubber with full control over the text via a `Func`

docs/serializer-settings.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ var target = new GuidTarget
178178

179179
await Verify(target);
180180
```
181-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1009-L1022' title='Snippet source file'>snippet source</a> | <a href='#snippet-guid' title='Start of snippet'>anchor</a></sup>
181+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1020-L1033' title='Snippet source file'>snippet source</a> | <a href='#snippet-guid' title='Start of snippet'>anchor</a></sup>
182182
<!-- endSnippet -->
183183

184184
Results in the following:
@@ -474,7 +474,7 @@ public Task ScopedSerializerFluent()
474474
.AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All);
475475
}
476476
```
477-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2161-L2188' title='Snippet source file'>snippet source</a> | <a href='#snippet-scopedserializer' title='Start of snippet'>anchor</a></sup>
477+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2174-L2201' title='Snippet source file'>snippet source</a> | <a href='#snippet-scopedserializer' title='Start of snippet'>anchor</a></sup>
478478
<!-- endSnippet -->
479479

480480
Result:
@@ -602,7 +602,7 @@ public Task IgnoreTypeFluent()
602602
.IgnoreMembersWithType<ToIgnoreStruct>();
603603
}
604604
```
605-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1399-L1504' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretype' title='Start of snippet'>anchor</a></sup>
605+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1412-L1517' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretype' title='Start of snippet'>anchor</a></sup>
606606
<!-- endSnippet -->
607607

608608
Or globally:
@@ -612,7 +612,7 @@ Or globally:
612612
```cs
613613
VerifierSettings.IgnoreMembersWithType<ToIgnore>();
614614
```
615-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1392-L1396' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretypeglobal' title='Start of snippet'>anchor</a></sup>
615+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1405-L1409' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretypeglobal' title='Start of snippet'>anchor</a></sup>
616616
<!-- endSnippet -->
617617

618618
Result:
@@ -683,7 +683,7 @@ public Task AddIgnoreInstanceFluent()
683683
.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
684684
}
685685
```
686-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1320-L1359' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstance' title='Start of snippet'>anchor</a></sup>
686+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1333-L1372' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstance' title='Start of snippet'>anchor</a></sup>
687687
<!-- endSnippet -->
688688

689689
Or globally:
@@ -693,7 +693,7 @@ Or globally:
693693
```cs
694694
VerifierSettings.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
695695
```
696-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1313-L1317' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstanceglobal' title='Start of snippet'>anchor</a></sup>
696+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1326-L1330' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstanceglobal' title='Start of snippet'>anchor</a></sup>
697697
<!-- endSnippet -->
698698

699699
Result:
@@ -736,7 +736,7 @@ public Task WithObsoleteProp()
736736
return Verify(target);
737737
}
738738
```
739-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2125-L2145' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoleteprop' title='Start of snippet'>anchor</a></sup>
739+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2138-L2158' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoleteprop' title='Start of snippet'>anchor</a></sup>
740740
<!-- endSnippet -->
741741

742742
Result:
@@ -784,7 +784,7 @@ public Task WithObsoletePropIncludedFluent()
784784
.IncludeObsoletes();
785785
}
786786
```
787-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2096-L2123' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincluded' title='Start of snippet'>anchor</a></sup>
787+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2109-L2136' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincluded' title='Start of snippet'>anchor</a></sup>
788788
<!-- endSnippet -->
789789

790790
Or globally:
@@ -794,7 +794,7 @@ Or globally:
794794
```cs
795795
VerifierSettings.IncludeObsoletes();
796796
```
797-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2089-L2093' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincludedglobally' title='Start of snippet'>anchor</a></sup>
797+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2102-L2106' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincludedglobally' title='Start of snippet'>anchor</a></sup>
798798
<!-- endSnippet -->
799799

800800
Result:
@@ -855,7 +855,7 @@ public Task IgnoreMemberByExpressionFluent()
855855
_ => _.PropertyThatThrows);
856856
}
857857
```
858-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1684-L1723' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpression' title='Start of snippet'>anchor</a></sup>
858+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1697-L1736' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpression' title='Start of snippet'>anchor</a></sup>
859859
<!-- endSnippet -->
860860

861861
Or globally
@@ -870,7 +870,7 @@ VerifierSettings.IgnoreMembers<IgnoreExplicitTarget>(
870870
_ => _.GetOnlyProperty,
871871
_ => _.PropertyThatThrows);
872872
```
873-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1672-L1681' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpressionglobal' title='Start of snippet'>anchor</a></sup>
873+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1685-L1694' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpressionglobal' title='Start of snippet'>anchor</a></sup>
874874
<!-- endSnippet -->
875875

876876
Result:
@@ -944,7 +944,7 @@ public Task IgnoreMemberByNameFluent()
944944
.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
945945
}
946946
```
947-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1776-L1829' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyname' title='Start of snippet'>anchor</a></sup>
947+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1789-L1842' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyname' title='Start of snippet'>anchor</a></sup>
948948
<!-- endSnippet -->
949949

950950
Or globally:
@@ -964,7 +964,7 @@ VerifierSettings.IgnoreMember<IgnoreExplicitTarget>("Field");
964964
// For a specific type with expression
965965
VerifierSettings.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
966966
```
967-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1759-L1773' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbynameglobal' title='Start of snippet'>anchor</a></sup>
967+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1772-L1786' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbynameglobal' title='Start of snippet'>anchor</a></sup>
968968
<!-- endSnippet -->
969969

970970
Result:
@@ -1011,7 +1011,7 @@ public Task CustomExceptionPropFluent()
10111011
.IgnoreMembersThatThrow<CustomException>();
10121012
}
10131013
```
1014-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1981-L2000' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrow' title='Start of snippet'>anchor</a></sup>
1014+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1994-L2013' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrow' title='Start of snippet'>anchor</a></sup>
10151015
<!-- endSnippet -->
10161016

10171017
Or globally:
@@ -1021,7 +1021,7 @@ Or globally:
10211021
```cs
10221022
VerifierSettings.IgnoreMembersThatThrow<CustomException>();
10231023
```
1024-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1974-L1978' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowglobal' title='Start of snippet'>anchor</a></sup>
1024+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1987-L1991' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowglobal' title='Start of snippet'>anchor</a></sup>
10251025
<!-- endSnippet -->
10261026

10271027
Result:
@@ -1058,7 +1058,7 @@ public Task ExceptionMessagePropFluent()
10581058
.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
10591059
}
10601060
```
1061-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1188-L1209' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpression' title='Start of snippet'>anchor</a></sup>
1061+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1199-L1220' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpression' title='Start of snippet'>anchor</a></sup>
10621062
<!-- endSnippet -->
10631063

10641064
Or globally:
@@ -1068,7 +1068,7 @@ Or globally:
10681068
```cs
10691069
VerifierSettings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
10701070
```
1071-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1181-L1185' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpressionglobal' title='Start of snippet'>anchor</a></sup>
1071+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1192-L1196' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpressionglobal' title='Start of snippet'>anchor</a></sup>
10721072
<!-- endSnippet -->
10731073

10741074
Result:
@@ -1228,7 +1228,7 @@ public Task MemberConverterByExpression()
12281228
return Verify(input);
12291229
}
12301230
```
1231-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1725-L1749' title='Snippet source file'>snippet source</a> | <a href='#snippet-memberconverter' title='Start of snippet'>anchor</a></sup>
1231+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1738-L1762' title='Snippet source file'>snippet source</a> | <a href='#snippet-memberconverter' title='Start of snippet'>anchor</a></sup>
12321232
<!-- endSnippet -->
12331233

12341234

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public Task VerifyJsonJToken()
349349
return VerifyJson(target);
350350
}
351351
```
352-
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1905-L1937' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyjson' title='Start of snippet'>anchor</a></sup>
352+
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1918-L1950' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyjson' title='Start of snippet'>anchor</a></sup>
353353
<!-- endSnippet -->
354354

355355
Results in:

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436</NoWarn>
5-
<Version>17.4.2</Version>
5+
<Version>17.5.0</Version>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<LangVersion>preview</LangVersion>
88
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TheUserName

src/Verify.Tests/Serialization/SerializationTests.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,12 @@ void List()
831831

832832
#endregion
833833

834+
#region ScrubUserName
835+
836+
verifySettings.ScrubUserName();
837+
838+
#endregion
839+
834840
#region AddScrubber
835841

836842
verifySettings.AddScrubber(_ => _.Remove(0, 100));
@@ -866,6 +872,11 @@ public Task ScrubCurrentDirectory()
866872
});
867873
}
868874

875+
[Fact]
876+
public Task ScrubUserName() =>
877+
Verify(Environment.UserName)
878+
.ScrubUserName();
879+
869880
[Fact]
870881
public Task MoreSpecificScrubberShouldOverride()
871882
{
@@ -1264,10 +1275,12 @@ public Task TestEnumerableWithExistingItemConverter()
12641275
{
12651276
"Value"
12661277
};
1267-
return Verify(target).AddExtraSettings(_ => _.Converters.Add(new EnumerableWithExistingItemConverter()));
1278+
return Verify(target)
1279+
.AddExtraSettings(_ => _.Converters.Add(new EnumerableWithExistingItemConverter()));
12681280
}
12691281

1270-
class EnumerableWithExistingItemConverterTarget: List<string>
1282+
class EnumerableWithExistingItemConverterTarget :
1283+
List<string>
12711284
{
12721285
}
12731286

src/Verify/Serialization/Scrubbers/Scrubbers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ public static class Scrubbers
55
public static void ScrubMachineName(StringBuilder builder) =>
66
builder.Replace(Environment.MachineName, "TheMachineName");
77

8+
public static void ScrubUserName(StringBuilder builder) =>
9+
builder.Replace(Environment.UserName, "TheUserName");
10+
811
public static string? ScrubStackTrace(string? stackTrace, bool removeParams = false)
912
{
1013
if (stackTrace is null)

src/Verify/Serialization/Scrubbers/VerifierSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,10 @@ public static void ScrubLinesContaining(params string[] stringToMatch) =>
7171
/// </summary>
7272
public static void ScrubMachineName() =>
7373
AddScrubber(Scrubbers.ScrubMachineName);
74+
75+
/// <summary>
76+
/// Remove the <see cref="Environment.UserName" /> from the test results.
77+
/// </summary>
78+
public static void ScrubUserName() =>
79+
AddScrubber(Scrubbers.ScrubUserName);
7480
}

0 commit comments

Comments
 (0)