public void ShouldThrowExceptionWhenGetTagsByNameFails() { _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>(); _tagsLogic = new TagsLogic(_tagRepository.Object, _postRepository.Object); Assert.Throws<BlogException>(() => _tagsLogic.GetTagsByName("foo")); }
public void ShouldGetTagsByName() { const string tagName = "ipsum"; var tags = _tags.Where(a => a.TagName.Contains(tagName)).ToList(); _tagRepository = new Mock<ITagRepository>(); _tagRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Tag, bool>>>(), true)) .Returns(tags); _postRepository = new Mock<IPostRepository>(); _tagsLogic = new TagsLogic(_tagRepository.Object, _postRepository.Object); var result = _tagsLogic.GetTagsByName(tagName); Assert.AreEqual(2, result.Count); }