public void AddLike_addPositiveLike_commentPopertyNegativeLikePlus1() { // Arrange const int userId = 1; const int commentId = 2; const bool isPositiveLike = false; var commentBo = new CommentBo(_commentRepo, _commentLikesRepo); _commentRepo .GetItem(Arg.Is<int>(x => x >= 1)) .Returns(new Comment { Id = commentId, PostId = 1, UserId = 1, }); _commentLikesRepo .Query() .Returns(new List<CommentVote> { new CommentVote { Id = 1, UserId = 3, CommentId = 1 }, new CommentVote { Id = 2, UserId = 3, CommentId = 2 } } .AsQueryable()); // Act commentBo.AddLike(userId, commentId, isPositiveLike); // Assert var commennt = _commentRepo.GetItem(1); Assert.AreEqual(commennt.NegativeLike, 1); _commentRepo .Received(1) .Save(); }
public void AddLike_likeAlreadyExist_likeNotAdded() { // Arrange const int userId = 2; const int commentId = 2; const bool isPositiveLike = false; var commentBo = new CommentBo(_commentRepo, _commentLikesRepo); _commentLikesRepo .Query() .Returns(new List<CommentVote> { new CommentVote { Id = 1, UserId = 1, CommentId = 1 }, new CommentVote { Id = 2, UserId = 2, CommentId = 2 } } .AsQueryable()); // Act commentBo.AddLike(userId, commentId, isPositiveLike); // Assert _commentLikesRepo .Received(0) .Create(Arg.Is<CommentVote>(x => x.UserId == 5 && x.CommentId == commentId)); }