Example #1
0
 public void TestInit()
 {
     _engine = Factory.NewEngine();
     _engine.SterlingDatabase.RegisterSerializer<TestSerializer>();
     _engine.Activate();
     _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>( TestContext.TestName, GetDriver() );
 }
Example #2
0
 public void TestInit()
 {            
     _engine = Factory.NewEngine();
     _engine.Activate();
     _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<NullableDatabase>( TestContext.TestName, GetDriver() );
     _databaseInstance.PurgeAsync().Wait();
 }
 public static ISterlingDatabaseInstance CreateDatabase()
 {
     var engine = new SterlingEngine(new SterlingPlatformAdapter());
     engine.SterlingDatabase.RegisterSerializer<SterlingContentSerializer>();
     engine.Activate();
     return engine.SterlingDatabase.RegisterDatabase<ContentStoreDB>("TestDB", new MemoryDriver());
 }
Example #4
0
 public void TestInit()
 {
     _engine = Factory.NewEngine();
     _engine.Activate();
     _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<DirtyDatabase>( TestContext.TestName, GetDriver() );
     ( (DirtyDatabase) _databaseInstance ).Predicate = model => true;
     _databaseInstance.PurgeAsync().Wait();
 }
Example #5
0
 public void TestInit()
 {
     _engine = Factory.NewEngine();
     _engine.Activate();
     _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>( TestContext.TestName, GetDriver() );
     _modelList = new List<TestModel>();
     for (var i = 0; i < 10; i++)
     {
         _modelList.Add(TestModel.MakeTestModel());
         _databaseInstance.SaveAsync(_modelList[i]).Wait();
     }
 }
Example #6
0
 public void TestInit()
 {
     //_startTime = DateTime.Now;
     _engine = Factory.NewEngine();
     _engine.Activate();
     _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>( "async" );
     _modelList = new List<TestModel>();
     for (var i = 0; i < MODELS; i++)
     {
         _modelList.Add(TestModel.MakeTestModel());
     }
 }
 public void Init()
 {
     _engine = Factory.NewEngine();
     _engine.Activate();
     _database = _engine.SterlingDatabase.RegisterDatabase<NestedInstancesDatabase>(TestContext.TestName, GetDriver());
 }
Example #8
0
        public void TestSaveShutdownReInitialize()
        {
            _databaseInstance.PurgeAsync().Wait();

            // test saving and reloading
            var expected1 = TestModel.MakeTestModel();
            var expected2 = TestModel.MakeTestModel();

            expected2.GuidNullable = null;

            var expectedComplex = new TestComplexModel
                                      {
                                          Id = 5,
                                          Dict = new Dictionary<string, string>(),
                                          Models = new ObservableCollection<TestModel>()
                                      };
            for (var x = 0; x < 10; x++)
            {
                expectedComplex.Dict.Add(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                expectedComplex.Models.Add(TestModel.MakeTestModel());
            }

            _databaseInstance.SaveAsync( expected1 ).Wait();
            _databaseInstance.SaveAsync( expected2 ).Wait();
            _databaseInstance.SaveAsync( expectedComplex ).Wait();

            _databaseInstance.FlushAsync().Wait();
            
            // shut it down

            _engine.Dispose();
            var driver = _databaseInstance.Driver; 
            _databaseInstance = null;

            // bring it back up
            _engine = Factory.NewEngine();
            _engine.Activate();
            _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>(TestContext.TestName, driver);

            var actual1 = _databaseInstance.LoadAsync<TestModel>( expected1.Key ).Result;
            var actual2 = _databaseInstance.LoadAsync<TestModel>( expected2.Key ).Result;
            
            Assert.IsNotNull(actual1, "Load failed for 1.");
            Assert.AreEqual(expected1.Key, actual1.Key, "Load failed (1): key mismatch.");
            Assert.AreEqual(expected1.Data, actual1.Data, "Load failed(1): data mismatch.");
            Assert.IsNotNull(actual1.SubClass, "Load failed (1): sub class is null.");
            Assert.AreEqual(expected1.SubClass.NestedText, actual1.SubClass.NestedText, "Load failed (1): sub class text mismtach.");
            Assert.AreEqual(expected1.GuidNullable, actual1.GuidNullable, "Load failed (1): nullable Guid mismtach.");

            Assert.IsNotNull(actual2, "Load failed for 2.");
            Assert.AreEqual(expected2.Key, actual2.Key, "Load failed (2): key mismatch.");
            Assert.AreEqual(expected2.Data, actual2.Data, "Load failed (2): data mismatch.");
            Assert.IsNotNull(actual2.SubClass, "Load failed (2): sub class is null.");
            Assert.AreEqual(expected2.SubClass.NestedText, actual2.SubClass.NestedText, "Load failed (2): sub class text mismatch.");
            Assert.IsNull(expected2.GuidNullable, "Load failed (2): nullable Guid was not loaded as null.");

            //insert a third 
            var expected3 = TestModel.MakeTestModel();
            _databaseInstance.SaveAsync( expected3 ).Wait();

            actual1 = _databaseInstance.LoadAsync<TestModel>( expected1.Key ).Result;
            actual2 = _databaseInstance.LoadAsync<TestModel>( expected2.Key ).Result;
            var actual3 = _databaseInstance.LoadAsync<TestModel>( expected3.Key ).Result;

            Assert.IsNotNull(actual1, "Load failed for 1.");
            Assert.AreEqual(expected1.Key, actual1.Key, "Load failed (1): key mismatch.");
            Assert.AreEqual(expected1.Data, actual1.Data, "Load failed(1): data mismatch.");
            Assert.IsNotNull(actual1.SubClass, "Load failed (1): sub class is null.");
            Assert.AreEqual(expected1.SubClass.NestedText, actual1.SubClass.NestedText, "Load failed (1): sub class text mismtach.");

            Assert.IsNotNull(actual2, "Load failed for 2.");
            Assert.AreEqual(expected2.Key, actual2.Key, "Load failed (2): key mismatch.");
            Assert.AreEqual(expected2.Data, actual2.Data, "Load failed (2): data mismatch.");
            Assert.IsNotNull(actual2.SubClass, "Load failed (2): sub class is null.");
            Assert.AreEqual(expected2.SubClass.NestedText, actual2.SubClass.NestedText, "Load failed (2): sub class text mismtach.");

            Assert.IsNotNull(actual3, "Load failed for 3.");
            Assert.AreEqual(expected3.Key, actual3.Key, "Load failed (3): key mismatch.");
            Assert.AreEqual(expected3.Data, actual3.Data, "Load failed (3): data mismatch.");
            Assert.IsNotNull(actual3.SubClass, "Load failed (3): sub class is null.");
            Assert.AreEqual(expected3.SubClass.NestedText, actual3.SubClass.NestedText, "Load failed (3): sub class text mismtach.");

            // load the complex 
            var actualComplex = _databaseInstance.LoadAsync<TestComplexModel>( 5 ).Result;
            Assert.IsNotNull(actualComplex, "Load failed (complex): object is null.");
            Assert.AreEqual(5, actualComplex.Id, "Load failed: id mismatch.");
            Assert.IsNotNull(actualComplex.Dict, "Load failed: dictionary is null.");
            foreach(var key in expectedComplex.Dict.Keys)
            {
                var value = expectedComplex.Dict[key];
                Assert.IsTrue(actualComplex.Dict.Contains(key), "Load failed: dictionary is missing key.");
                Assert.AreEqual(value, actualComplex.Dict[key], "Load failed: dictionary has invalid value.");
            }

            Assert.IsNotNull(actualComplex.Models, "Load failed: complex missing the model collection.");

            foreach(var model in expectedComplex.Models)
            {
                var targetModel = actualComplex.Models.Where(m => m.Key.Equals(model.Key)).FirstOrDefault();
                Assert.IsNotNull(targetModel, "Load failed for nested model.");
                Assert.AreEqual(model.Key, targetModel.Key, "Load failed for nested model: key mismatch.");
                Assert.AreEqual(model.Data, targetModel.Data, "Load failed for nested model: data mismatch.");
                Assert.IsNotNull(targetModel.SubClass, "Load failed for nested model: sub class is null.");
                Assert.AreEqual(model.SubClass.NestedText, targetModel.SubClass.NestedText, "Load failed for nested model: sub class text mismtach.");
            }

        }
Example #9
0
        public void TestSaveLateBoundTable()
        {
            // test saving and reloading
            var expected = new TestLateBoundTable {Id = 1, Data = Guid.NewGuid().ToString()};

            _databaseInstance.RegisterTableDefinition(_databaseInstance.CreateTableDefinition<TestLateBoundTable,int>(t=>t.Id));

            _databaseInstance.SaveAsync( expected ).Wait();

            var actual = _databaseInstance.LoadAsync<TestLateBoundTable>( expected.Id ).Result;

            Assert.IsNotNull(actual, "Load failed.");

            Assert.AreEqual(expected.Id, actual.Id, "Load failed: key mismatch.");
            Assert.AreEqual(expected.Data, actual.Data, "Load failed: data mismatch.");

            _databaseInstance.FlushAsync().Wait();

            _engine.Dispose();
            var driver = _databaseInstance.Driver;
            _databaseInstance = null;

            // bring it back up
            _engine = Factory.NewEngine();
            _engine.Activate();
            _databaseInstance = _engine.SterlingDatabase.RegisterDatabase<TestDatabaseInstance>(TestContext.TestName, driver);

            // do this in a different order
            _databaseInstance.RegisterTableDefinition(_databaseInstance.CreateTableDefinition<TestSecondLateBoundTable,int>(t=>t.Id));

            _databaseInstance.RegisterTableDefinition(_databaseInstance.CreateTableDefinition<TestLateBoundTable, int>(t => t.Id));

            actual = _databaseInstance.LoadAsync<TestLateBoundTable>( expected.Id ).Result;

            Assert.IsNotNull(actual, "Load failed after restart.");

            Assert.AreEqual(expected.Id, actual.Id, "Load failed: key mismatch after restart.");
            Assert.AreEqual(expected.Data, actual.Data, "Load failed: data mismatch after restart.");
        }
Example #10
0
        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.");
        }