public void AddCommentLike_DuplicateLike_ThrowEx() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new LikesService(mock.Object); Assert.Throws <NegotiatedContentResultException>(() => controller.AddCommentLike(new CommentLikes { UserId = 2, CommentId = 1 }) ); }
public void AddCommentLike_ValidLike_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new LikesService(mock.Object); controller.AddCommentLike(new CommentLikes { UserId = 1, CommentId = 1 }); init.mockSetCommentLikes.Verify(m => m.Add(It.IsAny <CommentLikes>()), Times.Once()); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void AddCommentLike_Counting_Test() { var init = new InitializeMockContext(); var mock = init.mock; var commentId = 1; var expectedLikeCountInt = mock.Object.PostComments.Where(x => x.Id == commentId).First().LikeCount; var controller = new LikesService(mock.Object); controller.AddCommentLike(new CommentLikes { UserId = 1, CommentId = commentId }); mock.Verify(m => m.SaveChanges(), Times.Once()); Assert.AreEqual(expectedLikeCountInt + 1, mock.Object.PostComments.Where(x => x.Id == commentId).First().LikeCount); }