Exemplo n.º 1
0
        public void ShouldThrowExceptionWhenAddCommentFails()
        {
            _commentsRepository = new Mock<ICommentRepository>();
            _commentsRepository.Setup(a => a.Add(It.IsAny<Comment>())).Throws(new Exception());

            _userRepository = new Mock<IUserRepository>();

            _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object);

            Assert.Throws<BlogException>(() => _commentsLogic.Add(new Common.Contracts.Comment()));
        }
Exemplo n.º 2
0
        public void ShouldAddComment()
        {
            var dbResult = new Comment
            {
                CommentId = 7,
                PostId = 1,
                ParentCommentId = null,
                CommentMessage = "Lorem ipsum dolor",
                UserId = 1
            };

            var dbUser = new User {UserId = 1, UserName = "******"};

            _commentsRepository = new Mock<ICommentRepository>();
            _commentsRepository.Setup(a => a.Add(It.IsAny<Comment>())).Returns(dbResult);

            _userRepository = new Mock<IUserRepository>();
            _userRepository.Setup(a => a.Find(It.IsAny<Expression<Func<User, bool>>>(), false)).Returns(new List<User> { dbUser });

            _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object);

            var result = _commentsLogic.Add(new Common.Contracts.Comment
            {
                Id = 7,
                PostId = 1,
                ParentCommentId = null,
                CommentMessage = "Lorem ipsum dolor",
                User = new Common.Contracts.User
                {
                    Id = 1,
                    UserName = "******"
                }
            });

            Assert.IsNotNull(result);
        }