public async Task ReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            const int resultsCount = 0;
            IEnumerable <JobProfileTasksSegmentModel> expectedResults = null;
            var controller             = BuildSegmentController(mediaTypeName);
            var indexDocumentViewModel = new IndexDocumentViewModel {
                CanonicalName = "job-profile-1"
            };

            A.CallTo(() => FakeJobProfileSegmentService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(indexDocumentViewModel);

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

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

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

            Assert.Null(model.Documents);

            controller.Dispose();
        }
Exemple #2
0
        public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName)
        {
            // Arrange
            var controller = BuildSegmentController(mediaTypeName);
            var dbModels   = GetSegmentModels();

            A.CallTo(() => FakeJobProfileSegmentService.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();
        }
Exemple #3
0
        public async Task ReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            List <JobProfileTasksSegmentModel> expectedResult = null;
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeJobProfileSegmentService.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();
        }