public async Task <IActionResult> RemoveAsync(int id) { var collection = await _repository.FindAsync(id); await _repository.RemoveAsync(collection); return(new OkResult()); }
public async Task Can_Remove_A_Collection() { //Given var toBeRemoved = await Database.OnceAndSaveAsync(async db => { var collections = new[] { new Collection { Name = "Collection1" }, new Collection { Name = "Collection2" }, new Collection { Name = "Collection3" }, }; await db.Collections.AddRangeAsync(collections); return(collections.First()); }); //When var isSucceed = await Database.OnceAsync(async db => { var repository = new CollectionRepository(db); return(await repository.RemoveAsync(toBeRemoved)); }); //Then Assert.True(isSucceed); var isExists = await Database.OnceAsync(async db => await db.Collections.AnyAsync(c => c.Name.Equals(toBeRemoved.Name))); Assert.False(isExists); }