コード例 #1
0
        public void GetBlog_Should_Return_Assigned_Blog()
        {
            mockService.Setup(service => service.GetBlog(1))
            .Returns(blogForTest);
            mockMapper.Setup(mapper => mapper.Map <BlogResponse>(It.IsAny <Blog>()))
            .Returns(new BlogResponse {
                Id = 1
            });

            var result = controller.GetBlog(1);

            var blog = Assert.IsAssignableFrom <BlogResponse>(result.Value);

            Assert.Equal(1, blog.Id);
        }
コード例 #2
0
        public void GetBlogReturnsSameID()
        {
            // Arrange

            // Act
            IHttpActionResult actionResult = _controller.GetBlog(_blogIDApprovedNoMockPosts);

            // Assert
            // Verify that GetByID is called just once
            // Verify that HTTP status code is Ok, with object of correct type
            _blogRepositoryMock.Verify(p => p.GetByID(_blogIDApprovedNoMockPosts), Times.Once);
            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <BlogModel>));

            // Extract the content from the HTTP result
            // Verify the content is not null, and the IDs match
            var contentResult = actionResult as OkNegotiatedContentResult <BlogModel>;

            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(contentResult.Content.BlogID, _blogIDApprovedNoMockPosts);
        }
コード例 #3
0
        public void UpdateBlogModifiesBlogsList()
        {
            var  userID     = "dd";
            Blog sampleBlog = new Blog(userID, "blog1", "description");
            var  result     = controller.Create(sampleBlog);

            sampleBlog      = ((result as ObjectResult).Value as Blog);
            sampleBlog.Name = "blog2";

            controller.Update(sampleBlog, sampleBlog.ID);

            var blogs   = controller.GetUserBlogs(userID).Value;
            var oldBlog = blogs.FirstOrDefault(b => b.Name == "blog1");

            Assert.Null(oldBlog);

            sampleBlog = controller.GetBlog(sampleBlog.ID).Value;
            Assert.Equal(sampleBlog.Name, "blog2");
        }