public void ShouldGetPostLikes() { var postLikes = _postLikes.Where(a => a.PostId == 1).ToList(); _postLikeRepository = new Mock<IPostLikeRepository>(); _postLikeRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostLike, bool>>>(), true)) .Returns(postLikes); _postLikesLogic = new PostLikesLogic(_postLikeRepository.Object); var result = _postLikesLogic.Get(1); Assert.AreEqual(2, result.Count); Assert.AreEqual(1, result[0].PostId); Assert.AreEqual(1, result[1].PostId); }
public void ShouldReturnEmptyListWhenGetPostLikesFoundNoRecords() { _postLikeRepository = new Mock<IPostLikeRepository>(); _postLikeRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostLike, bool>>>(), true)) .Returns(new List<PostLike>()); _postLikesLogic = new PostLikesLogic(_postLikeRepository.Object); var result = _postLikesLogic.Get(1); Assert.NotNull(result); Assert.AreEqual(0, result.Count); }
public void ShouldThrowExceptionWhenGetPostLikesFails() { _postLikeRepository = new Mock<IPostLikeRepository>(); _postLikeRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostLike, bool>>>(), true)) .Throws(new Exception()); _postLikesLogic = new PostLikesLogic(_postLikeRepository.Object); Assert.Throws<BlogException>(() => _postLikesLogic.Get(1)); }