Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 5, 2024
1 parent 4d5b04a commit 66e75a1
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 28 deletions.
14 changes: 7 additions & 7 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,8 @@ public Task IgnoreMemberByPredicate()
};
var settings = new VerifySettings();

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

return Verify(target, settings);
}
Expand All @@ -1157,8 +1157,8 @@ public Task IgnoreMemberByPredicateFluent()
var settings = new VerifySettings();

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

[Fact]
Expand Down Expand Up @@ -1239,8 +1239,8 @@ public Task ScrubMemberByPredicate()
};
var settings = new VerifySettings();

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

return Verify(target, settings);
}
Expand Down Expand Up @@ -1449,7 +1449,7 @@ public static void MemberConverterByExpressionInit()
// using only the member
VerifierSettings.MemberConverter<MemberTarget, string>(
expression: _ => _.Field,
converter: member => $"{member}_Suffix");
converter: _ => $"{_}_Suffix");

// using target and member
VerifierSettings.MemberConverter<MemberTarget, string>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Include": {
"Key1": "Value2"
},
"Key2": "Value4"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Include": "Value",
"GetOnlyProperty": "asd"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Include": "Value",
"GetOnlyProperty": "asd"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Ignore": "{Scrubbed}",
"Include": {
"Ignore": "{Scrubbed}",
"Key1": "Value2"
},
"Key2": "Value4"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Include": "Value",
"Field": "{Scrubbed}",
"Property": "{Scrubbed}",
"PropertyByName": "{Scrubbed}",
"GetOnlyProperty": "asd",
"PropertyThatThrows": "{Scrubbed}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Include": "Value",
"Field": "{Scrubbed}",
"Property": "{Scrubbed}",
"PropertyByName": "{Scrubbed}",
"GetOnlyProperty": "asd",
"PropertyThatThrows": "{Scrubbed}"
}
14 changes: 7 additions & 7 deletions src/Verify.Tests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3274,7 +3274,7 @@ public static void MemberConverterByExpressionInit()
// using only the member
VerifierSettings.MemberConverter<MemberTarget, string>(
expression: _ => _.Field,
converter: member => $"{member}_Suffix");
converter: _ => $"{_}_Suffix");

// using target and member
VerifierSettings.MemberConverter<MemberTarget, string>(
Expand Down Expand Up @@ -3478,8 +3478,8 @@ public Task ScrubMemberByPredicate()
};
var settings = new VerifySettings();

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

return Verify(target, settings);
}
Expand Down Expand Up @@ -3548,8 +3548,8 @@ public Task IgnoreMemberByPredicate()
};
var settings = new VerifySettings();

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

return Verify(target, settings);
}
Expand All @@ -3567,8 +3567,8 @@ public Task IgnoreMemberByPredicateFluent()
var settings = new VerifySettings();

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

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
public void IgnoreMembers(Func<MemberInfo, bool> predicate)
{
Guard.NotNull(predicate);
ignoredMemberPredicatesByMember.Add(member => predicate(member) ? ScrubOrIgnore.Ignore : null);
ignoredMemberPredicatesByMember.Add(_ => predicate(_) ? ScrubOrIgnore.Ignore : null);
}

public void IgnoreMembers(Func<string, bool> predicate)
{
Guard.NotNull(predicate);
ignoredMemberPredicatesByString.Add(member => predicate(member) ? ScrubOrIgnore.Ignore : null);
ignoredMemberPredicatesByString.Add(_ => predicate(_) ? ScrubOrIgnore.Ignore : null);
}

public void ScrubMembers(Func<MemberInfo, bool> predicate)
{
Guard.NotNull(predicate);
ignoredMemberPredicatesByMember.Add(member => predicate(member) ? ScrubOrIgnore.Scrub : null);
ignoredMemberPredicatesByMember.Add(_ => predicate(_) ? ScrubOrIgnore.Scrub : null);
}

public void ScrubMembers(Func<string, bool> predicate)
{
Guard.NotNull(predicate);
ignoredMemberPredicatesByString.Add(member => predicate(member) ? ScrubOrIgnore.Scrub : null);
ignoredMemberPredicatesByString.Add(_ => predicate(_) ? ScrubOrIgnore.Scrub : null);
}

internal bool TryGetScrubOrIgnorePredicateByName(string name, MemberInfo? memberInfo, [NotNullWhen(true)] out ScrubOrIgnore? scrubOrIgnore)
Expand Down
12 changes: 2 additions & 10 deletions src/Verify/Serialization/SerializationSettings_IgnoreInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ public void IgnoreInstance<T>(Func<T, bool> shouldIgnore)
var type = typeof(T);
IgnoreInstance(
type,
target =>
{
var arg = (T) target;
return shouldIgnore(arg);
});
_ => shouldIgnore((T) _));
}

public void IgnoreInstance(Type type, ShouldIgnore shouldIgnore)
Expand All @@ -39,11 +35,7 @@ public void ScrubInstance<T>(Func<T, bool> shouldScrub)
var type = typeof(T);
ScrubInstance(
type,
target =>
{
var arg = (T) target;
return shouldScrub(arg);
});
_ => shouldScrub((T) _));
}

public void ScrubInstance(Type type, ShouldScrub shouldScrub)
Expand Down

0 comments on commit 66e75a1

Please sign in to comment.