Exemplo n.º 1
0
        public void SendAsync_ValidRequest_VerifyHandler()
        {
            var param_request = new HttpRequestMessageFactory().StubHttpRequestMessage().Create();
            var stub_response = new HttpResponseMessageFactory().StubHttpResponseMessage().Create();
            var stub_task     = Task.FromResult(stub_response);
            var mockHandler   = new Mock <IFakeHttpMessageHandler>();

            mockHandler.Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .Returns(stub_task);
            var webApiDataAccess = new WebApiDataAccess(new FakeHttpMessageHandler(mockHandler.Object));

            webApiDataAccess.SendRequest(param_request);

            mockHandler.Verify(x => x.SendAsync(param_request, It.IsAny <CancellationToken>()));
        }
Exemplo n.º 2
0
        public void SendAsync_ValidRequest_ReturnsExpectedResponse()
        {
            var param_request = new HttpRequestMessageFactory().StubHttpRequestMessage().Create();
            var stub_response = new HttpResponseMessageFactory().StubHttpResponseMessage().Create();
            var stub_task     = Task.FromResult(stub_response);
            var stubHandler   = new Mock <IFakeHttpMessageHandler>();

            stubHandler.Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .Returns(stub_task);
            var webApiDataAccess = new WebApiDataAccess(new FakeHttpMessageHandler(stubHandler.Object));

            var returned = webApiDataAccess.SendRequest(param_request);

            Assert.Equal(returned, stub_response);
        }