public void DeleteBlogNoPostsReturnsOk() { // Arrange _userRepositoryMock.Setup(pr => pr.FirstOrDefault(It.IsAny <Expression <Func <User, bool> > >())) .Returns(_users[_userAuthorizedIndexInArray]); // Act IHttpActionResult actionResult = _controller.DeleteBlog(_blogIDApprovedNoMockPosts); // Assert // Verify: // GetByID is called once // Delete is called once with correct object // Unit of work commit is called once // Result is OK, and content result ID matches _blogRepositoryMock.Verify(p => p.GetByID(_blogIDApprovedNoMockPosts), Times.Once); _blogRepositoryMock.Verify(p => p.Delete(_blogs[_blogIDApprovedNoMockPostsIndexInArray]), Times.Once); _unitOfWorkMock.Verify(uow => uow.Commit(), Times.Once); Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <BlogModel>)); var contentResult = actionResult as OkNegotiatedContentResult <BlogModel>; Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.IsTrue(contentResult.Content.BlogID == _blogIDApprovedNoMockPosts); }
public async Task DeleteBlog_GetBlog_Model_ViewName_Ok() { var blogDto = _blogManager.Setup(repo => repo.GetBlog(1)) .ReturnsAsync(new BlogDto()); var result = await _controller .DeleteBlog(new BlogViewModel { Id = 1 }); var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <BlogViewModel>(viewResult.Model); }
public void DeleteBlog_Should_Return_Ok() { mockService.Setup(service => service.DeleteBlog(1)) .Returns(blogForTest); mockMapper.Setup(mapper => mapper.Map <BlogResponse>(It.IsAny <Blog>())) .Returns(new BlogResponse { Id = 1 }); var result = controller.DeleteBlog(1); var blogResult = Assert.IsAssignableFrom <ActionResult <BlogResponse> >(result); Assert.Equal(1, blogResult.Value.Id); }