public async void Delete_NonExistent_Item_ShouldReturnNotFound() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db6").Options); TodoController controller = new TodoController(_dbContext); var id = Guid.NewGuid(); var result = await controller.DeleteTodo(id); Assert.IsType <NotFoundResult>(result); }
public async Task DeleteItem() { var result = await ControllerUnderTest.DeleteTodo(2) as NoContentResult; Assert.IsNotNull(result); var shouldBeMissingItem = TodoContext.TodoItems.FirstOrDefault(i => i.Id == 2); Assert.IsNull(shouldBeMissingItem); }
public async void Delete_Item_ShouldSucceed() { var _dbContext = new TodoContext(new DbContextOptionsBuilder <TodoContext>().UseInMemoryDatabase("todo-db7").Options); TodoController controller = new TodoController(_dbContext); await controller.AddTodo(new TodoItem { Description = "Laundry", Date = DateTime.UtcNow }); var item = _dbContext.TodoItems.First(); var result = await controller.DeleteTodo(item.Id); Assert.IsType <OkResult>(result); }
public async Task Should_StatusCode404_WhenDeleteTodoIsNotExsist() { _mockRepo.Setup(repo => repo.Delete(GetTestTodo())); _mockRepo.Setup(repo => repo.SaveAll()).ReturnsAsync(true); var controller = new TodoController(_mockRepo.Object, _mockMapper.Object); var result = await controller.DeleteTodo("bad-id"); var notFoundResult = result as NotFoundResult; Assert.IsNotNull(notFoundResult); Assert.AreEqual(404, notFoundResult.StatusCode); }
public void DeleteTodo_Positive() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.DeleteTodo(1); //Assert Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public void DeleteTodo_Invalid_Request() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.DeleteTodo(0); //Assert //Assert.IsInstanceOf<BadRequestResult>(result); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public async Task DeleteTodo_WhenNotFound_Returns404() { // Arrange var todoServiceMock = new Mock <ITodoService>(); var todoController = new TodoController(todoServiceMock.Object); todoServiceMock .Setup(s => s.DeleteAsync(It.IsAny <int>())) .Returns(Task.FromResult(false)); // Act var result = await todoController.DeleteTodo(1); // Assert Assert.IsAssignableFrom <NotFoundResult>(result); }
public async Task DeleteTodo_Should_ReturnOk() { // Arrange var adapterMock = new Mock <ITodoAdapter>(); var loggerMock = new Mock <ILogger <TodoController> >(); var testTodoId = 2; var testTodos = GetTestTodos(); adapterMock.Setup(x => x.DeleteTodo(It.IsAny <int>())) .Callback(() => testTodos.Remove(testTodos.Where(x => x.TodoId == testTodoId).FirstOrDefault())); var controller = new TodoController(adapterMock.Object, loggerMock.Object); // Act var result = await controller.DeleteTodo(testTodoId); // Assert var actionResult = Assert.IsAssignableFrom <ActionResult <TodoViewModel> >(result); var returnValue = Assert.IsAssignableFrom <OkResult>(actionResult.Result); Assert.Single(testTodos); }