public void PingReturnsFalseWhenNotInRepository()
        {
            // arrange
            var repository     = A.Dummy <ICosmosRepository <JobProfileOverviewSegmentModel> >();
            var expectedResult = false;

            A.CallTo(() => repository.PingAsync()).Returns(expectedResult);

            var overviewSegmentService = new JobProfileOverviewSegmentService(repository, mapper, jobProfileSegmentRefreshService);

            // act
            var result = overviewSegmentService.PingAsync().Result;

            // assert
            A.CallTo(() => repository.PingAsync()).MustHaveHappenedOnceExactly();
            Assert.Equal(expectedResult, result);
        }
Exemple #2
0
        public async Task ReturnsServiceUnavailableWhenException()
        {
            // Arrange
            var controller = BuildHealthController(MediaTypeNames.Application.Json);

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

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

            // Assert
            A.CallTo(() => JobProfileOverviewSegmentService.PingAsync()).MustHaveHappenedOnceExactly();
            var statusResult = Assert.IsType <StatusCodeResult>(result);

            statusResult.StatusCode.Should().Be((int)HttpStatusCode.ServiceUnavailable);

            controller.Dispose();
        }
Exemple #3
0
        public async Task ReturnsSuccessWhenhealthy()
        {
            // Arrange
            const bool expectedResult = true;
            var        controller     = BuildHealthController(MediaTypeNames.Application.Json);

            A.CallTo(() => JobProfileOverviewSegmentService.PingAsync()).Returns(expectedResult);

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

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

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

            jsonResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            model.HealthItems.Count.Should().BeGreaterThan(0);
            model.HealthItems.First().Service.Should().NotBeNullOrWhiteSpace();
            model.HealthItems.First().Message.Should().NotBeNullOrWhiteSpace();

            controller.Dispose();
        }