Skip to content

[API Proposal]: Allow WithoutMessage when using Should().Throw() and ThrowAsync() #3093

@dennisdoomen

Description

@dennisdoomen

Background and motivation

Sometimes you want to ensure a particular exception is thrown, but where the message does not contain a particular wildcard phrase.

API Proposal

Affects ExceptionAssertions and ExceptionAssertionsExtensions

API Usage

Instead of

act.Should().Throw<XunitException>().WithMessage("*existingProperty*wrongvalue*")
            .Which.Message.Should().NotContain("missingProperty");

it would allow

act.Should().Throw<XunitException>()
      .WithMessage("*existingProperty*wrongvalue*")
      .WithoutMessage("*missingProperty*");

Alternative Designs

No response

Risks

No response

Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?

No

Metadata

Metadata

Assignees

Labels

api-suggestionEarly API idea and discussion, it is NOT ready for implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions