public void ShouldGetBlogPosts() { Mock <IAuthorRepository> authorRepositoryMock = new Mock <IAuthorRepository>(); Mock <IBlogPostRepository> blogPostRepositoryMock = new Mock <IBlogPostRepository>(); authorRepositoryMock.Setup(x => x.GetByUserIdAndId(It.IsAny <string>(), It.IsAny <string>())).Returns(new Author { Name = "AuthorTest" }); blogPostRepositoryMock.Setup(x => x.GetAll(It.IsAny <FilterDefinition <BlogPost> >())).Returns(() => new List <BlogPost> { new BlogPost { Title = "Test1" }, new BlogPost { Title = "Test2" }, new BlogPost { Title = "Test3" } }); var mapper = TestHelper.GetMapper(); var sut = new BlogPostService(authorRepositoryMock.Object, blogPostRepositoryMock.Object, mapper); var result = sut.GetBlogPosts("12345"); Assert.NotNull(result); Assert.Equal(3, result.Count); }
public IActionResult GetBlogPosts() { return(Ok(_blogPostService.GetBlogPosts())); }