public void Constructor_SutIsController(Mock<IQueryService<Post>> postQueryService) { // When var sut = new PostController(postQueryService.Object); // Then Assert.IsAssignableFrom<Controller>(sut); }
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); }
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); }
public void Index_DoesNotReturnNull(Mock<IQueryService<Post>> postQueryService) { // Given var sut = new PostController(postQueryService.Object); // When var result = sut.Index(); // Then Assert.NotNull(result); }
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()); }
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()); }