public void Submit_POCO_Insert5Cities() { CityDomainContext dc = new CityDomainContext(TestURIs.Cities); for (int i = 1; i <= 5; i++) { dc.Cities.Add(new City() { Name = "Redmond" + new string('x', i), CountyName = "King", StateName = "WA" }); } SubmitOperation so = dc.SubmitChanges(); EnqueueConditional(delegate { return(so.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void Submit_POCO_Insert5Simple() { TestProvider_Scenarios dc = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); for (int i = 0; i < 5; i++) { dc.POCONoValidations.Add(new POCONoValidation() { ID = i, A = "A" + i, B = "B" + i, C = "C" + i, D = "D" + i, E = "E" + i }); } SubmitOperation so = dc.SubmitChanges(); EnqueueConditional(delegate { return(so.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void JunkFile_RandomTest() { var maxAllowableTimeDifference = new TimeSpan(0, 0, 0, 1, 0); var tempFile = new FileInfo(Path.Combine(TempTestFileLocation.FullName, TestHelperMethods.RandomCharString(TestHelperMethods.GetRandomIntFromRange(2, 200)))); var size = TestHelperMethods.GetRandomIntFromRange(1, 1024 * 1024 * 1024); // Max 1 GB var blockSize = TestHelperMethods.GetRandomIntFromRange(1, size); var fillWithJunk = TestHelperMethods.GetRandomBool(); TestContext.WriteLine("Writing: {0}", tempFile); TestContext.WriteLine("Size: {0}", size); TestContext.WriteLine("Block size: {0}", size); TestContext.WriteLine("Fill with junk: {0}", fillWithJunk); var jf = new JunkFile(); var sw = new Stopwatch(); sw.Start(); var result = jf.Create(tempFile, size, blockSize, fillWithJunk, new CancellationTokenSource()); result.Wait(); sw.Stop(); TestContext.WriteLine("Reported time taken: {0}", result.Result); TestContext.WriteLine("Measured time taken: {0}", sw.Elapsed); // Confirm time taken is resonably accurate Assert.IsTrue(TestHelperMethods.TimeSpansAreSimilar(result.Result, sw.Elapsed, maxAllowableTimeDifference), "Timespans differ by too much!"); // Test file size is correct Assert.IsTrue(tempFile.Length == size, "Actual file size '{0}' differs from expected size '{1}'.", tempFile.Length, size); File.Delete(tempFile.FullName); }
public void JunkFile_MaxFileSizeTest() { var maxAllowableTimeDifference = new TimeSpan(0, 0, 0, 1, 0); var tempFile = new FileInfo(Path.Combine(TempTestFileLocation.FullName, TestHelperMethods.RandomCharString(TestHelperMethods.GetRandomIntFromRange(2, 200)))); var fillWithJunk = TestHelperMethods.GetRandomBool(); TestContext.WriteLine("Writing: {0}", tempFile); TestContext.WriteLine("Fill with junk: {0}", fillWithJunk); var jf = new JunkFile(); var cs = new CancellationTokenSource(); var sw = new Stopwatch(); sw.Start(); var result = jf.Create(tempFile, long.MaxValue, 1024, fillWithJunk, cs); result.Wait(5000); cs.Cancel(); result.Wait(); sw.Stop(); // Confirm time taken is appropriate Assert.IsTrue(TestHelperMethods.TimeSpansAreSimilar(result.Result, sw.Elapsed, maxAllowableTimeDifference), "Timespans differ by too much!"); File.Delete(tempFile.FullName); }
public void Composition_Inheritance_HierarchyQuery() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); // 3 parents, each with 4 children Assert.AreEqual(15, lo.AllEntities.Count(), "Unexpected number of entities in hierarchy"); Assert.AreEqual(3, ctxt.CI_Parents.Count, "Expected this many total parent entities"); foreach (CI_Parent p in ctxt.CI_Parents) { VerifyHierarchy(p); IEnumerable <CI_Child> baseChildren = p.Children.Where(c => c.GetType() == typeof(CI_Child)); Assert.AreEqual(2, baseChildren.Count(), "Wrong number of child entities"); IEnumerable <CI_AdoptedChild> adoptedChildren = p.Children.OfType <CI_AdoptedChild>(); Assert.AreEqual(2, adoptedChildren.Count(), "Wrong number of adopted child entities"); } }); EnqueueTestComplete(); }
private string SetupRaiseCredit(decimal credit) { // arrange Action action = () => controlUnit.State.RaiseCredit(credit); // act return(TestHelperMethods.CaptureConsoleOutput(action)); }
private string SetupSelectProduct(Coordinates coords, decimal?credit) { // arrange ConditionallyAssignCredit(credit); Action action = () => controlUnit.State.SelectProduct(coords); // act return(TestHelperMethods.CaptureConsoleOutput(action)); }
private string SetupTryDeliverStock(Coordinates?coords, decimal?credit) { // arrange ConditionallyAssignCredit(credit); if (coords.HasValue) { controlUnit.State.SelectProduct(coords.Value); } Action action = () => controlUnit.State.TryDeliverProduct(); // act return(TestHelperMethods.CaptureConsoleOutput(action)); }
/// <summary> /// Verify successful completion of an update operation /// </summary> private void VerifySuccess(CompositionInheritanceScenarios ctxt, SubmitOperation so, IEnumerable <Entity> expectedUpdates) { // verify operation completed successfully TestHelperMethods.AssertOperationSuccess(so); // verify that all operations were executed EntityChangeSet cs = so.ChangeSet; VerifyOperationResults(cs.AddedEntities, expectedUpdates); // verify that all changes have been accepted cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.IsEmpty); }
public void TEST_no_caching() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(5); for (int i = 0; i < 100; i++) { StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); History.LoadAll(true).ToList().ForEach( x => { History.Delete(x.Id); History.DeleteForever(x.Id); }); IEnumerable <Finance <object> > allx = fin.LoadAll(true); Finance <object> data = fin.Create(new Finance <object>()); IEnumerable <Finance <object> > allk = fin.LoadAll(true); IEnumerable <Finance <object> > allhhjjw = fin.LoadAll(true); data.FileContent = "bla"; IEnumerable <Finance <object> > allhhw = fin.LoadAll(true); fin.Update(data); IEnumerable <Finance <object> > allw = fin.LoadAll(true); History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id); data = fin.Load(data.Id); IEnumerable <Finance <object> > ally = fin.LoadAll(true); TestHelperMethods.AssertAwait( () => { IEnumerable <Finance <object> > all = fin.LoadAll(true); Assert.AreEqual(1, all.Count()); }); fin.Delete(data.Id); h = History.Load(History.LoadAll(true).Last().Id); DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); fin.DeleteForever(data.Id); h = History.Load(History.LoadAll(true).LastOrDefault().Id); stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); } }
public void InvokeOperation_ReturnsEntityCollection() { TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); InvokeOperation invoke = provider.ReturnsEntityCollection_Online(3, TestHelperMethods.DefaultOperationAction, null); EnqueueConditional(() => invoke.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(invoke); IEnumerable <MixedType> mts = invoke.Value as IEnumerable <MixedType>; Assert.AreEqual(3, mts.Count()); }); EnqueueTestComplete(); }
public void Query_POCO_AllCities() { CityDomainContext dc = new CityDomainContext(TestURIs.Cities); var query = dc.GetCitiesQuery(); LoadOperation lo = dc.Load(query, false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() > 0); }); EnqueueTestComplete(); }
public void Query_Take50Products() { Catalog catalog = CreateDomainContext(); var query = catalog.GetProductsQuery().OrderBy(p => p.Name).Take(50); LoadOperation lo = catalog.Load(query, false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() == 50); }); EnqueueTestComplete(); }
public void Invoke_RoundtripString() { TestProvider_Scenarios dc = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); string str = "Hello, World!"; InvokeOperation <string> io = dc.ReturnsString_Online(str); this.EnqueueCompletion(() => io); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(io); Assert.AreEqual(str, io.Value); }); EnqueueTestComplete(); }
public void dynamic_test() { new List <bool> { true, false }.ForEach( cache => { var store = new PecanDocumentStore("PecanDBTest", new DatabaseOptions(cache)); ISession session = store.OpenSession(); foreach (int i1 in Enumerable.Range(0, 10)) { string orderId = session.Save( new { Id = "yo be", Name = i1 }); string orderId2 = session.Save( new object()); dynamic order = null; TestHelperMethods.AssertAwait( () => { order = session.Load <dynamic>(orderId); Assert.AreEqual(order.Name.ToString(), i1.ToString()); Order oo = session.LoadAs <dynamic, Order>(orderId); Assert.AreEqual(oo.Name, i1.ToString()); Order oo2 = session.LoadAs <dynamic, Order>(orderId2); var oo3 = session.LoadAs <Order>(orderId2); dynamic oo4 = session.Load(orderId2); }); order.Name = "sam"; session.SaveChanges(true); var o = session.Load <object>(orderId); dynamic order2 = o; Assert.AreEqual(order2.Name.ToString(), "sam"); order2.Name = "sowhat"; Assert.AreEqual(order2.Name.ToString(), order.Name.ToString()); List <dynamic> result = session.Query <object>(all => from every in all select every).ToList(); } }); }
public void JunkFile_1ByteTest() { var tempFile = new FileInfo(Path.Combine(TempTestFileLocation.FullName, TestHelperMethods.RandomCharString(TestHelperMethods.GetRandomIntFromRange(2, 200)))); var fillWithJunk = TestHelperMethods.GetRandomBool(); TestContext.WriteLine("Writing: {0}", tempFile); TestContext.WriteLine("Fill with junk: {0}", fillWithJunk); var jf = new JunkFile(); var result = jf.Create(tempFile, 1, 1, fillWithJunk, new CancellationTokenSource()); result.Wait(); Assert.IsTrue(tempFile.Length == 1, "Actual file size '{0}' differs from expected size '{1}'.", tempFile.Length, 1); File.Delete(tempFile.FullName); }
public void InvokeOperation_ReturnsEntity() { TestProvider_Scenarios provider = new TestProvider_Scenarios(TestURIs.TestProvider_Scenarios); MixedType mt = new MixedType(); InvokeOperation invoke = provider.ReturnsEntity_Online(mt, "MixedType_Other", TestHelperMethods.DefaultOperationAction, null); EnqueueConditional(() => invoke.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(invoke); mt = invoke.Value as MixedType; Assert.IsNotNull(mt); Assert.AreEqual("MixedType_Other", mt.ID); }); EnqueueTestComplete(); }
public void Query_POCO_NoResults() { CityDomainContext dc = new CityDomainContext(TestURIs.Cities); var query = dc.GetCitiesQuery().Where(c => c.Name == "-"); LoadOperation lo = dc.Load(query, false); EnqueueConditional(delegate { return(lo.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() == 0); }); EnqueueTestComplete(); }
public void Query_NoResults() { Catalog catalog = CreateDomainContext(); var query = catalog.GetProductsQuery().Where(p => p.ProductID < 0); LoadOperation lo = catalog.Load(query, false); EnqueueConditional(delegate { return(lo.IsComplete); }); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); Assert.IsTrue(lo.Entities.Count() == 0); }); EnqueueTestComplete(); }
public void Composition_Inheritance_Add_Derived_Child_To_Derived_Parent() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); CI_SpecialParent parent = null; SubmitOperation so = null; IEnumerable <Entity> expectedUpdates = null; LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); EnqueueConditional(() => lo.IsComplete); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); parent = ctxt.CI_Parents.OfType <CI_SpecialParent>().First(); CI_AdoptedChild newChild = new CI_AdoptedChild() { Age = 5, }; parent.Children.Add(newChild); Assert.AreSame(parent, ((Entity)newChild).Parent); EntityChangeSet cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Count == 1, "wrong modified count"); Assert.IsTrue(cs.AddedEntities.Count == 1, "wrong added count"); Assert.IsTrue(cs.RemovedEntities.Count == 0, "wrong removed count"); Assert.IsTrue(cs.ModifiedEntities.Contains(parent)); Assert.IsTrue(cs.AddedEntities.Contains(newChild)); // verify that original associations are set up correctly IEnumerable <ChangeSetEntry> entityOps = ChangeSetBuilder.Build(cs); this.ValidateEntityOperationAssociations(entityOps); expectedUpdates = cs.Where(p => p.HasChildChanges || p.HasPropertyChanges).ToArray(); so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); EnqueueConditional(() => so.IsComplete); EnqueueCallback(delegate { this.VerifySuccess(ctxt, so, expectedUpdates); }); EnqueueTestComplete(); }
public void Association_Inheritance_Modify_MultipleValue_Derived_Association() { AssociationInheritanceScenarios ctxt = new AssociationInheritanceScenarios(AssociationInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetMastersQuery(), false); SubmitOperation so = null; this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); AI_MasterDerived master = ctxt.AI_Masters.OfType <AI_MasterDerived>().FirstOrDefault(); Assert.IsNotNull(master, "expected 1 master"); // Verify we can remove one derived from the list AI_DetailDerived1 d1 = master.DetailDerived1s.First(); master.DetailDerived1s.Remove(d1); Assert.AreEqual(1, master.DetailDerived1s.Count, "master.D1s.Remove didn't work"); AI_DetailDerived1 newD1 = new AI_DetailDerived1(); newD1.ID = 9999; master.DetailDerived1s.Add(newD1); Assert.AreEqual(2, master.DetailDerived1s.Count, "master.D1s.Add didn't work"); AI_DetailDerived2 newD2 = new AI_DetailDerived2(); newD2.ID = 99999; master.DetailDerived2s.Add(newD2); Assert.AreEqual(3, master.DetailDerived2s.Count, "master.D2s.Add didn't work"); so = ctxt.SubmitChanges(); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void Association_Inheritance_HierarchyQuery() { AssociationInheritanceScenarios ctxt = new AssociationInheritanceScenarios(AssociationInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetMastersQuery(), false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); // Master, 2 D1's, 2 D2's, 1 D3 and 1 D4 Assert.AreEqual(7, lo.AllEntities.Count(), "Unexpected number of entities in hierarchy"); AI_MasterDerived master = ctxt.AI_Masters.OfType <AI_MasterDerived>().FirstOrDefault(); Assert.IsNotNull(master, "expected 1 master"); // Confirm the single-value relations AI_DetailDerived3 d3 = master.DetailDerived3; Assert.IsNotNull(d3, "no master.D3"); Assert.AreSame(master, d3.Master, "wrong master.D3"); AI_DetailDerived4 d4 = master.DetailDerived4; Assert.IsNotNull(d4, "no master.D4"); Assert.AreSame(master, d4.Master, "wrong master.D4"); // Confirm the multi-value relations Assert.AreEqual(2, master.DetailDerived1s.Count, "wrong number of D1's"); Assert.AreEqual(2, master.DetailDerived2s.Count, "wrong number of D2's"); foreach (AI_DetailDerived1 d1 in master.DetailDerived1s) { Assert.AreSame(master, d1.Master, "D1.Master not root master"); } foreach (AI_DetailDerived2 d2 in master.DetailDerived2s) { Assert.AreSame(master, d2.Master, "D1.Master not root master"); } }); EnqueueTestComplete(); }
public void Composition_Inheritance_Update_Base_Child_On_Base_Parent() { CompositionInheritanceScenarios ctxt = new CompositionInheritanceScenarios(CompositionInheritanceScenarios_Uri); CI_Parent parent = null; SubmitOperation so = null; IEnumerable <Entity> expectedUpdates = null; LoadOperation lo = ctxt.Load(ctxt.GetParentsQuery(), false); this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); parent = ctxt.CI_Parents.First(p => p.GetType() == typeof(CI_Parent)); CI_Child existingChild = parent.Children.First(c => c.GetType() == typeof(CI_Child)); Assert.AreSame(parent, ((Entity)existingChild).Parent); // update derived comp child existingChild.Age++;; EntityChangeSet cs = ctxt.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Count == 2, "wrong modified count"); Assert.IsTrue(cs.RemovedEntities.Count == 0, "wrong removed count"); Assert.IsTrue(cs.ModifiedEntities.Contains(parent)); Assert.IsTrue(cs.ModifiedEntities.Contains(existingChild)); // verify that original associations are set up correctly IEnumerable <ChangeSetEntry> entityOps = ChangeSetBuilder.Build(cs); this.ValidateEntityOperationAssociations(entityOps); expectedUpdates = cs.Where(p => p.HasChildChanges || p.HasPropertyChanges).ToArray(); so = ctxt.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { this.VerifySuccess(ctxt, so, expectedUpdates); }); EnqueueTestComplete(); }
public void Association_Inheritance_Modify_Singleton_Derived_Association() { AssociationInheritanceScenarios ctxt = new AssociationInheritanceScenarios(AssociationInheritanceScenarios_Uri); LoadOperation lo = ctxt.Load(ctxt.GetMastersQuery(), false); SubmitOperation so = null; this.EnqueueCompletion(() => lo); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(lo); AI_MasterDerived master = ctxt.AI_Masters.OfType <AI_MasterDerived>().FirstOrDefault(); Assert.IsNotNull(master, "expected one master"); AI_DetailDerived3 d3 = master.DetailDerived3; Assert.IsNotNull(d3, "no master.D3"); Assert.AreSame(master, d3.Master, "wrong master.D3"); // Verify we can unset it master.DetailDerived3 = null; Assert.IsNull(master.DetailDerived3, "could not reset master.D4"); AI_DetailDerived3 newD3 = new AI_DetailDerived3(); newD3.ID = 99; master.DetailDerived3 = newD3; AI_DetailDerived4 newD4 = new AI_DetailDerived4(); newD4.ID = 999; master.DetailDerived4 = newD4; so = ctxt.SubmitChanges(); }); this.EnqueueCompletion(() => so); EnqueueCallback(delegate { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void load_test_with_nocaching() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(3); StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach(x => fin.DeleteForever(x.Id)); History.LoadAll(true).ToList().ForEach(x => History.DeleteForever(x.Id)); int count = 1000; for (int i = 0; i < count; i++) { fin.Create(new Finance <object>()); } fin.Create(new Finance <object>(), true); TestHelperMethods.AssertAwait( () => { int ttt = fin.LoadAll(true).Count(); Assert.AreEqual(count + 1, ttt); }); List <Finance <object> > x1 = fin.LoadAll(true).Take(10).ToList(); List <Finance <object> > x2 = fin.LoadAll(true).Take(1000).ToList(); List <Finance <object> > x3 = fin.LoadAll(true).Take(1000).ToList(); IEnumerable <Finance <object> > tester = fin.LoadAll( finances => from finance in finances where finance.ETag != null select finance); fin.LoadAll(true).ToList().ForEach(x => fin.DeleteForever(x.Id)); History.LoadAll(true).ToList().ForEach(x => History.DeleteForever(x.Id)); //(3000); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); }
public void TEST_with_caching_inmemory() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); for (int i = 0; i < 100; i++) { DatabaseService.DataBaseSettings.EnableFasterCachingButWithLeakyUpdates = true; StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); History.LoadAll(true).ToList().ForEach( x => { History.Delete(x.Id); History.DeleteForever(x.Id); }); Finance <object> data = fin.Create(new Finance <object>()); data.FileContent = "bla"; fin.Update(data); History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id); data = fin.Load(data.Id); TestHelperMethods.AssertAwait(() => Assert.AreEqual(1, fin.LoadAll(true).Count())); fin.Delete(data.Id); h = History.Load(History.LoadAll(true).Last().Id); DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); fin.DeleteForever(data.Id); h = History.Load(History.LoadAll(true).LastOrDefault().Id); stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); } }
public void Cities_LoadStates_TestEnums() { CityDomainContext dp = new CityDomainContext(TestURIs.Cities); SubmitOperation so = null; LoadOperation lo = dp.Load(dp.GetStatesQuery().Where(s => s.TimeZone == Cities.TimeZone.Pacific), false); this.EnqueueCompletion(() => lo); EnqueueCallback(() => { if (lo.Error != null) { Assert.Fail("LoadOperation.Error: " + lo.Error.Message); } // verify the TimeZones were serialized to the client properly State state = dp.States.Single(p => p.Name == "WA"); Assert.AreEqual(Cities.TimeZone.Pacific, state.TimeZone); Assert.IsFalse(dp.States.Any(p => p.Name == "OH")); // Now test update state.TimeZone = state.TimeZone = Cities.TimeZone.Central; Assert.AreEqual(EntityState.Modified, state.EntityState); EntityChangeSet cs = dp.EntityContainer.GetChanges(); Assert.IsTrue(cs.ModifiedEntities.Contains(state)); so = dp.SubmitChanges(TestHelperMethods.DefaultOperationAction, null); }); this.EnqueueCompletion(() => so); EnqueueCallback(() => { TestHelperMethods.AssertOperationSuccess(so); }); EnqueueTestComplete(); }
public void test_saving_into_different_directories_with_query_document() { dynamic data1 = new { Data = Guid.NewGuid().ToString() }; dynamic data2 = new { Data = Guid.NewGuid().ToString() }; dynamic data3 = new { Data = Guid.NewGuid().ToString() }; string t1 = "t1t1t1"; string t2 = "t2t2t2"; using (var store = new DocumentStoreInMemory( new DatabaseOptions { //MaxResponseTime = TimeSpan.FromMinutes(3), // EnableCaching = false })) { //using (ISession session = store.OpenSession()) //{ // foreach (PecanDocument<dynamic> order in session.QueryDocument<dynamic>(orders => from order in orders select order)) // session.DeleteForever<dynamic>(order.Id); // foreach (PecanDocument<dynamic> order in session.QueryDocument<dynamic>(orders => from order in orders select order,t1)) // session.DeleteForever<dynamic>(order.Id); // foreach (PecanDocument<dynamic> order in session.QueryDocument<dynamic>(orders => from order in orders select order,t2)) // session.DeleteForever<dynamic>(order.Id); //} string h1; using (ISession session = store.OpenSession()) { h1 = session.Save(data1); } string h2; using (ISession session = store.OpenSession()) { h2 = session.Save(t1, data2); } string h3; using (ISession session = store.OpenSession()) { h3 = session.Save(t2, data3); } using (ISession session = store.OpenSession()) { TestHelperMethods.AssertAwait( () => { var h1data = session.Load <dynamic>(h1); var list1 = session.QueryDocument <dynamic>((docs) => docs.Select(doc => doc)).Select(x => JsonConvert.SerializeObject(x)).ToList(); Assert.AreEqual(data1.Data.ToString(), h1data.Data.ToString()); Assert.AreEqual(list1.Count, 1); }); } using (ISession session = store.OpenSession()) { TestHelperMethods.AssertAwait( () => { var h2data = session.Load <dynamic>(h2, t1); var list2 = session.QueryDocument <dynamic>((docs) => docs.Select(doc => doc), t1).Select(x => JsonConvert.SerializeObject(x)).ToList(); Assert.AreEqual(data2.Data.ToString(), h2data.Data.ToString()); Assert.AreEqual(list2.Count, 1); }); } using (ISession session = store.OpenSession()) { TestHelperMethods.AssertAwait( () => { var h3data = session.Load <dynamic>(h3, t2); var list3 = session.QueryDocument <dynamic>((docs) => docs.Select(doc => doc), t2).Select(x => JsonConvert.SerializeObject(x)).ToList(); Assert.AreEqual(data3.Data.ToString(), h3data.Data.ToString()); Assert.AreEqual(list3.Count, 1); }); } } }
public void transaction() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(10); StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); int total = 100; Task.Run( () => { DatabaseService.Transaction( handle => { for (int i = 0; i < total; i++) { Finance <object> ti = handle.GetDBRef <Finance <object>, object>().Create(new Finance <object>()); } return(true); }); }); IEnumerable <Finance <object> > t = fin.LoadAll(true); TestHelperMethods.AssertAwait(1000); fin.Create(new Finance <object>()); //(3000); Assert.AreEqual(total + 1, fin.LoadAll(true).Count()); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); Assert.AreEqual(0, fin.LoadAll(true).Count()); Task task = Task.Run( () => { for (int i = 0; i < total; i++) { Finance <object> ti = fin.Create(new Finance <object>()); } }); IEnumerable <Finance <object> > ttt = fin.LoadAll(true); TestHelperMethods.AssertAwait(1000); fin.Create(new Finance <object>()); // Assert.AreNotEqual(total + 1, fin.LoadAll(true).Count()); task.Wait(); //(3000); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); Assert.AreEqual(0, fin.LoadAll(true).Count()); StorageDatabase <History <object>, object> his = DatabaseService.Documents <History <object>, object>(); his.LoadAll(true).ToList().ForEach( x => { his.Delete(x.Id); his.DeleteForever(x.Id); }); }
public void RunPerformanceTest <T>(bool isParallel, string description, Func <int, ISession, Action> opearation) { new List <bool> { true, false }.ForEach( dontWaitForWritesOnCreate => { for (int j = 0; j < this.numberOfSamples; j++) { var store = new PecanDocumentStore( "PecanDB", false, new DatabaseOptions { EnableCaching = false, DontWaitForWritesOnCreate = dontWaitForWritesOnCreate }); ISession session = store.OpenSession(); try { foreach (PecanDocument <T> order in session.QueryDocument <T>(orders => from order in orders select order)) { session.DeleteForever <T>(order.Id); } } catch (Exception e) { } // Create new stopwatch var stopwatch = new Stopwatch(); var validationOperations = new ConcurrentQueue <Action>(); // Begin timing stopwatch.Start(); if (isParallel) { Parallel.For(1, this.total, i => validationOperations.Enqueue(opearation(i, session))); } else { foreach (int i in Enumerable.Range(0, this.total)) { validationOperations.Enqueue(opearation(i, session)); } } // Stop timing stopwatch.Stop(); Console.Write($"{j} {(dontWaitForWritesOnCreate ? "" : "DONT WAIT FOR CREATE")} - Time elapsed: {stopwatch.Elapsed.TotalMilliseconds}ms : {description} with {this.total} iteration - RATE {this.total / (stopwatch.Elapsed.TotalMilliseconds / 1000)} op/sec"); var validationStopwatch = new Stopwatch(); validationStopwatch.Start(); Action validationOperation; while (validationOperations.TryDequeue(out validationOperation)) { if (validationOperation != null) { TestHelperMethods.AssertAwait(validationOperation); } } validationStopwatch.Stop(); Console.WriteLine($"VALIDATION TIMING elapsed: {validationStopwatch.Elapsed.TotalMilliseconds}ms "); try { foreach (PecanDocument <T> order in session.QueryDocument <T>(orders => from order in orders select order)) { session.DeleteForever <T>(order.Id); } } catch (Exception) { } } }); }