public async Task Then_the_response_is_returned(
            int id,
            TestCustomerEngagementApiConfiguration config,
            TestResponse expectedResponse)
        {
            //Arrange
            config.Url = "https://test.local";
            var httpResponse = new HttpResponseMessage
            {
                Content    = new StringContent(JsonConvert.SerializeObject(expectedResponse), Encoding.UTF8, "application/json"),
                StatusCode = HttpStatusCode.OK
            };
            var getTestRequest = new GetTestRequest(config.Url, id)
            {
                BaseUrl = config.Url
            };
            var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(httpResponse, getTestRequest.GetUrl);
            var client             = new HttpClient(httpMessageHandler.Object);
            var hostingEnvironment = new Mock <IWebHostEnvironment>();
            var clientFactory      = new Mock <IHttpClientFactory>();

            clientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            hostingEnvironment.Setup(x => x.EnvironmentName).Returns("Staging");
            var actual = new CustomerEngagementApiClient <TestCustomerEngagementApiConfiguration>(clientFactory.Object, config, hostingEnvironment.Object);

            //Act
            var response = await actual.Get <TestResponse>(getTestRequest);

            //Assert
            response.Should().BeEquivalentTo(expectedResponse);
        }
        public async Task Then_an_unsuccessful_response_returns_null(int id,
                                                                     TestCustomerEngagementApiConfiguration config)
        {
            //Arrange
            config.Url = "https://test.local";
            var httpResponse = new HttpResponseMessage
            {
                Content    = new StringContent(""),
                StatusCode = HttpStatusCode.NotFound
            };
            var getTestRequest = new GetTestRequest(config.Url, id)
            {
                BaseUrl = config.Url
            };
            var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(httpResponse, getTestRequest.GetUrl);
            var client             = new HttpClient(httpMessageHandler.Object);
            var hostingEnvironment = new Mock <IWebHostEnvironment>();
            var clientFactory      = new Mock <IHttpClientFactory>();

            clientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            hostingEnvironment.Setup(x => x.EnvironmentName).Returns("Staging");
            var actual = new CustomerEngagementApiClient <TestCustomerEngagementApiConfiguration>(clientFactory.Object, config, hostingEnvironment.Object);

            //Act
            var response = await actual.Get <TestResponse>(getTestRequest);

            //Assert
            response.Should().BeNull();
        }
        public async Task Then_The_Endpoint_Is_Called(
            int id,
            TestCustomerEngagementApiConfiguration config)
        {
            //Arrange
            config.Url = "https://test.local";
            var response = new HttpResponseMessage
            {
                Content    = new StringContent(""),
                StatusCode = HttpStatusCode.Accepted
            };
            var getTestRequest = new GetTestRequest(config.Url, id)
            {
                BaseUrl = config.Url
            };
            var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(response, getTestRequest.GetUrl);
            var client             = new HttpClient(httpMessageHandler.Object);
            var hostingEnvironment = new Mock <IWebHostEnvironment>();
            var clientFactory      = new Mock <IHttpClientFactory>();

            clientFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            hostingEnvironment.Setup(x => x.EnvironmentName).Returns("Staging");
            var actual = new CustomerEngagementApiClient <TestCustomerEngagementApiConfiguration>(clientFactory.Object, config, hostingEnvironment.Object);

            //Act
            await actual.Get <string>(getTestRequest);

            //Assert
            httpMessageHandler.Protected()
            .Verify <Task <HttpResponseMessage> >(
                "SendAsync", Times.Once(),
                ItExpr.Is <HttpRequestMessage>(c =>
                                               c.Method.Equals(HttpMethod.Get) &&
                                               c.RequestUri.AbsoluteUri.Equals(getTestRequest.GetUrl) &&
                                               c.Headers.FirstOrDefault(h => h.Key.Equals("Ocp-Apim-Subscription-Key")).Value.FirstOrDefault() == config.SubscriptionKey),
                ItExpr.IsAny <CancellationToken>()
                );
        }