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