public async Task HealthControllerHealthReturnsServiceUnavailableWhenException() { // Arrange var controller = BuildHealthController(MediaTypeNames.Application.Json); A.CallTo(() => FakeRelatedCareersSegmentService.PingAsync()).Throws <Exception>(); // Act var result = await controller.Health().ConfigureAwait(false); // Assert A.CallTo(() => FakeRelatedCareersSegmentService.PingAsync()).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)HttpStatusCode.ServiceUnavailable, statusResult.StatusCode); controller.Dispose(); }
public async Task HealthControllerHealthReturnsSuccessWhenhealthy() { // Arrange var controller = BuildHealthController(MediaTypeNames.Application.Json); A.CallTo(() => FakeRelatedCareersSegmentService.PingAsync()).Returns(true); // Act var result = await controller.Health().ConfigureAwait(false); // Assert A.CallTo(() => FakeRelatedCareersSegmentService.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(); }