Beispiel #1
0
        public async Task GetAsyncReturnsNullIfModelIsNull()
        {
            // Arrange
            var healthService = new ApplicationHealthService(defaultHttpClient, logger);

            // Act
            var result = await healthService.GetAsync(null);

            // Assert
            Assert.Null(result);
        }
Beispiel #2
0
        public async Task GetAsyncReturnsHealthTextWhenApiReturnsHealthText()
        {
            // Arrange
            var expectedResponse = new List <HealthItemModel>
            {
                new HealthItemModel
                {
                    Service = "A service 1",
                    Message = "A message 1",
                },
                new HealthItemModel
                {
                    Service = "A service 2",
                    Message = "A message 2",
                },
            };
            string expectedResponseString = JsonConvert.SerializeObject(expectedResponse);
            var    httpResponse           = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(expectedResponseString),
            };

            var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>();

            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);

            var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);
            var httpClient             = new HttpClient(fakeHttpMessageHandler)
            {
                BaseAddress = new Uri("http://SomeDummyUrl")
            };

            var healthService = new ApplicationHealthService(httpClient, logger);
            var model         = new ApplicationHealthModel {
                BearerToken = "SomeBearerToken"
            };

            // Act
            var result = await healthService.GetAsync(model);

            // Assert
            string resultString = JsonConvert.SerializeObject(result);

            Assert.Equal(expectedResponseString, resultString);

            httpResponse.Dispose();
            httpClient.Dispose();
            fakeHttpMessageHandler.Dispose();
        }