Esempio n. 1
0
        public void ShouldReturnEmptyListWhenGetTagsByPostIdFoundNoRecords()
        {
            _tagRepository = new Mock<ITagRepository>();
            _tagRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Tag, bool>>>(), null, string.Empty))
                .Returns(new List<Tag>());

            _postRepository = new Mock<IPostRepository>();
            _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(),
                It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>()))
                .Returns(new List<Post>());

            _tagsLogic = new TagsLogic(_tagRepository.Object, _postRepository.Object);

            var tags = _tagsLogic.GetByPostId(1);

            Assert.AreEqual(0, tags.Count);
        }
Esempio n. 2
0
        public void ShouldGetTagsByPostId()
        {
            const int postId = 1;
            var tags = _tags.Where(a => a.TagId != 3).ToList();
            var post = _posts.Where(a => a.PostId == 1).ToList();

            _tagRepository = new Mock<ITagRepository>();
            _tagRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Tag, bool>>>(), null, string.Empty))
                .Returns(tags);

            _postRepository = new Mock<IPostRepository>();
            _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(),
                It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>()))
                .Returns(post);

            _tagsLogic = new TagsLogic(_tagRepository.Object, _postRepository.Object);

            var result = _tagsLogic.GetByPostId(postId);

            Assert.AreEqual(2, result.Count);

        }
Esempio n. 3
0
        public void ShouldThrowExceptionWhenGetTagsByPostIdFails()
        {
            _tagRepository = new Mock<ITagRepository>();
            _tagRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Tag, bool>>>(), null, string.Empty))
                .Throws(new Exception());

            _postRepository = new Mock<IPostRepository>();
            _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(),
                It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>()))
                .Throws(new Exception());

            _tagsLogic = new TagsLogic(_tagRepository.Object, _postRepository.Object);
            
            Assert.Throws<BlogException>(() => _tagsLogic.GetByPostId(1));
        }