Exception assertions and 'And' #1946
-
I am upgrading our FA version from 5.10.3 to 6.7.0 and I am concerned that a number of our current test are using a no-longer used feature. We have many tests that look like sut.Awaiting(x => x.Handle(command, CancellationToken.None))
.Should()
.ThrowAsync<RequestFailureException>()
.And.Error.Code.Should()
.Be(StandardErrorCodes.ResourceNotFound.Code); Originally they were breaking on the throw, which was an easy enough fix, however now they all break on the I have tried searching for a topic like this but a search for why |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Because using 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: |
Beta Was this translation helpful? Give feedback.
Because using
Wait
andResult
inasync
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:or
PS:
Awaiting
returns aTask
, so you must usingawait
as well.