コード例 #1
0
        public void Check_InsertNewPost()
        {
            BlogPostController postController = new BlogPostController();
            var newPost = postController.InsertNewPost(
                new Post {
                Title = "Third Post", Author = "Diego", Content = "Third Post by Diego"
            }
                );

            Assert.IsType <OkObjectResult>(newPost);
        }
コード例 #2
0
        public void Create_WhenCalled_WithValidBlogPost_ReturnsCreatedAtActionResult()
        {
            // var mockService = new Mock<IBlogPostService>();
            var fakePost = new BlogPost {
                Title = "First BlogPost", Author = "Oscar Recio", Content = "First BlogPost by Oscar Recio"
            };

            mockService.Setup(serv => serv.Insert(fakePost)).Returns(new BlogPost {
                Id = 1, Title = "First BlogPost", Author = "Oscar Recio", Content = "First BlogPost by Oscar Recio"
            });
            //Given
            BlogPostController blogPostController = new BlogPostController(mockService.Object);

            //When
            var getResult = blogPostController.InsertNewPost(fakePost);

            //Then
            Assert.IsType <CreatedAtActionResult>(getResult);
        }