public void WHEN_post_returns_401_not_authorized_SHOULD_throw_UnauthorizedAccessException()
            {
                //Arrange
                MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler
                                                                                .Where_SendAsync_returns_StatusCode(HttpStatusCode.Unauthorized)
                                                                                .Where_SendAsync_returns_ReasonPhrase("Bad luck")
                                                                                .Build().Object));

                //Assert
                Assert.ThrowsAsync <HttpClientServiceAuthorizationException>(async() =>
                                                                             await Sut.PostAsync("http://baseaddress.com/testroute", new TestDto {
                    TestDtoProperty = "hello world"
                }, CancellationToken.None));
            }
            public void WHEN_post_fails_without_error_message_SHOULD_throw()
            {
                //Arrange
                MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler
                                                                                .Where_SendAsync_returns_StatusCode(HttpStatusCode.FailedDependency)
                                                                                .Where_SendAsync_returns_ReasonPhrase("Bad luck")
                                                                                .Build().Object));

                //Assert
                Assert.ThrowsAsync <HttpClientServiceException>(async() =>
                                                                await Sut.PostAsync("http://baseaddress.com/testroute", new TestDto {
                    TestDtoProperty = "hello world"
                }, CancellationToken.None));
            }
        public void WHEN_post_returns_401_not_authorized_SHOULD_throw_UnauthorizedAccessException()
        {
            //Arrange
            var wrapper = GetWrapper();

            MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler
                                                                            .Where_SendAsync_returns_StatusCode(HttpStatusCode.Unauthorized)
                                                                            .Where_SendAsync_returns_ReasonPhrase("Bad luck")
                                                                            .Build().Object));

            //Assert
            Assert.ThrowsAsync <HttpClientServiceAuthorizationException>(async() =>
                                                                         await ExecuteAsync(wrapper, CancellationToken.None));
        }
        public void WHEN_post_fails_without_error_message_SHOULD_throw()
        {
            //Arrange
            var wrapper = GetWrapper();

            MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler
                                                                            .Where_SendAsync_returns_StatusCode(HttpStatusCode.FailedDependency)
                                                                            .Where_SendAsync_returns_ReasonPhrase("Bad luck")
                                                                            .Build().Object));

            //Assert
            Assert.ThrowsAsync <HttpClientServiceException>(async() =>
                                                            await ExecuteAsync(wrapper, CancellationToken.None));
        }
            public void WHEN_post_fails_with_error_message_SHOULD_throw_message()
            {
                //Arrange
                MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler
                                                                                .Where_SendAsync_returns_StatusCode(HttpStatusCode.BadRequest)
                                                                                .Where_SendAsync_returns_Content(JsonConvert.SerializeObject(new HttpError
                {
                    Message = "bad luck"
                }))
                                                                                .Build().Object));

                //Assert
                Assert.ThrowsAsync <HttpClientServiceServerError>(async() =>
                                                                  await Sut.PostAsync("http://baseaddress.com/testroute", new TestDto {
                    TestDtoProperty = "hello world"
                }, CancellationToken.None), "bad luck");
            }
        public void WHEN_post_fails_with_error_message_SHOULD_throw()
        {
            //Arrange
            var wrapper = GetWrapper();

            MockHttpClientFactory.Where_CreateClient_returns(new HttpClient(MockMessageHandler
                                                                            .Where_SendAsync_returns_StatusCode(HttpStatusCode.BadRequest)
                                                                            .Where_SendAsync_returns_Content(JsonConvert.SerializeObject(new HttpError
            {
                Message = "bad luck"
            }))
                                                                            .Build().Object));

            //Assert
            Assert.ThrowsAsync <HttpClientServiceServerError>(async() =>
                                                              await ExecuteAsync(wrapper, CancellationToken.None), "bad luck");
        }