Beispiel #1
0
        public void DaoDbStatic()
        {
            var    db        = CopyDb("Static");
            string file      = File("Static");
            string fileWrong = File("Static2");
            string fileCopy  = File("Copy");
            string fileTmp   = TestLib.TestRunDir + @"Libraries\TmpDaoStatic.accdb";

            db.Dispose();
            Assert.IsNull(db.Database);
            Assert.IsNull(db.Connection);
            Assert.IsTrue(DaoDb.Check(file, "DaoTest"));
            Assert.IsTrue(DaoDb.Check(file, "DaoTest", new[] { "Tabl", "SubTabl", "EmptyTabl", "SysTabl", "SysSubTabl" }));
            Assert.IsTrue(DaoDb.Check(file, new[] { "Tabl", "SubTabl", "EmptyTabl" }));
            Assert.IsFalse(DaoDb.Check(fileWrong, "Fignia"));
            Assert.IsFalse(DaoDb.Check(null, "Fignia"));
            Assert.IsFalse(DaoDb.Check(fileWrong, "Fignia"));
            Assert.IsFalse(DaoDb.Check(fileWrong, new[] { "Tabl" }));
            Assert.IsFalse(DaoDb.Check(file, new[] { "Tabl", "SubTabl", "EmptyTabl1" }));

            DaoDb.Compress(file, 10000000);
            DaoDb.Compress(file, 10000);
            Assert.IsTrue(new FileInfo(fileTmp).Exists);

            Assert.IsTrue(DaoDb.FromTemplate(file, fileCopy, ReplaceByTemplate.Always));
            Assert.IsFalse(DaoDb.FromTemplate(file, fileCopy, ReplaceByTemplate.IfNotExists));
            Assert.IsFalse(DaoDb.FromTemplate(file, fileCopy, ReplaceByTemplate.IfNewVersion));
            new FileInfo(fileCopy).Delete();
            Assert.IsTrue(DaoDb.FromTemplate(file, fileCopy, ReplaceByTemplate.IfNotExists));
            new FileInfo(fileCopy).Delete();
            Assert.IsTrue(DaoDb.FromTemplate(file, fileCopy, ReplaceByTemplate.IfNewVersion));
            Assert.IsTrue(new FileInfo(fileCopy).Exists);

            DaoDb.Execute(file, "DELETE * FROM Tabl");
            DaoDb.ExecuteAdo(file, "DELETE * FROM SysTabl");
            using (var rec = new AdoReader(file, "SELECT * FROM Tabl"))
                Assert.IsFalse(rec.HasRows);
            using (var rec = new AdoReader(file, "SELECT * FROM SubTabl"))
                Assert.IsFalse(rec.HasRows);
            using (var rec = new DaoRec(file, "SysTabl"))
                Assert.IsFalse(rec.HasRows);
            using (var rec = new DaoRec(file, "SysSubTabl"))
                Assert.IsFalse(rec.HasRows);
        }