コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }