public void SendAsync_attaches_error_payload_to_exception_if_nonSuccessful_response(string method, [Frozen] MockHttpMessageHandler handler, HttpRestClient sut, Uri uri, string errorPayload)
        {
            var httpMethod = new HttpMethod(method);

            handler.When(httpMethod, uri.ToString())
            .Respond(HttpStatusCode.NotFound, "text/plain", errorPayload);

            Assert.That(() => sut.SendAsync(httpMethod, uri.ToString()), Throws.TypeOf <HttpException>().And.Property(nameof(HttpException.Payload)).EqualTo(errorPayload));
        }
        public void SendAsync_throws_HttpException_if_nonSuccessful_response(string method, [Frozen] MockHttpMessageHandler handler, HttpRestClient sut, Uri uri)
        {
            var httpMethod = new HttpMethod(method);

            handler.When(httpMethod, uri.ToString())
            .Respond(HttpStatusCode.NotFound);

            Assert.That(() => sut.SendAsync(httpMethod, uri.ToString()), Throws.TypeOf <HttpException>());
        }
        public void SendAsync_can_send_request_and_receive_response(string method, [Frozen] MockHttpMessageHandler handler, HttpRestClient sut, Uri uri)
        {
            var httpMethod = new HttpMethod(method);

            handler.When(httpMethod, uri.ToString())
            .Respond(HttpStatusCode.OK);

            Assert.That(() => sut.SendAsync(httpMethod, uri.ToString()), Throws.Nothing);
        }
        public void SendAsync_with_Request_and_Response_throws_HttpException_if_nonSuccessful_response(string method, [Frozen] MockHttpMessageHandler handler, HttpRestClient sut, Uri uri, Request request)
        {
            var httpMethod = new HttpMethod(method);

            handler.When(httpMethod, uri.ToString())
            .WithJsonContent(request)
            .Respond(HttpStatusCode.NotFound);

            Assert.That(() => sut.SendAsync <Request, Response>(httpMethod, uri.ToString(), request), Throws.TypeOf <HttpException>());
        }
        public void SendAsync_with_Request_can_send_request_with_body_and_receive_response(string method, [Frozen] MockHttpMessageHandler handler, HttpRestClient sut, Uri uri, Request request)
        {
            var httpMethod = new HttpMethod(method);

            handler.When(httpMethod, uri.ToString())
            .WithJsonContent(request)
            .Respond(HttpStatusCode.OK);

            Assert.That(() => sut.SendAsync <Request>(httpMethod, uri.ToString(), request), Throws.Nothing);
        }
        public async Task SendAsync_with_Response_can_send_request_and_receive_response_with_body(string method, [Frozen] MockHttpMessageHandler handler, HttpRestClient sut, Uri uri, Response response)
        {
            var httpMethod = new HttpMethod(method);

            handler.When(httpMethod, uri.ToString())
            .Respond(HttpStatusCode.OK, JsonContent.FromObject(response));

            var actualResponse = await sut.SendAsync <Response>(httpMethod, uri.ToString());

            Assert.That(actualResponse, Is.EqualTo(response));
        }
        public async Task HttpClientName_is_used_when_specified_in_options(string method, [Frozen] MockHttpMessageHandler handler, [Frozen] IHttpClientFactory httpClientFactory, [Frozen] HttpRestClientOptions options, HttpRestClient sut, Uri uri, string httpClientName)
        {
            var httpMethod = new HttpMethod(method);

            options.HttpClientName = httpClientName;

            handler.When(httpMethod, uri.ToString())
            .Respond(HttpStatusCode.OK);

            await sut.SendAsync(httpMethod, uri.ToString());

            Mock.Get(httpClientFactory).Verify(p => p.CreateClient(httpClientName), Times.AtLeastOnce());
        }