public void UpdateFrom340_To_342()
        {
            var filePath = InitializeTestFile("UpdateFrom340_To_342.crz3");

            using var ds = new CruiseDatastore(filePath);

            var updater = new Updater_V3();

            updater.Update(ds);

            ds.Invoking(x => x.Execute("DELETE FROM Plot_Stratum;")).Should().NotThrow <FMSC.ORM.SQLException>();
        }
Ejemplo n.º 2
0
        public void MigrateFromV2ToV3_testUpdaterMigrate(string fileName)
        {
            var filePath = Path.Combine(TestFilesDirectory, fileName);
            // copy file to test temp dir
            var tempPath = Path.Combine(TestTempPath, fileName);

            File.Copy(filePath, tempPath);

            var newFilePath = new Migrator().MigrateFromV2ToV3(filePath, true);

            using (var destDB = new CruiseDatastore_V3())
                using (var srcDB = new CruiseDatastore_V3(newFilePath))
                {
                    try
                    {
                        var destConn = destDB.OpenConnection();
                        Updater_V3.Migrate(srcDB, destDB);

                        var dumpPath = newFilePath + ".dump.crz3";
                        RegesterFileForCleanUp(dumpPath);
                        destDB.BackupDatabase(dumpPath);
                        File.Exists(dumpPath).Should().BeTrue();

                        using (var newdb = new CruiseDatastore_V3(dumpPath))
                        {
                            var tables = newdb.GetTableNames();

                            newdb.AttachDB(srcDB, "olddb");

                            foreach (var t in tables)
                            {
                                var stuff = newdb.QueryGeneric($"SELECT * FROM main.{t} EXCEPT SELECT * FROM olddb.{t};")
                                            .ToArray();

                                if (t == "MessageLog")
                                {
                                    stuff.Should().NotBeEmpty();
                                    continue;
                                }

                                stuff.Should().BeEmpty();
                            }
                        }
                    }
                    finally
                    {
                        destDB.ReleaseConnection();
                    }
                }
        }
        public void Update(string fileName)
        {
            var filePath = InitializeTestFile(fileName);

            using (var ds = new CruiseDatastore(filePath))
            {
                var orgDbVersion = ds.DatabaseVersion;
                orgDbVersion.Should().Be(Path.GetFileNameWithoutExtension(fileName));

                var unitCount = ds.GetRowCount("CuttingUnit", "");


                var updater = new Updater_V3();

                updater.Update(ds);

                var unitCountAfter = ds.GetRowCount("CuttingUnit", "");
                unitCountAfter.Should().Be(unitCount);

                var verAfter = ds.DatabaseVersion;
                verAfter.Should().Be(CruiseDatastoreBuilder_V3.DATABASE_VERSION.ToString());

                var tableDefs = CruiseDatastoreBuilder_V3.TABLE_DEFINITIONS;
                foreach (var t in tableDefs)
                {
                    var ti = ds.GetTableInfo(t.TableName);
                    ti.Should().NotBeNullOrEmpty(t.TableName);
                }

                var sale = ds.From <Sale>().Query().Single();
                sale.Should().NotBeNull();

                var cruise = ds.From <Cruise>().Query().Single();
                cruise.SaleNumber.Should().Be(sale.SaleNumber);

                var logs = ds.From <Log>().Query().ToArray();
                if (logs.Any())
                {
                    logs.Should().OnlyContain(x => string.IsNullOrEmpty(x.CruiseID) == false);
                }

                // do integrity check
                var ic_results = ds.QueryScalar <string>("PRAGMA integrity_check;");
                ic_results.Should().HaveCount(1);
                ic_results.Single().Should().Be("ok");
            }
        }
        public void ListFieldsIntersect()
        {
            using (var srcDB = new SQLiteDatastore())
                using (var destDB = new SQLiteDatastore())
                {
                    using (var srcConn = srcDB.OpenConnection())
                        using (var destCon = destDB.OpenConnection())
                        {
                            srcConn.ExecuteNonQuery("CREATE TABLE A ( f1 TEXT, f2 TEXT );");

                            destCon.ExecuteNonQuery("CREATE TABLE A ( f2 TEXT, f3 TEXT );");

                            var tables = Updater_V3.ListFieldsIntersect(destCon, srcConn, "A");
                            tables.Single().Should().Be("\"f2\"");
                        }
                }
        }