public async Task DeleteAsyncThrowsException() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var db = new ApplicationDbContext(options.Options); var repository = new EfDeletableEntityRepository <Complaint>(db); var service = new ComplaintsService(repository); var result = await service.CreateAsync("1", "first complaint"); await service.DeleteAsync(result.Id); await Assert.ThrowsAnyAsync <Exception>(async() => await service.DeleteAsync(result.Id)); }
public async Task DeleteAsyncWorksCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var db = new ApplicationDbContext(options.Options); var repository = new EfDeletableEntityRepository <Complaint>(db); var service = new ComplaintsService(repository); var result = await service.CreateAsync("1", "first complaint"); await service.DeleteAsync(result.Id); var actualComplaintsCount = await repository.All().CountAsync(); Assert.Equal(0, actualComplaintsCount); }