public void TestNew_FileDoesNotExist() { string filename = Path.GetTempFileName(); try { File.Delete(filename); using (RepositoryDataSource dataSource = new RepositoryDataSource()) { dataSource.New(filename); Assert.IsTrue(File.Exists(filename)); Assert.IsTrue(dataSource.IsOpen()); dataSource.Close(); } } finally { if (File.Exists(filename)) { File.Delete(filename); } } }
public void TestNew_FileExists() { string filename = Path.GetTempFileName(); try { using (RepositoryDataSource dataSource = new RepositoryDataSource()) { Assert.Throws <FileLoadException>(new TestDelegate( delegate { dataSource.New(filename); })); if (dataSource.IsOpen()) { dataSource.Close(); } } } finally { if (File.Exists(filename)) { File.Delete(filename); } } }
public void TestVerifyTablesExist() { IList <IDomainTable> expectedTables = new List <IDomainTable>(); expectedTables.Add(new InfoTable()); string filename = Path.GetTempFileName(); File.Delete(filename); using (RepositoryDataSource dataSource = new RepositoryDataSource()) { dataSource.New(filename); foreach (IDomainTable table in expectedTables) { Assert.IsTrue(((ISqliteDataConnection)dataSource.GetDataConnection()).DbConnection.TableExists(table.Name)); Assert.IsTrue(table.IsNew); } Assert.IsFalse(((ISqliteDataConnection)dataSource.GetDataConnection()).DbConnection.TableExists(SchemaTableName.SETTING_V1)); dataSource.Close(); } File.Delete(filename); }
public void TestBackup() { string filename = Path.GetTempFileName(); File.Delete(filename); try { using (RepositoryDataSource dataSource = new RepositoryDataSource()) { Assert.IsFalse(dataSource.IsOpen()); dataSource.New(filename); Assert.IsTrue(dataSource.IsOpen()); Assert.IsTrue(File.Exists(filename)); string backup = Path.GetTempFileName(); File.Exists(backup); Assert.IsTrue(dataSource.Backup(backup)); dataSource.Close(); Assert.IsFalse(dataSource.Backup(backup)); File.Delete(backup); } } finally { if (File.Exists(filename)) { File.Delete(filename); } } }
public void TestInfoTable() { using (RepositoryDataSource dataSource = new RepositoryDataSource()) { string filename = Path.GetTempFileName(); File.Delete(filename); File.Exists(filename).Should().BeFalse(); try { dataSource.New(filename); dataSource.IsOpen().Should().BeTrue(); InfoTable info = new InfoTable { InfoName = "Setting1", Value = "V1" }; IDomainTableRepository <InfoTable> repository = dataSource.DataRepository.GetTableRepositoryFor <InfoTable>(); repository.Should().NotBeNull(); info = repository.Save(info); info.Id.Should().NotBe(0); InfoTable info2 = new InfoTable(); info2 = repository[info.Id]; info2.Id.Should().Be(info.Id); info2.InfoName.Should().Be(info.InfoName); info2.Value.Should().Be(info.Value); IList <IField> fields = info.SupportedFields(); fields.Should().NotBeNull(); fields.Count.Should().Be(2); fields[0].Name.Should().Be(StandardFieldName.InfoName); fields[1].Name.Should().Be(StandardFieldName.Value); ((IEditField)fields[0]).SetValue(0, "Test2"); ((IEditField)fields[1]).SetValue(0, "Test3"); info.InfoName.Should().Be("Test2"); info.Value.Should().Be("Test3"); repository.Save(info); info2.Should().NotBe(info); IField infoNameField = info.Field(StandardFieldName.InfoName); infoNameField.GetValue(0).Should().Be("Test2"); IField valueField = info.Field(StandardFieldName.Value); valueField.GetValue(0).Should().Be("Test3"); } finally { dataSource.Close(); } File.Delete(filename); } }
public void TestOpen() { string filename = Path.GetTempFileName(); File.Delete(filename); try { using (RepositoryDataSource dataSource = new RepositoryDataSource()) { dataSource.New(filename); Assert.IsTrue(dataSource.IsOpen()); Assert.IsTrue(File.Exists(filename)); dataSource.Close(); Assert.IsFalse(dataSource.IsOpen()); dataSource.Open(filename); Assert.IsTrue(dataSource.IsOpen()); Assert.IsTrue(File.Exists(filename)); dataSource.Open(filename); Assert.IsTrue(dataSource.IsOpen()); dataSource.Flush(); dataSource.Close(); Assert.Throws <InvalidOperationException>(new TestDelegate( delegate { dataSource.Flush(); })); } } finally { if (File.Exists(filename)) { File.Delete(filename); } } }
public void TestBackupToInMemoryDatabase() { string filename = Path.GetTempFileName(); File.Delete(filename); using (RepositoryDataSource dataSource = new RepositoryDataSource()) { dataSource.New(filename); //Backing up to an in-memory database should return false. Assert.IsFalse(dataSource.Backup(":memory:")); dataSource.Close(); } }
public void TestNew_AttempRecreateTable() { string filename = Path.GetTempFileName(); File.Delete(filename); using (RepositoryDataSource dataSource = new RepositoryDataSource()) { dataSource.New(filename); Assert.IsTrue(dataSource.IsOpen()); (new InfoTable()).Create(((ISqliteDataConnection)dataSource.GetDataConnection()).DbConnection); dataSource.Close(); } if (File.Exists(filename)) { File.Delete(filename); } }