Exemplo n.º 1
0
        public void ShouldThrowExceptionWhenGetCommentByIdFails()
        {
            _commentsRepository = new Mock<ICommentRepository>();
            _commentsRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Comment, bool>>>(),
                It.IsAny<Func<IQueryable<Comment>, IOrderedQueryable<Comment>>>(), It.IsAny<string>()))
                .Throws(new Exception());

            _userRepository = new Mock<IUserRepository>();

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

            Assert.Throws<BlogException>(() => _commentsLogic.Get(1));
        }
Exemplo n.º 2
0
        public void ShouldGetCommentById()
        {
            var expected = _comments.Where(a => a.CommentId == 1).ToList();
            _commentsRepository = new Mock<ICommentRepository>();
            _commentsRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Comment, bool>>>(),
                It.IsAny<Func<IQueryable<Comment>, IOrderedQueryable<Comment>>>(), It.IsAny<string>()))
                .Returns(expected);

            _userRepository = new Mock<IUserRepository>();

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

            var result = _commentsLogic.Get(1);

            Assert.NotNull(result);
            Assert.IsInstanceOf(typeof(Common.Contracts.Comment), result);
        }