-
Notifications
You must be signed in to change notification settings - Fork 5
Verifying requests
skwasjer edited this page Mar 2, 2020
·
8 revisions
Similar to Moq, each setup can be configured as Verifiable()
, turning it into an expectation that can be verified later on using Verify()
.
mockHttp
.When(...)
.Respond(...)
.Verifiable();
mockHttp.Verify();
When the expectation is not met a HttpMockException
is thrown when calling Verify()
which provides details on which expectations were not met.
Verify methods | Description |
---|---|
Verify() |
Verifies that all verifiable expected requests have been sent. |
VerifyAll() |
Verifies all expected requests regardless of whether they have been flagged as verifiable. |
VerifyNoOtherRequests() |
Verifies that there were no requests sent other than those already verified. |
When a response sequence is configured and verified at least the same amount of requests must have been sent and matched by the expectation.
You also have the option, similar to Moq, to verify without having configured a verifiable request expectation. For example, to verify a specific URL has been requested using GET
twice:
await mockHttp.VerifyAsync(matching =>
matching
.Method("GET")
.RequestUri("http://localhost/controller/*"),
IsSent.Exactly(2)
);