public async Task CanPostReference() { 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); var count = (await service.GetCount().ConfigureAwait(false)).Value; Assert.Equal(1, count); var all = await service.GetAll(0, 10).ConfigureAwait(false); Assert.Single(all.ToArray()); } } finally { connection.Close(); } } }