Пример #1
0
        public IActionResult GetBlogPostById(int id)
        {
            var blogPost = _blogPostService.GetBlogPost(id);

            if (blogPost == null)
            {
                return(NotFound());
            }

            return(Ok(blogPost));
        }
Пример #2
0
        public void ShouldGetBlogPostById()
        {
            Mock <IAuthorRepository>   authorRepositoryMock   = new Mock <IAuthorRepository>();
            Mock <IBlogPostRepository> blogPostRepositoryMock = new Mock <IBlogPostRepository>();
            var id       = "5b9d8e952e6adf8005dbcf17";
            var expected = "TestSubject";

            blogPostRepositoryMock.Setup(x => x.GetByUserIdAndId(It.IsAny <string>(), It.IsAny <string>())).Returns(new BlogPost
            {
                Title = expected
            });
            authorRepositoryMock.Setup(x => x.GetByUserIdAndId(It.IsAny <string>(), It.IsAny <string>())).Returns(new Author
            {
                Name = "AuthorTest"
            });
            var mapper = TestHelper.GetMapper();
            var sut    = new BlogPostService(authorRepositoryMock.Object, blogPostRepositoryMock.Object, mapper);
            var result = sut.GetBlogPost("12345", id);

            Assert.NotNull(result);
            Assert.Equal(expected, result.Title);
        }