public void ShouldReturnEmptyListWhenGetPostContentsByPostFoundNoRecords() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Returns(new List<PostContent>()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var contents = _postContentsLogic.GetByPostId(1); Assert.NotNull(contents); Assert.AreEqual(0, contents.Count); }
public void ShouldGetPostContentsByPost() { var postContents = _postContents.Where(a => a.PostId == 1).ToList(); _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Returns(postContents); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var contents = _postContentsLogic.GetByPostId(1); Assert.AreEqual(2, contents.Count); Assert.AreEqual(1, contents[0].PostId); Assert.AreEqual(1, contents[1].PostId); }
public void ShouldThrowExceptionWhenGetPostContentsByPostFails() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Throws(new Exception()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); Assert.Throws<BlogException>(() => _postContentsLogic.GetByPostId(1)); }
public void ShouldReturnFalseWhenDeletePostContentFoundNoRecord() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), false)) .Returns(new List<PostContent>()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var result = _postContentsLogic.Delete(1); Assert.IsFalse(result); }
public void ShouldThrowExceptionWhenDeletePostContentFails() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Delete(It.IsAny<PostContent>())).Throws(new Exception()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); Assert.Throws<BlogException>(() => _postContentsLogic.Delete(1)); }
public void ShouldReturnTrueOnDeletePostContent() { var dbResult = new List<PostContent> { new PostContent { PostContentId = 1 } }; _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), false)) .Returns(dbResult); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var result = _postContentsLogic.Delete(1); Assert.IsTrue(result); }
public void ShouldThrowExceptionWhenAddPostContentFails() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Add(It.IsAny<PostContent>())).Throws(new Exception()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); Assert.Throws<BlogException>(() => _postContentsLogic.Add(new Common.Contracts.PostContent())); }
public void ShouldAddPostContent() { var dbResult = new PostContent { PostContentId = 4, PostContentTitle = "Foo", PostContentText = "Lorem Ipsum Dolor", PostId = 2 }; _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Add(It.IsAny<PostContent>())).Returns(dbResult); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var result = _postContentsLogic.Add(new Common.Contracts.PostContent { Id = 4, PostContentTitle = "Foo", PostContentText = "Lorem Ipsum Dolor", PostId = 5 }); Assert.IsNotNull(result); Assert.AreEqual(2, result.PostId); }
public void ShouldErrorWhenGetPostContentByIdFoundNoRecord() { _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Returns(new List<PostContent>()); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var content = _postContentsLogic.Get(1); Assert.NotNull(content.Error); Assert.AreEqual((int)Constants.Error.RecordNotFound, content.Error.Id); Assert.AreEqual("Cannot find post content with Id 1", content.Error.Message); }
public void ShouldGetPostContentById() { var postContent = _postContents.FirstOrDefault(a => a.PostContentId == 1); _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Returns(new List<PostContent> { postContent }); _postContentsLogic = new PostContentsLogic(_postContentRepository.Object); var content = _postContentsLogic.Get(1); Assert.AreEqual(1, content.Id); }