public void CanNotBulkPostReferencesWithIdenticalId() { GetInMemoryDb(out SqliteConnection connection, out DbContextOptions <ReferencesDbContext> options); using (var index = new Index(true, true)) { try { using (var context = new ReferencesDbContext(options)) { var id = Guid.NewGuid(); var service = new ReferencesController(context, index); Assert.Throws <InvalidOperationException>(() => service.PostMany(new[] { new Reference { Id = id, Summary = "Ref1" }, new Reference { Id = id, Summary = "Ref2" } })); } } finally { connection.Close(); } } }
public void CanPostBulkReferences() { GetInMemoryDb(out SqliteConnection connection, out DbContextOptions <ReferencesDbContext> options); using (var index = new Index(true, true)) { try { // Run the test against one instance of the context using (var context = new ReferencesDbContext(options)) { var service = new ReferencesController(context, index); var result = service.PostMany(new[] { new Reference { Summary = "Ref1" }, new Reference { Summary = "Ref2" } }); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ReferencesDbContext(options)) { Assert.Equal(1, context.Reference.Where(x => x.Summary == "Ref1").Count()); Assert.Equal(1, context.Reference.Where(x => x.Summary == "Ref2").Count()); } } finally { connection.Close(); } } }