Skip to content

Commit 55282d4

Browse files
committed
numeric id sample
1 parent 810e8d9 commit 55282d4

File tree

7 files changed

+107
-1
lines changed

7 files changed

+107
-1
lines changed

docs/mdsource/numericIds.source.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Numeric Ids
2+
3+
snippet: NumericIdSample
4+
5+
Produces
6+
7+
snippet: NumericIdSample.Test.verified.txt

docs/mdsource/scrubbers.source.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,5 @@ snippet: Verify.Xunit.Tests/Scrubbers/ScrubberLevelsSample.Usage.verified.txt
168168
## See also
169169

170170
* [Guid behavior](guids.md)
171-
* [Date behavior](dates.md)
171+
* [Date behavior](dates.md)
172+
* [Numeric Ids](numericIds.md)

docs/numericIds.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!--
2+
GENERATED FILE - DO NOT EDIT
3+
This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).
4+
Source File: /docs/mdsource/numericIds.source.md
5+
To change this file edit the source file and then run MarkdownSnippets.
6+
-->
7+
8+
# Numeric Ids
9+
10+
<!-- snippet: NumericIdSample -->
11+
<a id='snippet-NumericIdSample'></a>
12+
```cs
13+
public class NumericIdSample
14+
{
15+
public class Target : IHasId
16+
{
17+
public required int Id { get; init; }
18+
public required string Name { get; init; }
19+
}
20+
21+
[ModuleInitializer]
22+
public static void Init() =>
23+
VerifierSettings.ScrubMembers(
24+
_ => typeof(IHasId).IsAssignableFrom(_.DeclaringType) &&
25+
_.Name == "Id");
26+
27+
[Fact]
28+
public Task Test()
29+
{
30+
var target = new Target
31+
{
32+
Id = new Random().Next(),
33+
Name = "The Name"
34+
};
35+
return Verify(target);
36+
}
37+
38+
public interface IHasId
39+
{
40+
public int Id { get; init; }
41+
}
42+
}
43+
```
44+
<sup><a href='/src/Verify.Tests/Snippets/NumericIdSample.cs#L1-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-NumericIdSample' title='Start of snippet'>anchor</a></sup>
45+
<!-- endSnippet -->
46+
47+
Produces
48+
49+
<!-- snippet: NumericIdSample.Test.verified.txt -->
50+
<a id='snippet-NumericIdSample.Test.verified.txt'></a>
51+
```txt
52+
{
53+
Id: {Scrubbed},
54+
Name: The Name
55+
}
56+
```
57+
<sup><a href='/src/Verify.Tests/Snippets/NumericIdSample.Test.verified.txt#L1-L4' title='Snippet source file'>snippet source</a> | <a href='#snippet-NumericIdSample.Test.verified.txt' title='Start of snippet'>anchor</a></sup>
58+
<!-- endSnippet -->

docs/scrubbers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,4 @@ A B C
861861

862862
* [Guid behavior](guids.md)
863863
* [Date behavior](dates.md)
864+
* [Numeric Ids](numericIds.md)

src/Verify.Tests/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
global using Argon;
55
global using DiffEngine;
66
global using EmptyFiles;
7+
global using Polyfills;
78
global using Xunit.Abstractions;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
Id: {Scrubbed},
3+
Name: The Name
4+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#region NumericIdSample
2+
3+
public class NumericIdSample
4+
{
5+
public class Target : IHasId
6+
{
7+
public required int Id { get; init; }
8+
public required string Name { get; init; }
9+
}
10+
11+
[ModuleInitializer]
12+
public static void Init() =>
13+
VerifierSettings.ScrubMembers(
14+
_ => typeof(IHasId).IsAssignableFrom(_.DeclaringType) &&
15+
_.Name == "Id");
16+
17+
[Fact]
18+
public Task Test()
19+
{
20+
var target = new Target
21+
{
22+
Id = new Random().Next(),
23+
Name = "The Name"
24+
};
25+
return Verify(target);
26+
}
27+
28+
public interface IHasId
29+
{
30+
public int Id { get; init; }
31+
}
32+
}
33+
34+
#endregion

0 commit comments

Comments
 (0)