コード例 #1
0
        public void Constructor_SutIsController(Mock<IQueryService<Post>> postQueryService)
        {
            // When
            var sut = new PostController(postQueryService.Object);

            // Then
            Assert.IsAssignableFrom<Controller>(sut);
        }
コード例 #2
0
        public void Index_ReturnsViewWithPostsSequenceInViewBag(Mock<IQueryService<Post>> postQueryService)
        {
            // Given
            var sut = new PostController(postQueryService.Object);

            // When
            var result = sut.Index();

            // Then
            Assert.IsAssignableFrom<IEnumerable<Post>>(result.ViewData.Model);
        }
コード例 #3
0
        public void Index_ReturnsView(Mock<IQueryService<Post>> postQueryService)
        {
            // Given
            var sut = new PostController(postQueryService.Object);

            // When
            var result = sut.Index();

            // Then
            Assert.IsType<ViewResult>(result);
        }
コード例 #4
0
        public void Index_DoesNotReturnNull(Mock<IQueryService<Post>> postQueryService)
        {
            // Given
            var sut = new PostController(postQueryService.Object);

            // When
            var result = sut.Index();

            // Then
            Assert.NotNull(result);
        }
コード例 #5
0
        public void Index_WithSomePosts_ReturnsViewWithPublishedPostInItsModel(
            Mock<IQueryService<Post>> postQueryService,
            Post[] posts)
        {
            // Given
            var publishedPosts = posts.Where(p => !p.IsDraft);
            postQueryService.Setup(s => s.Find()).Returns(posts);
            var sut = new PostController(postQueryService.Object);

            // When
            var view = sut.Index();
            var result = view.ViewData.Model as IEnumerable<Post>;

            // Then
            Assert.Equal(publishedPosts.Count(), result.Count());
        }
コード例 #6
0
        public void Index_WithNoPosts_ReturnsViewWithEmptyPostsSequenceInViewBag(Mock<IQueryService<Post>> postQueryService)
        {
            // Given
            var sut = new PostController(postQueryService.Object);

            // When
            var result = sut.Index();
            var posts = result.ViewData.Model as IEnumerable<Post>;

            // Then
            Assert.False(posts.Any());
        }