Ejemplo n.º 1
0
        public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName)
        {
            // Arrange
            var controller = BuildSegmentController(mediaTypeName);
            var dbModels   = GetSegmentModels();

            A.CallTo(() => FakeJobProfileOverviewSegmentService.GetAllAsync()).Returns(dbModels);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentRefreshService.SendMessageListAsync(A <List <RefreshJobProfileSegmentServiceBusModel> > .Ignored)).MustHaveHappenedOnceExactly();
            var res = Assert.IsType <JsonResult>(result);

            Assert.Equal(dbModels.Count, (res.Value as List <RefreshJobProfileSegmentServiceBusModel>).Count);

            controller.Dispose();
        }
Ejemplo n.º 2
0
        public async Task ReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            List <JobProfileOverviewSegmentModel> expectedResult = null;
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeJobProfileOverviewSegmentService.GetAllAsync()).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentRefreshService.SendMessageListAsync(A <List <RefreshJobProfileSegmentServiceBusModel> > .Ignored)).MustNotHaveHappened();
            var statusResult = Assert.IsType <NoContentResult>(result);

            A.CallTo(() => FakeLogger.LogWarning(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal((int)HttpStatusCode.NoContent, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task ReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            IEnumerable <JobProfileOverviewSegmentModel> expectedResults = null;
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeJobProfileOverviewSegmentService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileOverviewSegmentModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobProfileOverviewSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileOverviewSegmentModel> .Ignored)).MustNotHaveHappened();

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model);

            Assert.Null(model.Documents);

            controller.Dispose();
        }
        public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName)
        {
            // Arrange
            const int resultsCount    = 2;
            var       expectedResults = A.CollectionOfFake <JobProfileOverviewSegmentModel>(resultsCount);
            var       controller      = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeJobProfileOverviewSegmentService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileOverviewSegmentModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>());

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

            // Assert
            A.CallTo(() => FakeJobProfileOverviewSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileOverviewSegmentModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model);

            Assert.Equal(resultsCount, model.Documents.Count());

            controller.Dispose();
        }