зеркало из https://github.com/VerifyTests/Verify.git
Date scrubbing (#1097)
This commit is contained in:
Родитель
75e1a7a026
Коммит
e0641fab3a
|
@ -71,7 +71,7 @@ settings.DontScrubDateTimes();
|
|||
|
||||
return Verify(target, settings);
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1456-L1468' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubdatetimes' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1598-L1610' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubdatetimes' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ var target = new
|
|||
return Verify(target)
|
||||
.DontScrubDateTimes();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1474-L1484' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubdatetimesfluent' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1616-L1626' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubdatetimesfluent' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -99,7 +99,7 @@ return Verify(target)
|
|||
```cs
|
||||
VerifierSettings.DontScrubDateTimes();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1491-L1495' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubdatetimesglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1633-L1637' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubdatetimesglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -126,6 +126,60 @@ public Task WithExtraDatetimeFormat() =>
|
|||
<!-- endSnippet -->
|
||||
|
||||
|
||||
## Inline Dates
|
||||
|
||||
Strings containing inline dates can also be scrubbed. There a equivalent APIs for `DateOnly`, `DateTime`, and `DateTimeOffset`.
|
||||
|
||||
|
||||
### Instance
|
||||
|
||||
<!-- snippet: ScrubInlineDateTimesInstance -->
|
||||
<a id='snippet-scrubinlinedatetimesinstance'></a>
|
||||
```cs
|
||||
[Fact]
|
||||
public Task ScrubInlineDateTimesInstance()
|
||||
{
|
||||
var settings = new VerifySettings();
|
||||
settings.ScrubInlineDateTimes("yyyy-MM-dd");
|
||||
return Verify(
|
||||
"content 2020-10-20 content",
|
||||
settings);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1568-L1580' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlinedatetimesinstance' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
### Fluent
|
||||
|
||||
<!-- snippet: ScrubInlineDateTimesFluent -->
|
||||
<a id='snippet-scrubinlinedatetimesfluent'></a>
|
||||
```cs
|
||||
[Fact]
|
||||
public Task ScrubInlineDateTimesFluent() =>
|
||||
Verify("content 2020-10-20 content")
|
||||
.ScrubInlineDateTimes("yyyy-MM-dd");
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1559-L1566' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlinedatetimesfluent' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
### Globally
|
||||
|
||||
<!-- snippet: ScrubInlineDateTimesGlobal -->
|
||||
<a id='snippet-scrubinlinedatetimesglobal'></a>
|
||||
```cs
|
||||
public static class ModuleInitializer
|
||||
{
|
||||
[ModuleInitializer]
|
||||
public static void Init() =>
|
||||
VerifierSettings.ScrubInlineDateTimes("yyyy-MM-dd");
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1547-L1556' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlinedatetimesglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
## Named Date and Times
|
||||
|
||||
Specific date or times can be named. When any of those values are found, they will be matched with the corresponding name.
|
||||
|
|
|
@ -23,7 +23,7 @@ var target = new GuidTarget
|
|||
|
||||
await Verify(target);
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1741-L1754' title='Snippet source file'>snippet source</a> | <a href='#snippet-guid' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1883-L1896' title='Snippet source file'>snippet source</a> | <a href='#snippet-guid' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Results in the following:
|
||||
|
@ -79,7 +79,7 @@ await Verify(target)
|
|||
```cs
|
||||
VerifierSettings.DontScrubGuids();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1377-L1381' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubguidsglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1483-L1487' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontscrubguidsglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -103,7 +103,7 @@ public Task ScrubInlineGuidsInstance()
|
|||
settings);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1426-L1438' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlineguidsinstance' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1532-L1544' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlineguidsinstance' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -117,7 +117,7 @@ public Task ScrubInlineGuidsFluent() =>
|
|||
Verify("content 651ad409-fc30-4b12-a47e-616d3f953e4c content")
|
||||
.ScrubInlineGuids();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1417-L1424' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlineguidsfluent' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1523-L1530' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlineguidsfluent' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -133,7 +133,7 @@ public static class ModuleInitializer
|
|||
VerifierSettings.ScrubInlineGuids();
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1405-L1414' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlineguidsglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1511-L1520' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubinlineguidsglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,26 @@ snippet: DontScrubDateTimesGlobal
|
|||
snippet: AddExtraDatetimeFormat
|
||||
|
||||
|
||||
## Inline Dates
|
||||
|
||||
Strings containing inline dates can also be scrubbed. There a equivalent APIs for `DateOnly`, `DateTime`, and `DateTimeOffset`.
|
||||
|
||||
|
||||
### Instance
|
||||
|
||||
snippet: ScrubInlineDateTimesInstance
|
||||
|
||||
|
||||
### Fluent
|
||||
|
||||
snippet: ScrubInlineDateTimesFluent
|
||||
|
||||
|
||||
### Globally
|
||||
|
||||
snippet: ScrubInlineDateTimesGlobal
|
||||
|
||||
|
||||
## Named Date and Times
|
||||
|
||||
Specific date or times can be named. When any of those values are found, they will be matched with the corresponding name.
|
||||
|
|
|
@ -19,7 +19,7 @@ Given a method that returns a named tuple:
|
|||
static (bool Member1, string Member2, string Member3) MethodWithNamedTuple() =>
|
||||
(true, "A", "B");
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1676-L1681' title='Snippet source file'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1818-L1823' title='Snippet source file'>snippet source</a> | <a href='#snippet-methodwithnamedtuple' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Can be verified:
|
||||
|
@ -29,7 +29,7 @@ Can be verified:
|
|||
```cs
|
||||
await VerifyTuple(() => MethodWithNamedTuple());
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1669-L1673' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifytuple' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1811-L1815' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifytuple' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Resulting in:
|
||||
|
|
|
@ -683,7 +683,7 @@ public static string NameWithParent(this Type type)
|
|||
return type.Name;
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify/Extensions.cs#L95-L107' title='Snippet source file'>snippet source</a> | <a href='#snippet-namewithparent' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify/Extensions.cs#L100-L112' title='Snippet source file'>snippet source</a> | <a href='#snippet-namewithparent' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ For example remove lines containing `text`:
|
|||
```cs
|
||||
verifySettings.ScrubLines(line => line.Contains("text"));
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1510-L1514' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublines' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1652-L1656' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublines' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ For example remove lines containing `text1` or `text2`
|
|||
```cs
|
||||
verifySettings.ScrubLinesContaining("text1", "text2");
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1516-L1520' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontaining' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1658-L1662' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontaining' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Case insensitive by default (StringComparison.OrdinalIgnoreCase).
|
||||
|
@ -85,7 +85,7 @@ Case insensitive by default (StringComparison.OrdinalIgnoreCase).
|
|||
```cs
|
||||
verifySettings.ScrubLinesContaining(StringComparison.Ordinal, "text1", "text2");
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1522-L1526' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontainingordinal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1664-L1668' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublinescontainingordinal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -100,7 +100,7 @@ For example converts lines to upper case:
|
|||
```cs
|
||||
verifySettings.ScrubLinesWithReplace(line => line.ToUpper());
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1528-L1532' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublineswithreplace' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1670-L1674' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrublineswithreplace' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ Replaces `Environment.MachineName` with `TheMachineName`.
|
|||
```cs
|
||||
verifySettings.ScrubMachineName();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1534-L1538' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmachinename' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1676-L1680' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmachinename' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -126,7 +126,7 @@ Replaces `Environment.UserName` with `TheUserName`.
|
|||
```cs
|
||||
verifySettings.ScrubUserName();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1540-L1544' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubusername' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1682-L1686' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubusername' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ To disable this behavior globally use:
|
|||
```cs
|
||||
VerifierSettings.DontIgnoreEmptyCollections();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1367-L1371' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontignoreemptycollections' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L1473-L1477' title='Snippet source file'>snippet source</a> | <a href='#snippet-dontignoreemptycollections' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
@ -308,7 +308,7 @@ public Task ScopedSerializerFluent()
|
|||
.AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3397-L3424' title='Snippet source file'>snippet source</a> | <a href='#snippet-scopedserializer' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3539-L3566' title='Snippet source file'>snippet source</a> | <a href='#snippet-scopedserializer' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -436,7 +436,7 @@ public Task IgnoreTypeFluent()
|
|||
.IgnoreMembersWithType<ToIgnoreStruct>();
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2428-L2533' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretype' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2570-L2675' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretype' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -446,7 +446,7 @@ Or globally:
|
|||
```cs
|
||||
VerifierSettings.IgnoreMembersWithType<ToIgnore>();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2415-L2419' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretypeglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2557-L2561' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoretypeglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -583,7 +583,7 @@ public Task ScrubTypeFluent()
|
|||
.ScrubMembersWithType<ToIgnoreStruct>();
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2536-L2641' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubtype' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2678-L2783' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubtype' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -593,7 +593,7 @@ Or globally:
|
|||
```cs
|
||||
VerifierSettings.ScrubMembersWithType<ToIgnore>();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2421-L2425' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubtypeglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2563-L2567' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubtypeglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -672,7 +672,7 @@ public Task AddIgnoreInstanceFluent()
|
|||
.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2301-L2340' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstance' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2443-L2482' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstance' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -682,7 +682,7 @@ Or globally:
|
|||
```cs
|
||||
VerifierSettings.IgnoreInstance<Instance>(_ => _.Property == "Ignore");
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2288-L2292' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstanceglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2430-L2434' title='Snippet source file'>snippet source</a> | <a href='#snippet-addignoreinstanceglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -744,7 +744,7 @@ public Task AddScrubInstanceFluent()
|
|||
.ScrubInstance<Instance>(_ => _.Property == "Ignore");
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2342-L2381' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubinstance' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2484-L2523' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubinstance' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -754,7 +754,7 @@ Or globally:
|
|||
```cs
|
||||
VerifierSettings.ScrubInstance<Instance>(_ => _.Property == "Ignore");
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2294-L2298' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubinstanceglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2436-L2440' title='Snippet source file'>snippet source</a> | <a href='#snippet-addscrubinstanceglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -799,7 +799,7 @@ public Task WithObsoleteProp()
|
|||
return Verify(target);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3362-L3383' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoleteprop' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3504-L3525' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoleteprop' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -847,7 +847,7 @@ public Task WithObsoletePropIncludedFluent()
|
|||
.IncludeObsoletes();
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3333-L3360' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincluded' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3475-L3502' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincluded' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -857,7 +857,7 @@ Or globally:
|
|||
```cs
|
||||
VerifierSettings.IncludeObsoletes();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3326-L3330' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincludedglobally' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3468-L3472' title='Snippet source file'>snippet source</a> | <a href='#snippet-withobsoletepropincludedglobally' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -918,7 +918,7 @@ public Task IgnoreMemberByExpressionFluent()
|
|||
_ => _.PropertyThatThrows);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2844-L2883' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpression' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2986-L3025' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpression' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally
|
||||
|
@ -933,7 +933,7 @@ VerifierSettings.IgnoreMembers<IgnoreExplicitTarget>(
|
|||
_ => _.GetOnlyProperty,
|
||||
_ => _.PropertyThatThrows);
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2821-L2830' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpressionglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2963-L2972' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyexpressionglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -993,7 +993,7 @@ public Task ScrubMemberByExpressionFluent()
|
|||
_ => _.PropertyThatThrows);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2885-L2924' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbyexpression' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3027-L3066' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbyexpression' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally
|
||||
|
@ -1008,7 +1008,7 @@ VerifierSettings.ScrubMembers<IgnoreExplicitTarget>(
|
|||
_ => _.GetOnlyProperty,
|
||||
_ => _.PropertyThatThrows);
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2832-L2841' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbyexpressionglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2974-L2983' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbyexpressionglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -1087,7 +1087,7 @@ public Task IgnoreMemberByNameFluent()
|
|||
.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2998-L3051' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyname' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3140-L3193' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbyname' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -1107,7 +1107,7 @@ VerifierSettings.IgnoreMember<IgnoreExplicitTarget>("Field");
|
|||
// For a specific type with expression
|
||||
VerifierSettings.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2965-L2979' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbynameglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3107-L3121' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignorememberbynameglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -1182,7 +1182,7 @@ public Task ScrubMemberByNameFluent()
|
|||
.ScrubMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3053-L3106' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbyname' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3195-L3248' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbyname' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -1202,7 +1202,7 @@ VerifierSettings.ScrubMember<IgnoreExplicitTarget>("Field");
|
|||
// For a specific type with expression
|
||||
VerifierSettings.ScrubMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2981-L2995' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbynameglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3123-L3137' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrubmemberbynameglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -1253,7 +1253,7 @@ public Task CustomExceptionPropFluent()
|
|||
.IgnoreMembersThatThrow<CustomException>();
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3214-L3233' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrow' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3356-L3375' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrow' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -1263,7 +1263,7 @@ Or globally:
|
|||
```cs
|
||||
VerifierSettings.IgnoreMembersThatThrow<CustomException>();
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3207-L3211' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3349-L3353' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -1300,7 +1300,7 @@ public Task ExceptionMessagePropFluent()
|
|||
.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2076-L2097' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpression' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2218-L2239' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpression' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Or globally:
|
||||
|
@ -1310,7 +1310,7 @@ Or globally:
|
|||
```cs
|
||||
VerifierSettings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2069-L2073' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpressionglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2211-L2215' title='Snippet source file'>snippet source</a> | <a href='#snippet-ignoremembersthatthrowexpressionglobal' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
Result:
|
||||
|
@ -1468,7 +1468,7 @@ public Task MemberConverterByExpression()
|
|||
return Verify(input);
|
||||
}
|
||||
```
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2926-L2954' title='Snippet source file'>snippet source</a> | <a href='#snippet-memberconverter' title='Start of snippet'>anchor</a></sup>
|
||||
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3068-L3096' title='Snippet source file'>snippet source</a> | <a href='#snippet-memberconverter' title='Start of snippet'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Title": "item DateTime_1 - (date={DateTime_1})",
|
||||
"Variant": {
|
||||
"Id": "variant date: DateTime_1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
content DateTime_1 content
|
|
@ -0,0 +1 @@
|
|||
content DateTime_1 content
|
|
@ -0,0 +1 @@
|
|||
DateTime_1after
|
|
@ -0,0 +1 @@
|
|||
beforeDateTime_1
|
|
@ -0,0 +1 @@
|
|||
-DateTime_1-
|
|
@ -0,0 +1 @@
|
|||
beforeDateTime_1after
|
|
@ -0,0 +1 @@
|
|||
1DateTime_11
|
|
@ -0,0 +1 @@
|
|||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
DateTime_1/
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
DateTime_1
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
/DateTime_1
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
(DateTime_1)
|
|
@ -0,0 +1 @@
|
|||
/DateTime_1/
|
|
@ -0,0 +1,129 @@
|
|||
#if NET8_0
|
||||
[UsesVerify]
|
||||
public class CultureToDateBuilder
|
||||
{
|
||||
const string monthDayFormat = "MMMM MMM dddd ddd";
|
||||
|
||||
[Fact]
|
||||
public Task BuildCultureToDate()
|
||||
{
|
||||
if (Environment.OSVersion.Version.Build < 22000)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
|
||||
var builder = new StringBuilder(
|
||||
"""
|
||||
// <auto-generated />
|
||||
static partial class DateScrubber
|
||||
{
|
||||
static Dictionary<string, CultureDate> cultureDates = new()
|
||||
{
|
||||
|
||||
""");
|
||||
foreach (var culture in cultures)
|
||||
{
|
||||
var (longDate, shortDate) = FindDates(culture);
|
||||
if (culture.Name.Contains('-'))
|
||||
{
|
||||
var (parentLongDate, parentShortDate) = FindDates(culture.Parent);
|
||||
if (longDate == parentLongDate && shortDate == parentShortDate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
builder.AppendLine(
|
||||
$$"""
|
||||
{
|
||||
"{{culture.Name}}",
|
||||
new(
|
||||
new(2023, {{longDate.Month}}, {{longDate.Day}}, {{longDate.Hour}}, 0, 0),
|
||||
new(2023, {{shortDate.Month}}, {{shortDate.Day}}, {{shortDate.Hour}}, 0, 0))
|
||||
},
|
||||
""");
|
||||
}
|
||||
|
||||
builder.AppendLine(
|
||||
"""
|
||||
};
|
||||
}
|
||||
""");
|
||||
var file = Path.Combine(AttributeReader.GetSolutionDirectory(), "Verify/Serialization/Scrubbers/DateScrubber_Generated.cs");
|
||||
File.Delete(file);
|
||||
return File.WriteAllTextAsync(file, builder.ToString());
|
||||
}
|
||||
|
||||
static (DateTime longDate, DateTime shortDate) FindDates(CultureInfo culture)
|
||||
{
|
||||
var formatInfo = culture.DateTimeFormat;
|
||||
var longDate = FindLongDate(formatInfo);
|
||||
var shortDate = FindShortDate(formatInfo);
|
||||
return (longDate, shortDate);
|
||||
}
|
||||
|
||||
static DateTime FindLongDate(DateTimeFormatInfo formatInfo)
|
||||
{
|
||||
DateTime longDate = default;
|
||||
var longFormatted = "";
|
||||
var amLength = formatInfo.AMDesignator.Length;
|
||||
var pmLength = formatInfo.PMDesignator.Length;
|
||||
for (var month = 1; month <= 12; month++)
|
||||
{
|
||||
for (var day = 20; day <= 27; day++)
|
||||
{
|
||||
DateTime date;
|
||||
if (amLength > pmLength)
|
||||
{
|
||||
date = new(2023, month, day, 1, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
date = new(2023, month, day, 13, 0, 0, 0);
|
||||
}
|
||||
|
||||
var formatted = date.ToString(monthDayFormat, formatInfo);
|
||||
if (formatted.Length > longFormatted.Length)
|
||||
{
|
||||
longFormatted = formatted;
|
||||
longDate = date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return longDate;
|
||||
}
|
||||
|
||||
static DateTime FindShortDate(DateTimeFormatInfo formatInfo)
|
||||
{
|
||||
DateTime shortDate = default;
|
||||
string? shortFormatted = null;
|
||||
var amLength = formatInfo.AMDesignator.Length;
|
||||
var pmLength = formatInfo.PMDesignator.Length;
|
||||
for (var month = 1; month <= 12; month++)
|
||||
{
|
||||
for (var day = 1; day <= 7; day++)
|
||||
{
|
||||
DateTime date;
|
||||
if (amLength < pmLength)
|
||||
{
|
||||
date = new(2023, month, day, 1, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
date = new(2023, month, day, 13, 0, 0, 0);
|
||||
}
|
||||
|
||||
var formatted = date.ToString(monthDayFormat, formatInfo);
|
||||
if (shortFormatted == null ||
|
||||
formatted.Length < shortFormatted.Length)
|
||||
{
|
||||
shortFormatted = formatted;
|
||||
shortDate = date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return shortDate;
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1 @@
|
|||
DateTimeOffset_1 DateTimeOffset_1 DateTimeOffset_2
|
|
@ -0,0 +1 @@
|
|||
dateTimeOffsetName
|
|
@ -0,0 +1 @@
|
|||
aaaa
|
|
@ -0,0 +1 @@
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
@ -0,0 +1 @@
|
|||
DateTimeOffset_1
|
|
@ -0,0 +1 @@
|
|||
aDateTimeOffset_1
|
|
@ -0,0 +1 @@
|
|||
DateTimeOffset_1b
|
|
@ -0,0 +1 @@
|
|||
aDateTimeOffset_1b
|
|
@ -0,0 +1 @@
|
|||
DateTime_1 DateTime_1 DateTime_2
|
|
@ -0,0 +1 @@
|
|||
dateTimeName
|
|
@ -0,0 +1 @@
|
|||
aaaa
|
|
@ -0,0 +1 @@
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
@ -0,0 +1 @@
|
|||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
aDateTime_1
|
|
@ -0,0 +1 @@
|
|||
DateTime_1b
|
|
@ -0,0 +1 @@
|
|||
aDateTime_1b
|
|
@ -0,0 +1 @@
|
|||
Date_1 Date_1 Date_2
|
|
@ -0,0 +1 @@
|
|||
dateName
|
|
@ -0,0 +1 @@
|
|||
aaaa
|
|
@ -0,0 +1 @@
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
@ -0,0 +1 @@
|
|||
Date_1
|
|
@ -0,0 +1 @@
|
|||
aDate_1
|
|
@ -0,0 +1 @@
|
|||
Date_1b
|
|
@ -0,0 +1 @@
|
|||
aDate_1b
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
invarient: {
|
||||
Long: DateTime_1,
|
||||
Short: DateTime_2
|
||||
},
|
||||
parent: {
|
||||
Long: DateTime_3,
|
||||
Short: DateTime_2
|
||||
},
|
||||
child: {
|
||||
Long: DateTime_3,
|
||||
Short: DateTime_2
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: instanceNamed
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: Date_1
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: instanceNamed
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: DateTime_1
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: instanceNamed
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: DateTimeOffset_1
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: instanceNamed
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: dateTimeOffsetName
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: instanceNamed
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: dateTimeName
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: instanceNamed
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value: dateName
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
DateTimeOffset_1 DateTimeOffset_1 DateTimeOffset_2
|
|
@ -0,0 +1 @@
|
|||
dateTimeOffsetName
|
|
@ -0,0 +1 @@
|
|||
aaaa
|
|
@ -0,0 +1 @@
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
@ -0,0 +1 @@
|
|||
DateTimeOffset_1
|
|
@ -0,0 +1 @@
|
|||
aDateTimeOffset_1
|
|
@ -0,0 +1 @@
|
|||
DateTimeOffset_1b
|
|
@ -0,0 +1 @@
|
|||
aDateTimeOffset_1b
|
|
@ -0,0 +1 @@
|
|||
DateTime_1 DateTime_1 DateTime_2
|
|
@ -0,0 +1 @@
|
|||
dateTimeName
|
|
@ -0,0 +1 @@
|
|||
aaaa
|
|
@ -0,0 +1 @@
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
@ -0,0 +1 @@
|
|||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
aDateTime_1
|
|
@ -0,0 +1 @@
|
|||
DateTime_1b
|
|
@ -0,0 +1 @@
|
|||
aDateTime_1b
|
|
@ -0,0 +1 @@
|
|||
Date_1 Date_1 Date_2
|
|
@ -0,0 +1 @@
|
|||
dateName
|
|
@ -0,0 +1 @@
|
|||
aaaa
|
|
@ -0,0 +1 @@
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
@ -0,0 +1 @@
|
|||
Date_1
|
|
@ -0,0 +1 @@
|
|||
aDate_1
|
|
@ -0,0 +1 @@
|
|||
Date_1b
|
|
@ -0,0 +1 @@
|
|||
aDate_1b
|
|
@ -0,0 +1,304 @@
|
|||
// ReSharper disable StringLiteralTypo
|
||||
[UsesVerify]
|
||||
public class DateScrubberTests
|
||||
{
|
||||
#region NamedDate
|
||||
|
||||
[ModuleInitializer]
|
||||
public static void Init()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
VerifierSettings.AddNamedDate(new(1998, 10, 1), "dateName");
|
||||
#endif
|
||||
VerifierSettings.AddNamedDateTime(new(1998, 10, 1), "dateTimeName");
|
||||
VerifierSettings.AddNamedDateTimeOffset(new(new(1998, 10, 1)), "dateTimeOffsetName");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Fact]
|
||||
public Task GetCultureDates() =>
|
||||
Verify(
|
||||
new
|
||||
{
|
||||
invarient = DateScrubber.GetCultureDates(CultureInfo.InvariantCulture),
|
||||
parent = DateScrubber.GetCultureDates(CultureInfo.GetCultureInfo("de")),
|
||||
child = DateScrubber.GetCultureDates(CultureInfo.GetCultureInfo("de-DE"))
|
||||
});
|
||||
|
||||
[Theory]
|
||||
[InlineData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "no match")]
|
||||
[InlineData("aaaa", "no match short")]
|
||||
[InlineData("1995-10-01", "simple")]
|
||||
[InlineData("a1995-10-01b", "wrapped")]
|
||||
[InlineData("1995-10-01b", "trailing")]
|
||||
[InlineData("a1995-10-01", "starting")]
|
||||
[InlineData("1995-10-01 1995-10-01 1995-10-02", "multiple")]
|
||||
[InlineData("1998-10-01", "named")]
|
||||
public async Task DateTimeOffsets(string value, string name)
|
||||
{
|
||||
var counter = Counter.Start();
|
||||
try
|
||||
{
|
||||
var builder = new StringBuilder(value);
|
||||
DateScrubber.ReplaceDateTimeOffsets(builder, "yyyy-MM-dd", counter, CultureInfo.InvariantCulture);
|
||||
await Verify(builder)
|
||||
.UseTextForParameters(name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Counter.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "no match")]
|
||||
[InlineData("aaaa", "no match short")]
|
||||
[InlineData("2023 December 21 Thursday", "simple")]
|
||||
[InlineData("a2023 December 21 Thursdayb", "wrapped")]
|
||||
[InlineData("2023 December 21 Thursdayb", "trailing")]
|
||||
[InlineData("a2023 December 21 Thursday", "starting")]
|
||||
[InlineData("2023 December 21 Thursday 2023 December 21 Thursday 2023 December 22 Friday", "multiple")]
|
||||
[InlineData("1998 October 01 Thursday", "named")]
|
||||
public async Task VariableLengthDateTimeOffsets(string value, string name)
|
||||
{
|
||||
var counter = Counter.Start();
|
||||
try
|
||||
{
|
||||
var builder = new StringBuilder(value);
|
||||
DateScrubber.ReplaceDateTimeOffsets(builder, "yyyy MMMM dd dddd", counter, CultureInfo.InvariantCulture);
|
||||
await Verify(builder)
|
||||
.UseTextForParameters(name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Counter.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1998-10-01", "named")]
|
||||
[InlineData("1935-10-01", "instanceNamed")]
|
||||
public Task NamedDateTimeOffsets(string value, string name) =>
|
||||
Verify(
|
||||
new
|
||||
{
|
||||
value = DateTimeOffset.Parse(value)
|
||||
})
|
||||
.AddNamedDateTimeOffset(new(new(1935, 10, 1)), "instanceNamed")
|
||||
.UseTextForParameters(name);
|
||||
|
||||
[Theory]
|
||||
[InlineData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "no match")]
|
||||
[InlineData("aaaa", "no match short")]
|
||||
[InlineData("1995-10-01", "simple")]
|
||||
[InlineData("a1995-10-01b", "wrapped")]
|
||||
[InlineData("1995-10-01b", "trailing")]
|
||||
[InlineData("a1995-10-01", "starting")]
|
||||
[InlineData("1995-10-01 1995-10-01 1995-10-02", "multiple")]
|
||||
[InlineData("1998-10-01", "named")]
|
||||
public async Task DateTimes(string value, string name)
|
||||
{
|
||||
var counter = Counter.Start();
|
||||
try
|
||||
{
|
||||
var builder = new StringBuilder(value);
|
||||
DateScrubber.ReplaceDateTimes(builder, "yyyy-MM-dd", counter, CultureInfo.InvariantCulture);
|
||||
await Verify(builder)
|
||||
.UseTextForParameters(name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Counter.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "no match")]
|
||||
[InlineData("aaaa", "no match short")]
|
||||
[InlineData("2023 December 21 Thursday", "simple")]
|
||||
[InlineData("a2023 December 21 Thursdayb", "wrapped")]
|
||||
[InlineData("2023 December 21 Thursdayb", "trailing")]
|
||||
[InlineData("a2023 December 21 Thursday", "starting")]
|
||||
[InlineData("2023 December 21 Thursday 2023 December 21 Thursday 2023 December 22 Friday", "multiple")]
|
||||
[InlineData("1998 October 01 Thursday", "named")]
|
||||
public async Task VariableLengthDateTimes(string value, string name)
|
||||
{
|
||||
var counter = Counter.Start();
|
||||
try
|
||||
{
|
||||
var builder = new StringBuilder(value);
|
||||
DateScrubber.ReplaceDateTimes(builder, "yyyy MMMM dd dddd", counter, CultureInfo.InvariantCulture);
|
||||
await Verify(builder)
|
||||
.UseTextForParameters(name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Counter.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1998-10-01", "named")]
|
||||
[InlineData("1935-10-01", "instanceNamed")]
|
||||
public Task NamedDateTimes(string value, string name) =>
|
||||
Verify(
|
||||
new
|
||||
{
|
||||
value = DateTime.Parse(value)
|
||||
})
|
||||
.AddNamedDateTime(new(1935, 10, 1), "instanceNamed")
|
||||
.UseTextForParameters(name);
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
[Theory]
|
||||
[InlineData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "no match")]
|
||||
[InlineData("aaaa", "no match short")]
|
||||
[InlineData("1995-10-01", "simple")]
|
||||
[InlineData("a1995-10-01b", "wrapped")]
|
||||
[InlineData("1995-10-01b", "trailing")]
|
||||
[InlineData("a1995-10-01", "starting")]
|
||||
[InlineData("1995-10-01 1995-10-01 1995-10-02", "multiple")]
|
||||
[InlineData("1998-10-01", "named")]
|
||||
public async Task Dates(string value, string name)
|
||||
{
|
||||
var counter = Counter.Start();
|
||||
try
|
||||
{
|
||||
var builder = new StringBuilder(value);
|
||||
DateScrubber.ReplaceDates(builder, "yyyy-MM-dd", counter, CultureInfo.InvariantCulture);
|
||||
await Verify(builder)
|
||||
.UseTextForParameters(name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Counter.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "no match")]
|
||||
[InlineData("aaaa", "no match short")]
|
||||
[InlineData("2023 December 21 Thursday", "simple")]
|
||||
[InlineData("a2023 December 21 Thursdayb", "wrapped")]
|
||||
[InlineData("2023 December 21 Thursdayb", "trailing")]
|
||||
[InlineData("a2023 December 21 Thursday", "starting")]
|
||||
[InlineData("2023 December 21 Thursday 2023 December 21 Thursday 2023 December 22 Friday", "multiple")]
|
||||
[InlineData("1998 October 01 Thursday", "named")]
|
||||
public async Task VariableLengthDates(string value, string name)
|
||||
{
|
||||
var counter = Counter.Start();
|
||||
try
|
||||
{
|
||||
var builder = new StringBuilder(value);
|
||||
DateScrubber.ReplaceDates(builder, "yyyy MMMM dd dddd", counter, CultureInfo.InvariantCulture);
|
||||
await Verify(builder)
|
||||
.UseTextForParameters(name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Counter.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1998-10-01", "named")]
|
||||
[InlineData("1935-10-01", "instanceNamed")]
|
||||
public Task NamedDates(string value, string name) =>
|
||||
Verify(
|
||||
new
|
||||
{
|
||||
value = Date.Parse(value)
|
||||
})
|
||||
.AddNamedDate(new(1935, 10, 1), "instanceNamed")
|
||||
.UseTextForParameters(name);
|
||||
|
||||
#region NamedDateInstance
|
||||
|
||||
[Fact]
|
||||
public Task NamedDateInstance()
|
||||
{
|
||||
var settings = new VerifySettings();
|
||||
settings.AddNamedDate(new(1935, 10, 1), "instanceNamed");
|
||||
return Verify(
|
||||
new
|
||||
{
|
||||
value = new Date(1935, 10, 1)
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NamedDateFluent
|
||||
|
||||
[Fact]
|
||||
public Task NamedDateFluent() =>
|
||||
Verify(
|
||||
new
|
||||
{
|
||||
value = new Date(1935, 10, 1)
|
||||
})
|
||||
.AddNamedDate(new(1935, 10, 1), "instanceNamed");
|
||||
|
||||
#endregion
|
||||
|
||||
#endif
|
||||
|
||||
#region NamedDateTimeInstance
|
||||
|
||||
[Fact]
|
||||
public Task NamedDateTimeInstance()
|
||||
{
|
||||
var settings = new VerifySettings();
|
||||
settings.AddNamedDateTime(new(1935, 10, 1), "instanceNamed");
|
||||
return Verify(
|
||||
new
|
||||
{
|
||||
value = new DateTime(1935, 10, 1)
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NamedDateTimeFluent
|
||||
|
||||
[Fact]
|
||||
public Task NamedDateTimeFluent() =>
|
||||
Verify(
|
||||
new
|
||||
{
|
||||
value = new DateTime(1935, 10, 1)
|
||||
})
|
||||
.AddNamedDateTime(new(1935, 10, 1), "instanceNamed");
|
||||
|
||||
#endregion
|
||||
|
||||
#region NamedDateTimeOffsetInstance
|
||||
|
||||
[Fact]
|
||||
public Task NamedDateTimeOffsetInstance()
|
||||
{
|
||||
var settings = new VerifySettings();
|
||||
settings.AddNamedDateTimeOffset(new(new(1935, 10, 1)), "instanceNamed");
|
||||
return Verify(
|
||||
new
|
||||
{
|
||||
value = new DateTimeOffset(new(1935, 10, 1))
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NamedDateTimeOffsetFluent
|
||||
|
||||
[Fact]
|
||||
public Task NamedDateTimeOffsetFluent() =>
|
||||
Verify(
|
||||
new
|
||||
{
|
||||
value = new DateTimeOffset(new(1935, 10, 1))
|
||||
})
|
||||
.AddNamedDateTimeOffset(new(new(1935, 10, 1)), "instanceNamed");
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
Title: item DateTime_1 - (date={DateTime_1}),
|
||||
Variant: {
|
||||
Id: variant date: DateTime_1
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
content DateTime_1 content
|
|
@ -0,0 +1 @@
|
|||
content DateTime_1 content
|
|
@ -0,0 +1 @@
|
|||
DateTime_1after
|
|
@ -0,0 +1 @@
|
|||
beforeDateTime_1
|
|
@ -0,0 +1 @@
|
|||
-DateTime_1-
|
|
@ -0,0 +1 @@
|
|||
beforeDateTime_1after
|
|
@ -0,0 +1 @@
|
|||
1DateTime_11
|
|
@ -0,0 +1 @@
|
|||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
DateTime_1
|
|
@ -0,0 +1 @@
|
|||
DateTime_1/
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
DateTime_1
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
DateTime_1
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче