public void Posts_Delete() { _controller.Delete(1); _controller.Delete(0); _postService.Received().DeletePost(Arg.Is <int>(id => id > 0)); _postService.DidNotReceive().DeletePost(0); }
public void DeleteWithNoIdReturnError() { // Act ViewResult actual = controller.Delete(null) as ViewResult; // Assert Assert.AreEqual("Error", actual.ViewName); }
public void DeletePost() { Assert.Equal(2, DbPosts.Count); var existingPost = DbPosts.FirstOrDefault(); var result = _controller.Delete(existingPost.Id) as OkResult; Assert.NotNull(result); Assert.Equal(1, DbPosts.Count); Assert.Null(DbPosts.Find(x => x.Id == existingPost.Id)); }
public async Task Delete_PostIsNull_ReturnNotFoundResult() { _unitOfWork .Setup(x => x.PostRepository.GetById(It.IsAny <int>())) .ReturnsAsync((Post)null); var result = await _controller.Delete(It.IsAny <int>()); result .Should() .BeOfType <NotFoundResult>(); }
public void Verify_NotFound_When_Delete_Called_Post_Not_In_System() { //arrange var user = getDefaultUser(); var post = GetDefaultPost(); _postServiceMock.Setup(_ => _.GetPostById(It.IsAny <int>())) .ReturnsAsync(() => null); //act var result = sut.Delete(user.Id, post.Id).Result; //assert var okResult = Assert.IsType <NotFoundObjectResult>(result); }
public void Delete_Post_Deletes_Post() { var id = Guid.NewGuid().ToString(); var isDeleted = postsController.Delete(id); Assert.IsTrue(isDeleted); }
public void TestDeletePostNegative() { PostsService service = new PostsService(); PostsController controller = new PostsController(service); controller.Delete(-1); }
public void Delete_ShouldReturnInstanceOfViewResult_WhenPostServiceReturnValidPost() { // Arrange var postsServiceMock = new Mock <IDataService <Post> >(); postsServiceMock.Setup(x => x.GetById(It.IsAny <object>())).Returns(new Post { Id = 1 }); var categoriesServiceMock = new Mock <IDataService <PostCategory> >(); var usersServiceMock = new Mock <IDataService <ApplicationUser> >(); var commentsServiceMock = new Mock <IDataService <Comment> >(); var mockedMapper = new Mock <IMapper>(); var controller = new PostsController( postsServiceMock.Object, categoriesServiceMock.Object, usersServiceMock.Object, commentsServiceMock.Object, mockedMapper.Object); // Act var result = controller.Delete(1); // Assert Assert.IsInstanceOf <ViewResult>(result); }
public void TestDeletePostPositive() { PostsService service = new PostsService(); PostsController controller = new PostsController(service); //id of existing post controller.Delete(2); }
public void DeletePostRemoveFromList() { Post samplePost = new Post("sample", "content"); controller.Create(blog.ID, samplePost); var posts = controller.GetPosts(blog.ID).Value; samplePost = posts.FirstOrDefault(target => target.Title == samplePost.Title); Assert.NotNull(samplePost); controller.Delete(blog.ID, samplePost.ID); samplePost = controller.GetPosts(blog.ID).Value .FirstOrDefault(target => target.Title == samplePost.Title); Assert.Null(samplePost); }
public void Delete_ReturnsNoContent() { var controller = new PostsController(new PostService()); var result = controller.Delete(1); Assert.IsType <NoContentResult>(result); }
public void Post_Delete_With_Error() { _mockUserContext.Setup(x => x.HasGroupPermission(It.IsAny <string>(), It.IsAny <string>())).Returns(true); _controller.ModelState.AddModelError("Error", "Error"); var result = _controller.Delete(new IdInput() { Id = FakeValues.KeyString }); Assert.IsInstanceOf <JsonResult>(result); var jsonResult = result as JsonResult; Assert.IsNotNull(jsonResult); Assert.AreEqual(jsonResult.Data.ToString().ToLower(), "Failure".ToLower()); }
public void PostsController_Delete() { var postId = 6; var viewResult = _postsController.Delete(postId) as ViewResult; _postRepository.ReceivedWithAnyArgs().Remove(p => p.Id == postId); _postRepository.ClearReceivedCalls(); }
public void Get_NoContent() { // Ensure that Delete(id) returns No Content status if Delete if successful var controller = new PostsController(new PostService()); //act - id 2 is in the seed data, should exist var result = controller.Delete(2); // assert Assert.IsType <NoContentResult>(result); }
public void DeleteTest() { //Arrange PostsController postsController = new PostsController(); //Act var result = postsController.Delete(1006); //Assert Assert.IsNotNull(result); }
public void Delete_DeleteNonExistingPost_PostShouldNotBeDeleted() { // Arrange var controller = new PostsController(postService); // Act IHttpActionResult result = controller.Delete(5); // Assert Assert.IsInstanceOfType(result, typeof(BadRequestResult)); }
public void Delete_NotFound(int id) { // Arrange var repo = new EntityRepository(new TestStoreDbContext()); PostsController postsController = new PostsController(repo); // Act IHttpActionResult actionResult = postsController.Delete(id); // Assert Assert.IsType <NotFoundResult>(actionResult); }
public void OnPost_ShouldDeletePost(ApplicationDbContext context) { //Arrange int id = 1; bool ChangesError = false; PostsController postController = new PostsController(context); //Act ViewResult objectViewResult = postController.Delete(id, ChangesError) as ViewResult; //Assert Assert.AreEqual("Delete", objectViewResult.ViewName); }
public void Delete_ShouldCallPostServiceDelete() { // Arrange var postServiceMock = new Mock <IPostService>(); var controller = new PostsController(postServiceMock.Object); var guid = Guid.NewGuid(); // Act var result = controller.Delete(guid); // Assert postServiceMock.Verify(x => x.Delete(It.Is <Guid>(y => y == guid))); }
public void DeleteMethodCallsRepositoryDeleteMethodAndReturnsOkResult() { // arrange var postId = 5; mockRepository.Setup(x => x.Delete(postId)); // act IActionResult result = controller.Delete(postId); // assert mockRepository.VerifyAll(); Assert.IsInstanceOf <OkResult>(result); }
public async Task Delete_SuccessShouldReturnOk() { // Arrange PostsController controller = new PostsController(); // Act var actionResult = await controller.Delete(234); var responseMessage = actionResult as OkNegotiatedContentResult <HttpResponseMessage>; // Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(responseMessage); }
public async Task DeleteShouldReturnProperRedirect() { // Arrange var mockPostsService = new Mock <IPostsService>(); var controller = new PostsController(mockPostsService.Object); // Act var result = await controller.Delete(0); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); }
public async Task Delete_IdLessThanOneShouldReturnBadRequest() { // Arrange PostsController controller = new PostsController(); // Act var actionResult = await controller.Delete(0); var contentResult = actionResult as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(actionResult); Assert.IsNotNull(contentResult); Assert.AreEqual("invalid id", contentResult.Message); }
public async void Delete_Errors() { PostsControllerMockFacade mock = new PostsControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); PostsController controller = new PostsController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
public void Delete_ShouldReturnInstanceHttpNotFoundResult_WhenPostServiceCantFindPost() { // Arrange var postsServiceMock = new Mock <IDataService <Post> >(); var categoriesServiceMock = new Mock <IDataService <PostCategory> >(); var usersServiceMock = new Mock <IDataService <ApplicationUser> >(); var commentsServiceMock = new Mock <IDataService <Comment> >(); var mockedMapper = new Mock <IMapper>(); var controller = new PostsController( postsServiceMock.Object, categoriesServiceMock.Object, usersServiceMock.Object, commentsServiceMock.Object, mockedMapper.Object); // Act var result = controller.Delete(1); // Assert Assert.IsInstanceOf <HttpNotFoundResult>(result); }
public void DeletePost() { var actionResult = _controller.Delete(1); Assert.IsInstanceOfType(actionResult, typeof(OkResult)); }
public void PostControllerDelete() { var result = _ctrl.Delete("96d5b379-7e1d-4dac-a6ba-1e50db561b04"); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
private void btnDelete_Click(object sender, EventArgs e) { _ctrlPosts.Delete(Int32.Parse(txtId.Text)); CleanTextBox(); }