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 ShouldThrowExceptionWhenGetPostContentByIdFails() { _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.Get(1)); }
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); }