public void BackupDatabase_into_existing() { using (var ds = new SQLiteDatastore()) { var dbbuilder = new TestDBBuilder(); ds.CreateDatastore(dbbuilder); var orgTableInfo = ds.QueryGeneric("SELECT * FROM Sqlite_Master;").ToArray(); orgTableInfo.Should().NotBeEmpty(); var backupTarget = base.GetTempFilePath(".db"); RegesterFileForCleanUp(backupTarget); // create database file using (var targetds = new SQLiteDatastore(backupTarget)) { targetds.CreateDatastore(dbbuilder); targetds.Execute("CREATE TABLE Something (" + "col1 text" + ");"); targetds.CheckTableExists("Something").Should().BeTrue(); targetds.Execute("ALTER Table MultiPropTable ADD COLUMN justanothercolumn text;"); targetds.CheckFieldExists("MultiPropTable", "justanothercolumn").Should().BeTrue(); ds.BackupDatabase(targetds); targetds.CheckTableExists("something").Should().BeFalse(); targetds.CheckFieldExists("MultiPropTable", "justanothercolumn").Should().BeFalse(); } } }
public void BackupDatabase_overwrite_openfile_with_inmemory() { var tempPath = GetTempFilePath(".crz3"); RegesterFileForCleanUp(tempPath); using (var ds = new SQLiteDatastore(tempPath)) { var dbbuilder = new TestDBBuilder(); ds.CreateDatastore(dbbuilder); var orgTableInfo = ds.QueryGeneric("SELECT * FROM Sqlite_Master;").ToArray(); orgTableInfo.Should().NotBeEmpty(); ds.From <POCOMultiTypeObject>().Query().Should().BeEmpty(); using (var newds = new SQLiteDatastore()) { newds.CreateDatastore(dbbuilder); newds.Insert(new POCOMultiTypeObject() { ID = 1, }); newds.From <POCOMultiTypeObject>().Query().Should().NotBeEmpty(); newds.BackupDatabase(tempPath); } ds.From <POCOMultiTypeObject>().Query().Should().NotBeEmpty(); } }
public void BackupDatabase_overwrite_existing() { using (var ds = new SQLiteDatastore()) { var dbbuilder = new TestDBBuilder(); ds.CreateDatastore(dbbuilder); var orgTableInfo = ds.QueryGeneric("SELECT * FROM Sqlite_Master;").ToArray(); orgTableInfo.Should().NotBeEmpty(); var backupTarget = base.GetTempFilePath(".db"); RegesterFileForCleanUp(backupTarget); // create a file to overwrite // this doesn't need to be an actual db file File.WriteAllText(backupTarget, "something"); File.Exists(backupTarget).Should().BeTrue(); // backup the database to the location of the file we just created ds.BackupDatabase(backupTarget); File.Exists(backupTarget).Should().BeTrue(); // and conferm that it did overwrite the old file using (var newds = new SQLiteDatastore(backupTarget)) { var newTableInfo = ds.QueryGeneric("SELECT * FROM Sqlite_Master;"); newTableInfo.Should().BeEquivalentTo(orgTableInfo); } } }
public void BackupDatabase_inmemory() { using (var ds = new SQLiteDatastore()) { var dbbuilder = new TestDBBuilder(); ds.CreateDatastore(dbbuilder); var orgTableInfo = ds.QueryGeneric("SELECT * FROM Sqlite_Master;").ToArray(); orgTableInfo.Should().NotBeEmpty(); var backupTarget = base.GetTempFilePath(".db"); RegesterFileForCleanUp(backupTarget); File.Exists(backupTarget).Should().BeFalse(); ds.BackupDatabase(backupTarget); File.Exists(backupTarget).Should().BeTrue(); using (var newds = new SQLiteDatastore(backupTarget)) { var newTableInfo = ds.QueryGeneric("SELECT * FROM Sqlite_Master;"); newTableInfo.Should().BeEquivalentTo(orgTableInfo); } } }
public void CreateInmemorySQLiteDatastoreTest() { var dbBuilder = new TestDBBuilder(); using (var ds = new SQLiteDatastore()) { Assert.True(ds.Exists); ds.CreateDatastore(dbBuilder); VerifySQLiteDatastore(ds); } }
public void CreateSQLiteDatastoreTest() { Output.WriteLine("Path: " + _testCreatePath); var dbBuilder = new TestDBBuilder(); using (var ds = new SQLiteDatastore(_testCreatePath)) { Assert.False(ds.Exists, "Pre-condition failed file already created"); ds.CreateDatastore(dbBuilder); ds.Extension.Should().NotBeNullOrWhiteSpace("file must have extention"); ds.Path.Should().NotBeNullOrWhiteSpace(); VerifySQLiteDatastore(ds); } File.Exists(_testCreatePath + "-journal").Should().BeFalse(); var file = new FileInfo(_testCreatePath); file.Invoking(f => f.Delete()).Should().NotThrow(); }