Пример #1
0
        public async Task Delete_Post_ThatDoesNotExist_Returns_NotFound()
        {
            //Arrange
            postRepository.Setup(repo => repo.GetPostAsync(It.IsAny <Guid>())).ReturnsAsync(() => null);

            //Act
            var result = await postsController.DeletePost(Guid.NewGuid());

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
Пример #2
0
        public async Task DeletePost_GetPost_Model_Ok()
        {
            var postgDto = _postManager.Setup(repo => repo.GetPost(1))
                           .ReturnsAsync(new PostDto());

            var result = await _controller
                         .DeletePost(new PostViewModel { Id = 1 });

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <PostViewModel>(viewResult.Model);
        }
        public void PostApiController_DeletePost()
        {
            var postId = 6;
            var result = _postsApiController.DeletePost(postId) as OkNegotiatedContentResult <PostApiEntity>;

            _postRepository.ReceivedWithAnyArgs().Remove(p => p.Id == postId);
            _postRepository.ClearReceivedCalls();
        }
        public async void DeletePost_ReturnsBadRequestObjectResult_WhenThePostGuidIdIsInvalid()
        {
            //Arrange
            var controller = new PostsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object);
            //Act
            var result = await controller.DeletePost(ConstIds.InvalidGuid);

            //Assert
            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal($"{ConstIds.InvalidGuid} is not valid guid.", badRequestObjectResult.Value);
        }
        public void DeletePostReturnsOk()
        {
            // Arrange

            // Act
            IHttpActionResult actionResult = _controller.DeletePost(_postIDFirst);

            // 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
            _postRepositoryMock.Verify(p => p.GetByID(_postIDFirst), Times.Once);
            _postRepositoryMock.Verify(p => p.Delete(_posts[_postIDFirstIndexInArray]), Times.Once);
            _unitOfWorkMock.Verify(uow => uow.Commit(), Times.Once);
            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <PostModel>));
            var contentResult = actionResult as OkNegotiatedContentResult <PostModel>;

            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.IsTrue(contentResult.Content.PostID == _postIDFirst);
        }
        public async void DeletePost_ReturnsNoContentResult_WhenThePostHasBeenRemoved()
        {
            //Arrange
            _mockPostService.Setup(Service => Service.DeletePostAsync(It.IsAny <Guid>()))
            .Verifiable();

            var controller = new PostsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object);
            //Act
            var result = await controller.DeletePost(ConstIds.ExamplePostId);

            //Act
            var noContentResult = Assert.IsType <NoContentResult>(result);

            _mockPostService.Verify();
        }
        public async void DeletePost_ReturnsInternalServerErrorResult_WhenExceptionThrownInService()
        {
            //Arrange
            _mockPostService.Setup(Service => Service.DeletePostAsync(It.IsAny <Guid>()))
            .Throws(new ArgumentNullException(nameof(Guid)))
            .Verifiable();

            var controller = new PostsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object);
            //Act
            var result = await controller.DeletePost(ConstIds.ExamplePostId);

            //Assert
            var internalServerErrorResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal(StatusCodes.Status500InternalServerError, internalServerErrorResult.StatusCode);
            _mockPostService.Verify();
        }
Пример #8
0
        public void CanDeletePost()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.DeletePost(1) as ObjectResult;

            _postRepository.Verify(m =>
                                   m.DeletePost(It.IsAny <Post>()), Times.Once);
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("deleted", result.Value);
        }
Пример #9
0
        public void CannotDeletePost_PostNotFound()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.DeletePost(0) as ObjectResult;

            _postRepository.Verify(m =>
                                   m.DeletePost(It.IsAny <Post>()), Times.Never);
            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("Post not found", result.Value);
        }