public void TestInit() { _engine = Factory.NewEngine(); _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<NullableDatabase>( TestContext.TestName, GetDriver() ); _databaseInstance.PurgeAsync().Wait(); }
public void TestInit() { _engine = Factory.NewEngine(); _engine.SterlingDatabase.RegisterSerializer<TestCompositeSerializer>(); _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstanceComposite>( TestContext.TestName, GetDriver() ); _databaseInstance.PurgeAsync().Wait(); }
public void TestCleanup() { _databaseInstance.PurgeAsync().Wait(); _engine.Dispose(); _databaseInstance = null; }
public override void Cleanup() { _databaseInstance.PurgeAsync().Wait(); _engine.Dispose(); _databaseInstance = null; }
public void TestBackupAndRestore() { var driver = GetDriver(); // activate the engine and store the data _engine = Factory.NewEngine(); _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>( TestContext.TestName, driver); // test saving and reloading var expected = TestModel.MakeTestModel(); _databaseInstance.SaveAsync(expected).Wait(); // now back it up var memStream = new MemoryStream(); byte[] databaseBuffer; using (var binaryWriter = new BinaryWriter(memStream)) { _engine.SterlingDatabase.BackupAsync<TestDatabaseInstance>(binaryWriter).Wait(); binaryWriter.Flush(); databaseBuffer = memStream.ToArray(); } // now purge the database _databaseInstance.PurgeAsync().Wait(); var actual = _databaseInstance.LoadAsync<TestModel>( expected.Key ).Result; // confirm the database is gone Assert.IsNull(actual, "Purge failed, was able to load the test model."); _databaseInstance = null; // shut it all down _engine.Dispose(); _engine = null; // get a new engine _engine = Factory.NewEngine(); // activate it and grab the database again _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>(TestContext.TestName, driver); // restore it _engine.SterlingDatabase.RestoreAsync<TestDatabaseInstance>(new BinaryReader(new MemoryStream(databaseBuffer))).Wait(); _engine.Dispose(); _engine = null; // get a new engine _engine = Factory.NewEngine(); // activate it and grab the database again _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>(TestContext.TestName, driver); actual = _databaseInstance.LoadAsync<TestModel>(expected.Key).Result; Assert.IsNotNull(actual, "Load failed."); Assert.AreEqual(expected.Key, actual.Key, "Load failed: key mismatch."); Assert.AreEqual(expected.Data, actual.Data, "Load failed: data mismatch."); Assert.IsNull(actual.Data2, "Load failed: suppressed data property not valid on de-serialize."); Assert.IsNotNull(actual.SubClass, "Load failed: sub class is null."); Assert.IsNull(actual.SubClass2, "Load failed: supressed sub class should be null."); Assert.AreEqual(expected.SubClass.NestedText, actual.SubClass.NestedText, "Load failed: sub class text mismtach."); Assert.AreEqual(expected.SubStruct.NestedId, actual.SubStruct.NestedId, "Load failed: sub struct id mismtach."); Assert.AreEqual(expected.SubStruct.NestedString, actual.SubStruct.NestedString, "Load failed: sub class string mismtach."); }
public void TestBackupAndRestore() { var driver = GetDriver(); // activate the engine and store the data _engine = Factory.NewEngine(); _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase <TestDatabaseInstance>(TestContext.TestName, driver); // test saving and reloading var expected = TestModel.MakeTestModel(); _databaseInstance.SaveAsync(expected).Wait(); // now back it up var memStream = new MemoryStream(); byte[] databaseBuffer; using (var binaryWriter = new BinaryWriter(memStream)) { _engine.SterlingDatabase.BackupAsync <TestDatabaseInstance>(binaryWriter).Wait(); binaryWriter.Flush(); databaseBuffer = memStream.ToArray(); } // now purge the database _databaseInstance.PurgeAsync().Wait(); var actual = _databaseInstance.LoadAsync <TestModel>(expected.Key).Result; // confirm the database is gone Assert.IsNull(actual, "Purge failed, was able to load the test model."); _databaseInstance = null; // shut it all down _engine.Dispose(); _engine = null; // get a new engine _engine = Factory.NewEngine(); // activate it and grab the database again _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase <TestDatabaseInstance>(TestContext.TestName, driver); // restore it _engine.SterlingDatabase.RestoreAsync <TestDatabaseInstance>(new BinaryReader(new MemoryStream(databaseBuffer))).Wait(); _engine.Dispose(); _engine = null; // get a new engine _engine = Factory.NewEngine(); // activate it and grab the database again _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase <TestDatabaseInstance>(TestContext.TestName, driver); actual = _databaseInstance.LoadAsync <TestModel>(expected.Key).Result; Assert.IsNotNull(actual, "Load failed."); Assert.AreEqual(expected.Key, actual.Key, "Load failed: key mismatch."); Assert.AreEqual(expected.Data, actual.Data, "Load failed: data mismatch."); Assert.IsNull(actual.Data2, "Load failed: suppressed data property not valid on de-serialize."); Assert.IsNotNull(actual.SubClass, "Load failed: sub class is null."); Assert.IsNull(actual.SubClass2, "Load failed: supressed sub class should be null."); Assert.AreEqual(expected.SubClass.NestedText, actual.SubClass.NestedText, "Load failed: sub class text mismtach."); Assert.AreEqual(expected.SubStruct.NestedId, actual.SubStruct.NestedId, "Load failed: sub struct id mismtach."); Assert.AreEqual(expected.SubStruct.NestedString, actual.SubStruct.NestedString, "Load failed: sub class string mismtach."); }
public void TestInit() { _engine = Factory.NewEngine(); _engine.Activate(); _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<DirtyDatabase>( TestContext.TestName, GetDriver() ); ( (DirtyDatabase) _databaseInstance ).Predicate = model => true; _databaseInstance.PurgeAsync().Wait(); }
public void TestAddBill() { _database.PurgeAsync().Wait(); var bill = new Bill { Id = Guid.NewGuid(), Name = "Test" }; _database.SaveAsync(bill).Wait(); var person1 = new Person { Id = Guid.NewGuid(), Name = "Martin" }; _database.SaveAsync(person1).Wait(); var partaker1 = new Partaker { Id = Guid.NewGuid(), Paid = 42, Person = person1 }; bill.Partakers.Add(partaker1); _database.SaveAsync(bill).Wait(); var person2 = new Person { Id = Guid.NewGuid(), Name = "Jeremy" }; _database.SaveAsync(person2).Wait(); var partaker2 = new Partaker { Id = Guid.NewGuid(), Paid = 0, Person = person2 }; bill.Partakers.Add(partaker2); _database.SaveAsync(bill).Wait(); var partaker3 = new Partaker() { Id = Guid.NewGuid(), Paid = 1, Person = person1 }; bill.Partakers.Add(partaker3); _database.SaveAsync(bill).Wait(); _database.FlushAsync().Wait(); var billKeys = _database.Query <Bill, Guid>(); Assert.IsTrue(billKeys.Count == 1); Assert.AreEqual(billKeys[0].Key, bill.Id); var freshBill = billKeys[0].LazyValue.Value; Assert.IsTrue(freshBill.Partakers.Count == 3, "Bill should have exactly 3 partakers."); var personKeys = _database.Query <Person, Guid>(); Assert.IsTrue(personKeys.Count == 2, "Failed to save exactly 2 persons."); // Compare loaded instances and verify they are equal var persons = (from p in freshBill.Partakers where p.Person.Id.Equals(person1.Id) select p.Person).ToList(); // should be two of these Assert.AreEqual(2, persons.Count, "Failed to grab two instances of the same person."); Assert.AreEqual(persons[0], persons[1], "Instances were not equal."); }