Beispiel #1
0
        public async Task SegmentControllerDocumentHtmlReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            const string article = "an-article-name";
            CurrentOpportunitiesSegmentModel expectedResult = null;
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustNotHaveHappened();

            var statusResult = Assert.IsType <NoContentResult>(result);

            Assert.Equal((int)HttpStatusCode.NoContent, statusResult.StatusCode);

            controller.Dispose();
        }
Beispiel #2
0
        public async Task SegmentControllerDocumentHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var expectedResult    = A.Fake <CurrentOpportunitiesSegmentModel>();
            var controller        = BuildSegmentController(mediaTypeName);
            var documentViewModel = GetDocumentViewModel();

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(documentViewModel);

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model);

            controller.Dispose();
        }