コード例 #1
0
        public void AddComment_ShouldAdd()
        {
            var videoRepositoryMock   = new Mock <IRepository <Video> >();
            var unitOfWorkMock        = new Mock <IUnitOfWork>();
            var commentRepositoryMock = new Mock <IRepository <Comment> >();
            var userRepositoryMock    = new Mock <IRepository <VidconfileUser> >();

            Comment value = null;

            commentRepositoryMock.Setup(x => x.Add(It.IsAny <Comment>()))
            .Callback <Comment>(x => value = x);

            CommentServices commentService =
                new CommentServices(commentRepositoryMock.Object, unitOfWorkMock.Object, userRepositoryMock.Object, videoRepositoryMock.Object);

            Video          video       = new Video();
            VidconfileUser user        = new VidconfileUser();
            string         commentText = "asdasd";

            commentService.AddComment(video, user, commentText);

            Assert.Same(video, value.Video);
            Assert.Same(user, value.Author);
            Assert.Same(commentText, value.CommentText);

            commentRepositoryMock.Verify(x => x.Add(value), Times.Once);
            unitOfWorkMock.Verify(x => x.Commit(), Times.Once);
        }
コード例 #2
0
        public PartialViewResult _AddComment(Comment comment)
        {
            _commentService.AddComment(comment);
            var comments = _commentService.GetComments(comment.SessionId);

            ViewBag.SessionId = comment.SessionId;

            return(PartialView("_CommentList", new CommentsViewModel {
                Items = comments.ToList()
            }));
        }
コード例 #3
0
        public void AddComment_NullVideo_ShouldThrow()
        {
            var videoRepositoryMock   = new Mock <IRepository <Video> >();
            var unitOfWorkMock        = new Mock <IUnitOfWork>();
            var commentRepositoryMock = new Mock <IRepository <Comment> >();
            var userRepositoryMock    = new Mock <IRepository <VidconfileUser> >();

            CommentServices commentService =
                new CommentServices(commentRepositoryMock.Object, unitOfWorkMock.Object, userRepositoryMock.Object, videoRepositoryMock.Object);

            Video          video       = new Video();
            VidconfileUser user        = new VidconfileUser();
            string         commentText = "asdasd";

            string message = Assert
                             .Throws <NullReferenceException>(() => commentService.AddComment(null, user, commentText))
                             .Message;

            Assert.Equal("video cannot be null", message);
        }