public async Task Respond_To_DELETE() { var result = await _controller.Delete(null); Assert.IsInstanceOf(typeof(JArray), result); Assert.IsEmpty(result); }
public void Delete_NotExistingGuidPassed_ReturnsNotFoundResponse() { var invalidGuid = Guid.NewGuid(); var badResponse = _controller.Delete(invalidGuid).Result; Assert.IsType <NotFoundResult>(badResponse); }
public void GivenIdIsNotFoundWhenRemovingItemThenNotFoundResultIsReturned() { long id = 5; var actual = sut.Delete(id); Assert.IsType <NotFoundResult>(actual); }
public void TodoController_Delete_return_Internal_error() { _tasksService.Setup(x => x.Delete(It.IsAny <Guid>())).Throws(new Exception()); var response = _todoController.Delete(Guid.NewGuid()); Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); }
public void Remove_NotExistingGuidPassed_ReturnsNotFoundResponse() { // Arrange var notExistingGuid = Guid.NewGuid(); // Act var badResponse = _controller.Delete(notExistingGuid.ToString()).Result; // Assert Assert.IsType <NotFoundResult>(badResponse); }
public void Test_Delete_Success() { const int id = 1; var todo = new TodoItem { Id = id }; _todosRepository.Setup(x => x.Get(1)) .Returns(todo); _todosRepository.Setup(x => x.Delete(todo)); var result = _todoController.Delete(id); Assert.IsInstanceOfType(result, typeof(NoContentResult)); }
public void Delete_RedirectsToIndex_WhenSucceeded() { var result = controller.Delete(1); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); }
public void DeleteTest() { ITaskRepository repo = new ObjectTaskRepository(); TodoController controller = new TodoController(repo); controller.Delete(-1); repo.Delete(-1); ViewResult result = controller.Index() as ViewResult; Assert.AreEqual((result.Model as TodoIndexViewModel).Tasks.Count, repo.GetAll().Count); controller.Delete(2); repo.Delete(2); result = controller.Index() as ViewResult; Assert.AreEqual((result.Model as TodoIndexViewModel).Tasks.Count, repo.GetAll().Count); }
public void Test_Delete_FailCase() { var lastItem = _context.TodoItems.LastOrDefault(); var controller = new TodoController(_context); var result = controller.Delete(lastItem.Id + 1); Assert.IsType <NotFoundResult>(result); }
public void DeleteShouldReturnNotFound() { var mockCurrentUser = new Mock <ICurrentUser>(); var mockTodoRepository = new Mock <ITodoRepository>(); var controller = new TodoController(mockCurrentUser.Object, mockTodoRepository.Object); var response = controller.Delete(1); Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }
public void DeleteNote_Positive() { var datarepo = new Mock <IDataRepo>(); int id = 1; datarepo.Setup(d => d.DeleteNote(id)).Returns(true); TodoController todoController = new TodoController(datarepo.Object); var actionResult = todoController.Delete(id); var okObjectResult = actionResult as OkObjectResult; Assert.NotNull(okObjectResult); }
public void DeleteNote_Negative() { var datarepo = new Mock <IDataRepo>(); int id = 5; datarepo.Setup(d => d.DeleteNote(id)).Returns(false); TodoController todoController = new TodoController(datarepo.Object); var actionResult = todoController.Delete(id); var nfObjectResult = actionResult as NotFoundObjectResult; Assert.NotNull(nfObjectResult); }
public async void CanRemoveItemsFromList() { DbContextOptions <TodoDbContext> options = new DbContextOptionsBuilder <TodoDbContext>() .UseInMemoryDatabase("Test10Database").Options; using (TodoDbContext context = new TodoDbContext(options)) { // Arrange TodoList datList1 = new TodoList(); datList1.ID = 1; datList1.Name = "house chores"; TodoListController lc = new TodoListController(context); TodoItem datItem1 = new TodoItem(); datItem1.ID = 30; datItem1.Name = "vacuum the floor"; datItem1.IsComplete = false; datItem1.DatListID = datList1.ID; TodoItem datItem2 = new TodoItem(); datItem2.ID = 40; datItem2.Name = "wash the dishes"; datItem2.IsComplete = true; datItem2.DatListID = datList1.ID; TodoController ic = new TodoController(context); // Act - note: this requires async in order for the // result below to include all of the items in the list // Otherwise, the result query displays as having no // items according to the test even if it actually does. var createdList = await lc.Create(datList1); var createdItem1 = await ic.Create(datItem1); var createdItem2 = await ic.Create(datItem2); var deletedItem = await ic.Delete(datItem1.ID); var result1 = lc.GetById(datList1.ID); var listCount = result1.Result.Value.TodoItems.Count(); var todoInList = result1.Result.Value.TodoItems[0].Name; // Assert Assert.Equal(1, listCount); Assert.Equal(datItem2.Name, todoInList); } }
public void Delete_Returns_NoContent_If_Success() { var options = CreateDbContextOptions(); using (var todoApiDbContext = new TodoApiDbContext(options)) { var mockLogger = new Mock <ILogger <TodoController> >(); var todoController = new TodoController(mockLogger.Object, todoApiDbContext); var todo = todoController.Delete(1); Assert.IsType <NoContentResult>(todo); } }
public async Task Can_Delete_A_Todo() { var fixture = new TodoDataFixture(); var subject = new TodoController(fixture.Repository); var result = (await subject.Delete("test-id")).Result as OkObjectResult; Assert.NotNull(result); Assert.Equal(200, result.StatusCode); Assert.Equal( TodoDataFixture.TodoApiModel, (TodoApiModel)result.Value, new TodoApiModelComparer() ); Assert.Empty(fixture.Repository.Values); }
public void DeleteShouldReturnOk() { var mockCurrentUser = new Mock <ICurrentUser>(); var mockTodoRepository = new Mock <ITodoRepository>(); mockTodoRepository .Setup(_ => _.GetById(It.IsAny <int>())) .Returns(new Todo()); var controller = new TodoController(mockCurrentUser.Object, mockTodoRepository.Object); var response = controller.Delete(1); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public async Task Can_404_When_Deleting_A_Missing_Todo() { var fixture = new TodoDataFixture(); var subject = new TodoController(fixture.Repository); var result = (await subject.Delete("BADID")).Result as NotFoundObjectResult; Assert.NotNull(result); Assert.Equal(404, result.StatusCode); Assert.IsAssignableFrom <ApiErrorModel>(result.Value); Assert.Equal( "not_found", ((ApiErrorModel)result.Value).Code ); Assert.Single(fixture.Repository.Values); }
public void Test_Delete_SuccessCase() { var item = new TodoItem { Name = "Item to test delete" }; var controller = new TodoController(_context); item = (TodoItem)((CreatedAtRouteResult)controller.CreateItem(item)).Value; var deleteResult = controller.Delete(item.Id); Assert.IsType <NoContentResult>(deleteResult); var getResult = controller.GetById(item.Id); Assert.IsType <NotFoundResult>(getResult); }
public void UserFailTest() { // Arrange var mockServ = new Mock <ITodoService>(); var controller = new TodoController(mockServ.Object); // Act var actualGetResp = controller.Get(null) as BadRequestResult; var actualPostResp = controller.Post(null) as BadRequestResult; var actualPutResp = controller.Put(0, null) as BadRequestResult; var actualDeleteResp = controller.Delete(0) as BadRequestResult; // Assert Assert.IsNotNull(actualGetResp); Assert.IsNotNull(actualPostResp); Assert.IsNotNull(actualPutResp); Assert.IsNotNull(actualDeleteResp); }
public void DeleteFailTest() { var userId = 1; var todoId = 1; // Arrange var mockServ = new Mock <ITodoService>(); mockServ.Setup(s => s.DeleteTodo(todoId, userId)).Returns(false); var controller = new TodoController(mockServ.Object); controller.ControllerContext = FakeContext; // Act var actualResp = controller.Delete(todoId) as BadRequestResult; // Assert Assert.IsNotNull(actualResp); }
public void Delete_Removes_Todo() { var todoId = 1; var deletedTodo = new Todo(todoId, "First item"); var todoList = new List <Todo>() { deletedTodo, new Todo(2, "Second item") }; todoRepo.GetById(todoId).Returns(deletedTodo); todoRepo.When(d => d.Delete(deletedTodo)) .Do(d => todoList.Remove(deletedTodo)); todoRepo.GetAll().Returns(todoList); var result = underTest.Delete(todoId); // Assert.DoesNotContain(deletedTodo, result); Does not work in all cases Assert.All(result, item => Assert.Contains("Second item", item.Name)); }
public async void CanDeleteTodoItem() { DbContextOptions <TodoDbContext> options = new DbContextOptionsBuilder <TodoDbContext>() .UseInMemoryDatabase("Test4Database").Options; using (TodoDbContext context = new TodoDbContext(options)) { // Arrange // Note: For this test, the ID has to be different // than 1 because async is forcing the ic controller // to create a dummy todo with an ID of 1 TodoItem datItem1 = new TodoItem(); datItem1.ID = 2; datItem1.Name = "walk the dog"; datItem1.IsComplete = false; TodoItem datItem2 = new TodoItem(); datItem2.ID = 3; datItem2.Name = "wash the dishes"; datItem2.IsComplete = true; TodoController ic = new TodoController(context); // Act - note: create and delete need to be async // in order for the result value to display as null // for the deleted playlist var created1 = await ic.Create(datItem1); var created2 = await ic.Create(datItem2); var deletedItem = await ic.Delete(datItem1.ID); var result1 = ic.GetById(datItem1.ID); var result2 = ic.GetById(datItem2.ID); // Assert Assert.Null(result1.Result.Value); Assert.NotNull(result2); } }