Beispiel #1
0
        public async Task HealthControllerHealthReturnsServiceUnavailableWhenException()
        {
            // Arrange
            var controller = BuildHealthController(MediaTypeNames.Application.Json);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.PingAsync()).Throws <Exception>();

            // Act
            var result = await controller.Health().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.PingAsync()).MustHaveHappenedOnceExactly();

            var statusResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.ServiceUnavailable, statusResult.StatusCode);

            controller.Dispose();
        }
Beispiel #2
0
        public async Task HealthControllerHealthReturnsSuccessWhenhealthy()
        {
            // Arrange
            var controller = BuildHealthController(MediaTypeNames.Application.Json);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.PingAsync()).Returns(true);

            // Act
            var result = await controller.Health().ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.PingAsync()).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsAssignableFrom <HealthViewModel>(jsonResult.Value);

            Assert.True(model.HealthItems.Count > 0);
            Assert.True(!string.IsNullOrWhiteSpace(model.HealthItems.First().Service));
            Assert.True(!string.IsNullOrWhiteSpace(model.HealthItems.First().Message));

            controller.Dispose();
        }