예제 #1
0
        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
            })
                                                             );
        }
예제 #2
0
        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());
        }
예제 #3
0
        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);
        }