public async Task GivenTodoItemNotExists_WhenDelete_ThenReturnNotFound() { using (var context = new TodoContext(_contextOptions)) { TodoItemsController controller = new TodoItemsController(context); var invalidId = context.TodoItems.Count() + 1; var deleteResult = await controller.DeleteTodoItem(invalidId); Assert.AreEqual(typeof(NotFoundResult), deleteResult.Result.GetType()); Assert.AreEqual(3, await context.TodoItems.CountAsync()); } }
public async Task GivenTodoItemExists_WhenDelete_ThenReturnDeletedItem() { using (var context = new TodoContext(_contextOptions)) { TodoItemsController controller = new TodoItemsController(context); int id = GetRandomId(context); var deleteResult = await controller.DeleteTodoItem(id); Assert.AreEqual(id, deleteResult.Value.Id); TodoItem freshFetched = await context.TodoItems.FirstOrDefaultAsync(t => t.Id == id); Assert.IsNull(freshFetched); Assert.AreEqual(2, await context.TodoItems.CountAsync()); } }