public async Task Given_request_has_non_matching_method_when_sending_with_negated_setup_it_should_match_mock(string notMethod, string sendMethod)
        {
            _mockHttp
            .When(m => m.Not.Method(notMethod))
            .Respond(HttpStatusCode.OK)
            .Verifiable();

            // Act
            HttpResponseMessage response = await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod(sendMethod), ""));

            // Assert
            response.Should().HaveStatusCode(HttpStatusCode.OK);
            _mockHttp.Verify();
            _mockHttp.VerifyNoOtherRequests();
        }
示例#2
0
        public void Given_request_is_configured_to_throw_when_sending_request_should_throw_exception()
        {
            _sut.When(matching => { })
            .Throws <TestableException>()
            .Verifiable();

            // Act
            Func <Task <HttpResponseMessage> > act = () => _httpClient.GetAsync("");

            // Assert
            act.Should().ThrowExactly <TestableException>();
            _sut.Verify(m => { }, IsSent.Once);
            _sut.VerifyNoOtherRequests();
        }