Skip to content

Latest commit

 

History

History
106 lines (86 loc) · 3.87 KB

members-throw.md

File metadata and controls

106 lines (86 loc) · 3.87 KB

Members that throw

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>();
}

snippet source | anchor

Or globally:

VerifierSettings.IgnoreMembersThatThrow<CustomException>();

snippet source | anchor

Result:

{}

snippet source | anchor

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");
}

snippet source | anchor

Or globally:

VerifierSettings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore");

snippet source | anchor

Result:

{}

snippet source | anchor