Skip to content

Commit

Permalink
Docs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 5, 2024
1 parent d5e9f09 commit 4d5b04a
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/members-throw.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Task CustomExceptionPropFluent()
.IgnoreMembersThatThrow<CustomException>();
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3694-L3713' 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#L3710-L3729' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrow' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -45,7 +45,7 @@ Or globally:
```cs
VerifierSettings.IgnoreMembersThatThrow<CustomException>();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3688-L3692' 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#L3704-L3708' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down
6 changes: 3 additions & 3 deletions docs/obsolete-members.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Task WithObsoleteProp()
return Verify(target);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3841-L3862' 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#L3857-L3878' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoleteProp' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -79,7 +79,7 @@ public Task WithObsoletePropIncludedFluent()
.IncludeObsoletes();
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3812-L3839' 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#L3828-L3855' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoletePropIncluded' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand All @@ -89,7 +89,7 @@ Or globally:
```cs
VerifierSettings.IncludeObsoletes();
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3806-L3810' 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#L3822-L3826' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithObsoletePropIncludedGlobally' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down
212 changes: 209 additions & 3 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public Task ScopedSerializerFluent()
.AddExtraSettings(_ => _.TypeNameHandling = TypeNameHandling.All);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3876-L3903' 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#L3892-L3919' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScopedSerializer' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:
Expand Down Expand Up @@ -983,7 +983,7 @@ public Task IgnoreMemberByNameFluent()
.IgnoreMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3341-L3394' 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#L3357-L3410' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByName' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand Down Expand Up @@ -1078,7 +1078,7 @@ public Task ScrubMemberByNameFluent()
.ScrubMember<IgnoreExplicitTarget>(_ => _.PropertyThatThrows);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3396-L3449' 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#L3412-L3465' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByName' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:
Expand Down Expand Up @@ -1119,6 +1119,212 @@ Result:
<!-- endSnippet -->


## Ignore member by predicate

To ignore members of a certain type using a predicate function:

<!-- snippet: IgnoreMemberByPredicate -->
<a id='snippet-IgnoreMemberByPredicate'></a>
```cs
[Fact]
public Task IgnoreMemberByPredicate()
{
var target = new IgnoreExplicitTarget
{
Include = "Value",
Field = "Value",
Property = "Value",
PropertyByName = "Value"
};
var settings = new VerifySettings();

settings.IgnoreMembers(name => name is "Field" or "Property");
settings.IgnoreMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows");

return Verify(target, settings);
}

[Fact]
public Task IgnoreMemberByPredicateFluent()
{
var target = new IgnoreExplicitTarget
{
Include = "Value",
Field = "Value",
Property = "Value",
PropertyByName = "Value"
};
var settings = new VerifySettings();

return Verify(target, settings)
.IgnoreMembers(name => name is "Field" or "Property")
.IgnoreMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows");
}

[Fact]
public Task IgnoreDictionaryByPredicate()
{
var settings = new VerifySettings();

settings.IgnoreMembers(name => name is "Ignore");

var target = new Dictionary<string, object>
{
{
"Include", new Dictionary<string, string>
{
{
"Ignore", "Value1"
},
{
"Key1", "Value2"
}
}
},
{
"Ignore", "Value3"
},
{
"Key2", "Value4"
}
};
return Verify(target, settings);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3537-L3603' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByPredicate' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:

<!-- snippet: IgnoreMemberByPredicateGlobal -->
<a id='snippet-IgnoreMemberByPredicateGlobal'></a>
```cs
VerifierSettings.IgnoreMembers(
_=>_.DeclaringType == typeof(TargetClass) &&
_.Name == "Proprty");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3347-L3353' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMemberByPredicateGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:

<!-- snippet: SerializationTests.IgnoreMemberByPredicate.verified.txt -->
<a id='snippet-SerializationTests.IgnoreMemberByPredicate.verified.txt'></a>
```txt
{
Include: Value,
GetOnlyProperty: asd
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.IgnoreMemberByPredicate.verified.txt#L1-L4' title='Snippet source file'>snippet source</a> | <a href='#snippet-SerializationTests.IgnoreMemberByPredicate.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## Scrub member by predicate

To scrub members of a certain type using a predicate function:

<!-- snippet: ScrubMemberByPredicate -->
<a id='snippet-ScrubMemberByPredicate'></a>
```cs
[Fact]
public Task ScrubMemberByPredicate()
{
var target = new IgnoreExplicitTarget
{
Include = "Value",
Field = "Value",
Property = "Value",
PropertyByName = "Value"
};
var settings = new VerifySettings();

settings.ScrubMembers(name => name is "Field" or "Property");
settings.ScrubMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows");

return Verify(target, settings);
}

[Fact]
public Task ScrubMemberByPredicateFluent()
{
var target = new IgnoreExplicitTarget
{
Include = "Value",
Field = "Value",
Property = "Value",
PropertyByName = "Value"
};
var settings = new VerifySettings();

return Verify(target, settings)
.ScrubMembers(name => name is "Field" or "Property")
.ScrubMembers(member => member.Name is "PropertyByName" or "PropertyThatThrows");
}

[Fact]
public Task ScrubDictionaryByPredicate()
{
var settings = new VerifySettings();

settings.ScrubMembers(name => name is "Ignore");

var target = new Dictionary<string, object>
{
{
"Include", new Dictionary<string, string>
{
{
"Ignore", "Value1"
},
{
"Key1", "Value2"
}
}
},
{
"Ignore", "Value3"
},
{
"Key2", "Value4"
}
};
return Verify(target, settings);
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3467-L3535' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByPredicate' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Or globally:

<!-- snippet: ScrubMemberByPredicateGlobal -->
<a id='snippet-ScrubMemberByPredicateGlobal'></a>
```cs
VerifierSettings.ScrubMembers(
_=>_.DeclaringType == typeof(TargetClass) &&
_.Name == "Proprty");
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3340-L3346' title='Snippet source file'>snippet source</a> | <a href='#snippet-ScrubMemberByPredicateGlobal' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:

<!-- snippet: SerializationTests.ScrubMemberByPredicate.verified.txt -->
<a id='snippet-SerializationTests.ScrubMemberByPredicate.verified.txt'></a>
```txt
{
Include: Value,
Field: {Scrubbed},
Property: {Scrubbed},
PropertyByName: {Scrubbed},
GetOnlyProperty: asd,
PropertyThatThrows: {Scrubbed}
}
```
<sup><a href='/src/Verify.Tests/Serialization/SerializationTests.ScrubMemberByPredicate.verified.txt#L1-L8' title='Snippet source file'>snippet source</a> | <a href='#snippet-SerializationTests.ScrubMemberByPredicate.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


## TreatAsString

Certain types, when passed directly in to Verify, are written directly without going through json serialization.
Expand Down

0 comments on commit 4d5b04a

Please sign in to comment.