public void ShouldGetPostContentsByPost() { var postContents = _postContents.Where(a => a.PostId == 1).ToList(); _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Returns(postContents); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var contents = _postContentsLogic.GetByPostId(1); Assert.AreEqual(2, contents.Count); Assert.AreEqual(1, contents[0].PostId); Assert.AreEqual(1, contents[1].PostId); }
public void ShouldThrowExceptionWhenGetPostContentsByPostFails() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Throws(new Exception()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); Assert.Throws<BlogException>(() => _postContentsLogic.GetByPostId(1)); }
public void ShouldReturnEmptyListWhenGetPostContentsByPostFoundNoRecords() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Returns(new List<PostContent>()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var contents = _postContentsLogic.GetByPostId(1); Assert.NotNull(contents); Assert.AreEqual(0, contents.Count); }