public void ShouldDeleteCommentLikeWhenCommentLikedByUserAlready() { var commentLike = _commentLikes.Where(a => a.CommentId == 1 && a.UserId == 1).ToList(); _commentLikeRepository = new Mock<ICommentLikeRepository>(); _commentLikeRepository.Setup(a => a.Find(It.IsAny<Expression<Func<CommentLike, bool>>>(), false)) .Returns(commentLike); _commentLikeRepository.Setup(a => a.Delete(It.IsAny<CommentLike>())); _commentLikesLogic = new CommentLikesLogic(_commentLikeRepository.Object); var result = _commentLikesLogic.Add(new Common.Contracts.CommentLike { CommentId = 1, UserId = 1 }); Assert.Null(result); }
public void ShouldThrowExceptionWhenAddCommentLikeFails() { _commentLikeRepository = new Mock<ICommentLikeRepository>(); _commentLikeRepository.Setup(a => a.Find(It.IsAny<Expression<Func<CommentLike, bool>>>(), false)) .Throws(new Exception()); _commentLikesLogic = new CommentLikesLogic(_commentLikeRepository.Object); Assert.Throws<BlogException>(() => _commentLikesLogic.Add(new Common.Contracts.CommentLike())); }
public void ShouldAddCommentLikeWhenCommentNotYetLikedByUser() { var commentLike = new CommentLike { CommentLikeId = 4, CommentId = 1, UserId = 1, User = new User { UserId = 1, UserName = "******" } }; _commentLikeRepository = new Mock<ICommentLikeRepository>(); _commentLikeRepository.Setup(a => a.Find(It.IsAny<Expression<Func<CommentLike, bool>>>(), false)) .Returns(new List<CommentLike>()); _commentLikeRepository.Setup(a => a.Add(It.IsAny<CommentLike>())) .Returns(commentLike); _commentLikesLogic = new CommentLikesLogic(_commentLikeRepository.Object); var result = _commentLikesLogic.Add(new Common.Contracts.CommentLike { CommentId = 1, UserId = 1 }); Assert.NotNull(result); Assert.AreEqual(4, result.CommentLikeId); }