public async Task Can_Remove_A_Todo_Item() { //Given var item = await Database.OnceAndSaveAsync(async db => { var item = new TodoItem { Name = "An Item" }; var collection = new Collection { Name = "A Collection" }; collection.TodoItems.Add(item); await db.Collections.AddAsync(collection); return(item); }); //When var isSucceed = await Database.OnceAsync(async db => { var repository = new TodoItemRepository(db); return(await repository.RemoveAsync(item)); }); //Then Assert.True(isSucceed); var isExists = await Database.OnceAsync(db => db.TodoItems.AnyAsync(i => i.Name.Equals(item.Name) || i.Id.Equals(item.Id))); Assert.False(isExists); }
public async Task <IActionResult> RemoveAsync(int id) { var item = await _repository.FindAsync(id); await _repository.RemoveAsync(item); return(new OkResult()); }