Skip to content

Commit 3ab2a8c

Browse files
committed
docs
1 parent 684cf49 commit 3ab2a8c

25 files changed

+594
-16
lines changed

readme.md

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,281 @@ public static void Init() =>
2727
<!-- endSnippet -->
2828

2929

30+
### JsonDocument
31+
32+
<!-- snippet: JsonDocumentSample -->
33+
<a id='snippet-JsonDocumentSample'></a>
34+
```cs
35+
[Test]
36+
public Task JsonDocumentSample()
37+
{
38+
var json =
39+
"""
40+
{
41+
"short": {
42+
"original": "http://www.foo.com/",
43+
"short": "foo",
44+
"error": {
45+
"code": 0,
46+
"msg": "No action taken"
47+
}
48+
}
49+
}
50+
""";
51+
52+
var document = JsonDocument.Parse(json);
53+
return Verify(document);
54+
}
55+
```
56+
<sup><a href='/src/Tests/Samples.cs#L4-L27' title='Snippet source file'>snippet source</a> | <a href='#snippet-JsonDocumentSample' title='Start of snippet'>anchor</a></sup>
57+
<!-- endSnippet -->
58+
59+
Results in:
60+
61+
<!-- snippet: Samples.JsonDocumentSample.verified.txt -->
62+
<a id='snippet-Samples.JsonDocumentSample.verified.txt'></a>
63+
```txt
64+
{
65+
short: {
66+
original: http://www.foo.com/,
67+
short: foo,
68+
error: {
69+
code: 0,
70+
msg: No action taken
71+
}
72+
}
73+
}
74+
```
75+
<sup><a href='/src/Tests/Samples.JsonDocumentSample.verified.txt#L1-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-Samples.JsonDocumentSample.verified.txt' title='Start of snippet'>anchor</a></sup>
76+
<!-- endSnippet -->
77+
78+
### Strict Json
79+
80+
Note that the above does not result in json files. [This is by design](https://github.com/VerifyTests/Verify/blob/main/docs/serializer-settings.md#not-valid-json). If json files are required then use [UseStrictJson](https://github.com/VerifyTests/Verify/blob/main/docs/serializer-settings.md#usestrictjson)
81+
82+
This can be done at the Globally in a ModuleInitializer
83+
84+
<!-- snippet: StrictJson -->
85+
<a id='snippet-StrictJson'></a>
86+
```cs
87+
[ModuleInitializer]
88+
public static void Init() =>
89+
VerifierSettings.UseStrictJson();
90+
```
91+
<sup><a href='/src/TestsStrictJson/ModuleInitializer.cs#L3-L9' title='Snippet source file'>snippet source</a> | <a href='#snippet-StrictJson' title='Start of snippet'>anchor</a></sup>
92+
<!-- endSnippet -->
93+
94+
Or at the test level
95+
96+
<!-- snippet: JsonDocumentSampleStrictJson -->
97+
<a id='snippet-JsonDocumentSampleStrictJson'></a>
98+
```cs
99+
[Test]
100+
public Task JsonDocumentSample()
101+
{
102+
var json =
103+
"""
104+
{
105+
"short": {
106+
"original": "http://www.foo.com/",
107+
"short": "foo",
108+
"error": {
109+
"code": 0,
110+
"msg": "No action taken"
111+
}
112+
}
113+
}
114+
""";
115+
116+
var document = JsonDocument.Parse(json);
117+
return Verify(document)
118+
.UseStrictJson();
119+
}
120+
```
121+
<sup><a href='/src/TestsStrictJson/Samples.cs#L4-L28' title='Snippet source file'>snippet source</a> | <a href='#snippet-JsonDocumentSampleStrictJson' title='Start of snippet'>anchor</a></sup>
122+
<!-- endSnippet -->
123+
124+
Results in:
125+
126+
<!-- snippet: Samples.JsonDocumentSample.verified.json -->
127+
<a id='snippet-Samples.JsonDocumentSample.verified.json'></a>
128+
```json
129+
{
130+
"short": {
131+
"original": "http://www.foo.com/",
132+
"short": "foo",
133+
"error": {
134+
"code": 0,
135+
"msg": "No action taken"
136+
}
137+
}
138+
}
139+
```
140+
<sup><a href='/src/TestsStrictJson/Samples.JsonDocumentSample.verified.json#L1-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-Samples.JsonDocumentSample.verified.json' title='Start of snippet'>anchor</a></sup>
141+
<!-- endSnippet -->
142+
143+
144+
### Ignoring and Scrubbing
145+
146+
Values in the json can be ignored or scrubbed:
147+
148+
<!-- snippet: ScrubIgnoreMember -->
149+
<a id='snippet-ScrubIgnoreMember'></a>
150+
```cs
151+
[Test]
152+
public Task ScrubIgnoreMemberSample()
153+
{
154+
var json =
155+
"""
156+
{
157+
"node": {
158+
"original": "http://www.foo.com/",
159+
"short": "foo",
160+
"error": {
161+
"code": 0,
162+
"msg": "No action taken"
163+
}
164+
}
165+
}
166+
""";
167+
168+
var document = JsonDocument.Parse(json);
169+
return Verify(document)
170+
.ScrubMember("short")
171+
.IgnoreMember("msg");
172+
}
173+
```
174+
<sup><a href='/src/Tests/Samples.cs#L28-L53' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubIgnoreMember' title='Start of snippet'>anchor</a></sup>
175+
<!-- endSnippet -->
176+
177+
Results in:
178+
179+
<!-- snippet: Samples.ScrubIgnoreMemberSample.verified.txt -->
180+
<a id='snippet-Samples.ScrubIgnoreMemberSample.verified.txt'></a>
181+
```txt
182+
{
183+
node: {
184+
original: http://www.foo.com/,
185+
short: Scrubbed,
186+
error: {
187+
code: 0
188+
}
189+
}
190+
}
191+
```
192+
<sup><a href='/src/Tests/Samples.ScrubIgnoreMemberSample.verified.txt#L1-L9' title='Snippet source file'>snippet source</a> | <a href='#snippet-Samples.ScrubIgnoreMemberSample.verified.txt' title='Start of snippet'>anchor</a></sup>
193+
<!-- endSnippet -->
194+
195+
196+
### Dates and Guid scrubbing
197+
198+
Json values that map to known date and time formats are scrubbed. See [Guids scrubbing](https://github.com/VerifyTests/Verify/blob/main/docs/guids.md) and [Date scrubbing](https://github.com/VerifyTests/Verify/blob/main/docs/dates.md)
199+
200+
<!-- snippet: GuidsAndDates -->
201+
<a id='snippet-GuidsAndDates'></a>
202+
```cs
203+
[Test]
204+
public Task GuidsAndDatesSample()
205+
{
206+
var json =
207+
"""
208+
{
209+
"node": {
210+
"date": "1/10/2023",
211+
"short": "foo",
212+
"error": {
213+
"guid": "123e4567-e89b-12d3-a456-426614174000",
214+
"msg": "No action taken"
215+
}
216+
}
217+
}
218+
""";
219+
220+
var document = JsonDocument.Parse(json);
221+
return Verify(document);
222+
}
223+
```
224+
<sup><a href='/src/Tests/Samples.cs#L54-L77' title='Snippet source file'>snippet source</a> | <a href='#snippet-GuidsAndDates' title='Start of snippet'>anchor</a></sup>
225+
<!-- endSnippet -->
226+
227+
Results in:
228+
229+
<!-- snippet: Samples.GuidsAndDatesSample.verified.txt -->
230+
<a id='snippet-Samples.GuidsAndDatesSample.verified.txt'></a>
231+
```txt
232+
{
233+
node: {
234+
date: Date_1,
235+
short: foo,
236+
error: {
237+
guid: Guid_1,
238+
msg: No action taken
239+
}
240+
}
241+
}
242+
```
243+
<sup><a href='/src/Tests/Samples.GuidsAndDatesSample.verified.txt#L1-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-Samples.GuidsAndDatesSample.verified.txt' title='Start of snippet'>anchor</a></sup>
244+
<!-- endSnippet -->
245+
246+
247+
### Inline dates and Guids
248+
249+
Inline dates and Guids can be scrubbed:
250+
251+
<!-- snippet: InlineGuidsAndDates -->
252+
<a id='snippet-InlineGuidsAndDates'></a>
253+
```cs
254+
[Test]
255+
public Task InlineGuidsAndDatesSample()
256+
{
257+
var json =
258+
"""
259+
{
260+
"node": {
261+
"date": "01/10/2023",
262+
"short": "foo 01/10/2023",
263+
"error": {
264+
"guid": "123e4567-e89b-12d3-a456-426614174000",
265+
"msg": "No action taken 123e4567-e89b-12d3-a456-426614174000"
266+
}
267+
}
268+
}
269+
""";
270+
271+
var document = JsonDocument.Parse(json);
272+
return Verify(document)
273+
.ScrubInlineDates("dd/MM/yyyy")
274+
.ScrubInlineGuids();
275+
}
276+
```
277+
<sup><a href='/src/Tests/Samples.cs#L78-L103' title='Snippet source file'>snippet source</a> | <a href='#snippet-InlineGuidsAndDates' title='Start of snippet'>anchor</a></sup>
278+
<!-- endSnippet -->
279+
280+
Results in:
281+
282+
<!-- snippet: Samples.InlineGuidsAndDatesSample.verified.txt -->
283+
<a id='snippet-Samples.InlineGuidsAndDatesSample.verified.txt'></a>
284+
```txt
285+
{
286+
node: {
287+
date: Date_1,
288+
short: foo Date_1,
289+
error: {
290+
guid: Guid_1,
291+
msg: No action taken Guid_1
292+
}
293+
}
294+
}
295+
```
296+
<sup><a href='/src/Tests/Samples.InlineGuidsAndDatesSample.verified.txt#L1-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-Samples.InlineGuidsAndDatesSample.verified.txt' title='Start of snippet'>anchor</a></sup>
297+
<!-- endSnippet -->
298+
299+
Inline date and Guids scrubbing can also be defined globally:
300+
301+
* [VerifierSettings.ScrubInlineDateTimes](https://github.com/VerifyTests/Verify/blob/main/docs/dates.md#globally-2)
302+
* [VerifierSettings.ScrubInlineGuids](https://github.com/VerifyTests/Verify/blob/main/docs/guids.md#globally-1)
303+
304+
30305
## Icon
31306

32307
[Pattern](https://thenounproject.com/term/pattern/1070611/) designed by [Trevor Dsouza](https://thenounproject.com/TDsouza/) from [The Noun Project](https://thenounproject.com/).

src/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ dotnet_style_coalesce_expression = false:error
272272
dotnet_style_null_propagation = true:error
273273
dotnet_style_explicit_tuple_names = true:error
274274

275+
# Use collection expression syntax
276+
resharper_use_collection_expression_highlighting = error
277+
275278
# Prefer "var" everywhere
276279
csharp_style_var_for_built_in_types = true:error
277280
csharp_style_var_when_type_is_apparent = true:error

src/Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<PackageVersion Include="System.Text.Json" Version="9.0.5" />
1212
<PackageVersion Include="Verify" Version="30.1.0" />
1313
<PackageVersion Include="Verify.DiffPlex" Version="3.1.2" />
14-
<PackageVersion Include="Verify.XunitV3" Version="30.1.0" />
15-
<PackageVersion Include="xunit.v3" Version="2.0.2" />
16-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0" />
14+
<PackageVersion Include="NUnit" Version="4.3.2" />
15+
<PackageVersion Include="Verify.NUnit" Version="30.1.0" />
16+
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
1717
<PackageVersion Include="Microsoft.Sbom.Targets" Version="4.0.3" />
1818
</ItemGroup>
1919
</Project>

src/Tests/GlobalUsings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
global using System.Text.Json;
2-
global using System.Text.Json.Nodes;
2+
global using System.Text.Json.Nodes;
3+
global using Argon;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
node: {
3+
date: Date_1,
4+
short: foo,
5+
error: {
6+
guid: Guid_1,
7+
msg: No action taken
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
node: {
3+
date: Date_1,
4+
short: foo Date_1,
5+
error: {
6+
guid: Guid_1,
7+
msg: No action taken Guid_1
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
short: {
3+
original: http://www.foo.com/,
4+
short: foo,
5+
error: {
6+
code: 0,
7+
msg: No action taken
8+
}
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
node: {
3+
original: http://www.foo.com/,
4+
short: Scrubbed,
5+
error: {
6+
code: 0
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)