public void create_docs_with_global_id() { #region sample_configuring-global-hilo-defaults-sequencename var store = DocumentStore.For(_ => { _.Advanced.HiloSequenceDefaults.SequenceName = "Entity"; _.Connection(ConnectionSource.ConnectionString); _.DatabaseSchemaName = "sequences"; }); #endregion sample_configuring-global-hilo-defaults-sequencename using (var session = store.OpenSession()) { var doc1 = new IntDoc(); var doc2 = new Int2Doc(); var doc3 = new IntDoc(); var doc4 = new Int2Doc(); session.Store(doc1); session.Store(doc2); session.Store(doc3); session.Store(doc4); doc1.Id.ShouldBeGreaterThanOrEqualTo(1); doc2.Id.ShouldBe(doc1.Id + 1); doc3.Id.ShouldBe(doc2.Id + 1); doc4.Id.ShouldBe(doc3.Id + 1); } }
//[Fact] -- don't run this as part of the build public void try_to_make_hilo_fail() { var tasks = new Task[50]; for (var i = 0; i < tasks.Length; i++) { tasks[i] = Task.Factory.StartNew(() => { for (int j = 0; j < 50; j++) { using (var session = theStore.OpenSession()) { for (int k = 0; k < 50; k++) { var doc = new IntDoc(); session.Store(doc); } session.SaveChanges(); } } }); } Task.WaitAll(tasks, 5.Minutes()); }
public void create_docs_with_global_id() { // SAMPLE: configuring-global-hilo-defaults-sequencename var store = DocumentStore.For(_ => { _.HiloSequenceDefaults.SequenceName = "Entity"; _.Connection(ConnectionSource.ConnectionString); }); // ENDSAMPLE using (var session = store.OpenSession()) { var doc1 = new IntDoc(); var doc2 = new Int2Doc(); var doc3 = new IntDoc(); var doc4 = new Int2Doc(); session.Store(doc1); session.Store(doc2); session.Store(doc3); session.Store(doc4); doc1.Id.ShouldBeGreaterThanOrEqualTo(1); doc2.Id.ShouldBe(doc1.Id + 1); doc3.Id.ShouldBe(doc2.Id + 1); doc4.Id.ShouldBe(doc3.Id + 1); } }
public void does_indeed_assign_the_id_during_bulk_insert() { var docs = new IntDoc[50]; for (var i = 0; i < docs.Length; i++) { docs[i] = new IntDoc(); } theStore.BulkInsert(docs); using (var session = theStore.QuerySession()) { session.Query<IntDoc>().Count().ShouldBe(50); } }
public void persist_and_load() { var IntDoc = new IntDoc { Id = 456 }; theSession.Store(IntDoc); theSession.SaveChanges(); using (var session = theStore.OpenSession()) { SpecificationExtensions.ShouldNotBeNull(session.Load <IntDoc>(456)); SpecificationExtensions.ShouldBeNull(session.Load <IntDoc>(222)); } }
public void can_function_after_the_schema_is_in_place() { StoreOptions(_ => { _.AutoCreateSchemaObjects = AutoCreate.None; _.Schema.For <IntDoc>(); }); theStore.Schema.ApplyAllConfiguredChangesToDatabase(); using (var session = theStore.OpenSession()) { var doc = new IntDoc(); session.Store(doc); session.SaveChanges(); } }
public void can_establish_the_hilo_starting_point() { var store = DocumentStore.For(ConnectionSource.ConnectionString); store.Advanced.ResetHiloSequenceFloor <IntDoc>(2500); using (var session = store.OpenSession()) { var doc1 = new IntDoc(); var doc2 = new IntDoc(); var doc3 = new IntDoc(); session.Store(doc1, doc2, doc3); doc1.Id.ShouldBeGreaterThanOrEqualTo(2500); doc2.Id.ShouldBeGreaterThanOrEqualTo(2500); doc3.Id.ShouldBeGreaterThanOrEqualTo(2500); } }
public void persist_and_delete() { var IntDoc = new IntDoc { Id = 567 }; theSession.Store(IntDoc); theSession.SaveChanges(); using (var session = theStore.OpenSession()) { session.Delete <IntDoc>(IntDoc.Id); session.SaveChanges(); } using (var session = theStore.OpenSession()) { SpecificationExtensions.ShouldBeNull(session.Load <IntDoc>(IntDoc.Id)); } }
public void auto_assign_id_for_0_id() { var doc = new IntDoc { Id = 0 }; theSession.Store(doc); SpecificationExtensions.ShouldBeGreaterThan(doc.Id, 0); var doc2 = new IntDoc { Id = 0 }; theSession.Store(doc2); doc2.Id.ShouldNotBe(0); doc2.Id.ShouldNotBe(doc.Id); }
public void can_delete_by_query_with_complex_where_clauses() { var targets = Target.GenerateRandomData(50).ToArray(); for (var i = 0; i < 15; i++) { targets[i].Double = 578; } theStore.BulkInsert(targets); var current = new IntDoc { Id = 5 }; theSession.DeleteWhere <Target>(x => x.Double == 578 && x.Number == current.Id); theSession.SaveChanges(); theSession.Query <Target>().Where(x => x.Double == 578 && x.Number == current.Id).Count() .ShouldBe(0); }
public void can_establish_the_hilo_starting_point() { // SAMPLE: ResetHiloSequenceFloor var store = DocumentStore.For(ConnectionSource.ConnectionString); // Resets the minimum Id number for the IntDoc document // type to 2500 store.Advanced.ResetHiloSequenceFloor<IntDoc>(2500); // ENDSAMPLE using (var session = store.OpenSession()) { var doc1 = new IntDoc(); var doc2 = new IntDoc(); var doc3 = new IntDoc(); session.Store(doc1, doc2, doc3); doc1.Id.ShouldBeGreaterThanOrEqualTo(2500); doc2.Id.ShouldBeGreaterThanOrEqualTo(2500); doc3.Id.ShouldBeGreaterThanOrEqualTo(2500); } }