コード例 #1
0
        public async Task Delete_throws_ServiceException_when_server_status_code_is_BAD_REQUEST_Async()
        {
            var handler = new Mock<HttpMessageHandler>();

            handler.Protected()
                .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
                .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent("some known error occurred and was handled", Encoding.UTF8, "application/json")
                }));

            var proxy = new HttpServiceProxyStub(new HttpClient(handler.Object));

            await proxy.DeleteAsync(1);
            proxy.OnFormatServerErrorWasInvoked.ShouldBe(true);
        }
コード例 #2
0
        public async Task Delete_invokes_expected_virtual_methods_async()
        {
            var handler = new Mock<HttpMessageHandler>();

            handler.Protected()
                .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
                .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)));

            var proxy = new HttpServiceProxyStub(new HttpClient(handler.Object));
            await proxy.DeleteAsync(1);

            proxy.BuildConfiguredClientWasInvoked.ShouldBe(true);
        }
コード例 #3
0
        public async Task Delete_throws_DomainObjectNotFoundException_when_server_status_code_is_NOT_FOUND_Async()
        {
            var handler = new Mock<HttpMessageHandler>();

            handler.Protected()
                .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
                .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent("the item was not found", Encoding.UTF8, "application/json")
                }));

            var proxy = new HttpServiceProxyStub(new HttpClient(handler.Object));

            await proxy.DeleteAsync(1);
            proxy.OnFormatServerErrorWasInvoked.ShouldBe(true);
        }
コード例 #4
0
        public async Task Delete_invokes_an_HTTP_DELETE_against_the_correct_uri_async()
        {
            var handler = new Mock<HttpMessageHandler>();

            handler.Protected()
                .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
                .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)))
                .Callback<HttpRequestMessage, CancellationToken>((r, c) =>
                {
                    r.RequestUri.AbsoluteUri.ShouldBe("http://api/customers/1");
                    Assert.AreEqual(HttpMethod.Delete, r.Method);
                });

            var proxy = new HttpServiceProxyStub(new HttpClient(handler.Object));
            await proxy.DeleteAsync(1);
        }