Пример #1
0
        public async Task CreateBlogPostReturnsCreatedResponse()
        {
            // Arrange
            BlogPost blogPost = new BlogPost
            {
                Title       = "Augmented Reality iOS Application",
                Description = "Rubicon Software Development and Gazzda furniture are proud to launch an augmented reality app.",
                Body        = "The app is simple to use, and will help you decide on your best furniture fit.",
                TagList     = new string[] { "iOS", "AR" }
            };
            var mockRepository = new Mock <IBlogPostService>();

            mockRepository.Setup(s => s.CreateBlogPost(blogPost))
            .Returns(Task.FromResult(new BlogPost
            {
                Slug      = "augmented_reality_ios_application",
                TagList   = new string[] { "iOS", "AR" },
                CreatedAt = DateTime.Now,
                UpdatedAt = null
            }));
            var controller = new BlogPostController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = await controller.CreateBlogPost(blogPost);

            var createdResult = actionResult as CreatedNegotiatedContentResult <BlogPost>;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(createdResult.Content);
            Assert.IsInstanceOfType(createdResult.Content, typeof(BlogPost));
            Assert.AreEqual("augmented_reality_ios_application", createdResult.Content.Slug);
        }