Members that throw exceptions can be excluded from serialization based on the exception type or properties.
By default members that throw NotImplementedException
or NotSupportedException
are ignored.
Note that this is global for all members on all types.
Ignore by exception type:
[Fact]
public Task CustomExceptionProp()
{
var target = new WithCustomException();
var settings = new VerifySettings();
settings.IgnoreMembersThatThrow<CustomException>();
return Verify(target, settings);
}
[Fact]
public Task CustomExceptionPropFluent()
{
var target = new WithCustomException();
return Verify(target)
.IgnoreMembersThatThrow<CustomException>();
}
Or globally:
VerifierSettings.IgnoreMembersThatThrow<CustomException>();
Result:
{}
Ignore by exception type and expression:
[Fact]
public Task ExceptionMessageProp()
{
var target = new WithExceptionIgnoreMessage();
var settings = new VerifySettings();
settings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
return Verify(target, settings);
}
[Fact]
public Task ExceptionMessagePropFluent()
{
var target = new WithExceptionIgnoreMessage();
return Verify(target)
.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
}
Or globally:
VerifierSettings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");
Result:
{}