Skip to content

Exception assertions and 'And' #1946

Discussion options

You must be logged in to vote

Because using Wait and Result in async code is widely discouraged, in v6 we have been very careful to remove any blocking code. You can do a couple of things to workaround this:

await sut.Awaiting(x => x.Handle(command, CancellationToken.None))
    .Should()
    .ThrowAsync<RequestFailureException>()
    .Where(e => e.Error.Code == StandardErrorCodes.ResourceNotFound.Code);

or

(await sut.Awaiting(x => x.Handle(command, CancellationToken.None))
    .Should()
    .ThrowAsync<RequestFailureException>())
    .And.Error.Code.Should()
    .Be(StandardErrorCodes.ResourceNotFound.Code);

PS: Awaiting returns a Task, so you must using await as well.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JesseNicholsonStorable
Comment options

Answer selected by JesseNicholsonStorable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants