public async Task CanDeleteReference() { GetInMemoryDb(out SqliteConnection connection, out DbContextOptions <ReferencesDbContext> options); using (var index = new Index(true, true)) { try { var id = Guid.NewGuid(); using (var context = new ReferencesDbContext(options)) { var service = new ReferencesController(context, index); var result = await service.Post(new Reference { Id = id }).ConfigureAwait(false); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ReferencesDbContext(options)) { var service = new ReferencesController(context, index); var result = await service.Get(id).ConfigureAwait(false); Assert.Equal(id, result.Value.Id); service.Delete(id); var all = await service.GetAll(0, 10).ConfigureAwait(false); Assert.Empty(all.ToArray()); } } finally { connection.Close(); } } }
public async Task CanDeleteReferenceAfterDeletingUsages() { GetInMemoryDb(out SqliteConnection connection, out DbContextOptions <ReferencesDbContext> options); using (var index = new Index(true, true)) { try { var id = Guid.NewGuid(); using (var context = new ReferencesDbContext(options)) { var service = new ReferencesController(context, index); var result = await service.Post(new Reference { Id = id, ReferenceUsage = new List <ReferenceUsage> { new ReferenceUsage { ApplicationId = 1, UserId = new Guid() } } }).ConfigureAwait(false); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ReferencesDbContext(options)) { var service = new ReferencesController(context, index); var result = await service.Get(id).ConfigureAwait(false); Assert.Equal(id, result.Value.Id); Assert.Throws <InvalidOperationException>(() => service.Delete(id)); var all = await service.GetAll(0, 10).ConfigureAwait(false); Assert.Single(all.ToArray()); } } finally { connection.Close(); } } }