public void ShouldErrorWhenTagExistsOnAdd() { var tag = new Common.Contracts.Tag { TagName = "lorem" }; var tags = _tags.Where(a => a.TagName == "lorem").ToList(); _tagRepository = new Mock<ITagRepository>(); _tagRepository.Setup(a => a.Add(It.IsAny<Tag>())).Returns(It.IsAny<Tag>); _tagRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Tag, bool>>>(), It.IsAny<Func<IQueryable<Tag>, IOrderedQueryable<Tag>>>(), It.IsAny<string>())) .Returns(tags); _postRepository = new Mock<IPostRepository>(); _tagsLogic = new TagsLogic(_tagRepository.Object, _postRepository.Object); var result = _tagsLogic.Add(tag); Assert.NotNull(result.Error); Assert.AreEqual((int)Constants.Error.ValidationError, result.Error.Id); Assert.AreEqual("Record already exists", result.Error.Message); }
public void ShouldThrowExceptionWhenAddingTagFails() { var tag = new Common.Contracts.Tag { TagName = "foo" }; _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.Add(tag)); }
public void ShouldAddTag() { var tag = new Common.Contracts.Tag {TagName = "foo"}; _tagRepository = new Mock<ITagRepository>(); _tagRepository.Setup(a => a.Add(It.IsAny<Tag>())).Returns(new Tag { TagName = "foo" }); _tagRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Tag, bool>>>(), It.IsAny<Func<IQueryable<Tag>, IOrderedQueryable<Tag>>>(), It.IsAny<string>())) .Returns(new List<Tag>()); _postRepository = new Mock<IPostRepository>(); _tagsLogic = new TagsLogic(_tagRepository.Object, _postRepository.Object); var result = _tagsLogic.Add(tag); Assert.NotNull(result); Assert.IsNull(result.Error); }