public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName) { // Arrange var controller = BuildSegmentController(mediaTypeName); var dbModels = GetSegmentModels(); A.CallTo(() => FakeHowToBecomeSegmentService.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(); }
public async Task ReturnsNoContentWhenNoData(string mediaTypeName) { // Arrange List <HowToBecomeSegmentModel> expectedResult = null; var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeHowToBecomeSegmentService.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 PagesControllerIndexHtmlReturnsSuccessWhenNoData(string mediaTypeName) { // Arrange var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeHowToBecomeSegmentService.GetAllAsync()).Returns((IEnumerable <HowToBecomeSegmentModel>)null); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <HowToBecomeSegmentModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>()); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeHowToBecomeSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <HowToBecomeSegmentModel> .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 SegmentControllerIndexHtmlReturnsSuccess(string mediaTypeName) { // Arrange const int resultsCount = 2; var expectedResults = A.CollectionOfFake <HowToBecomeSegmentModel>(resultsCount); var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeHowToBecomeSegmentService.GetAllAsync()).Returns(expectedResults); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <HowToBecomeSegmentModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>()); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeHowToBecomeSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <HowToBecomeSegmentModel> .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(); }