示例#1
0
        public void ExpandContractSpecies_SpecificProd()
        {
            var fromPath = GetTempFilePath("ExpandContractSpecies_SpecificProd.crz3");
            var toPath   = GetTempFilePath("ExpandContractSpecies_SpecificProd.cruise");

            var specifProd = "01";

            var init = new DatabaseInitializer()
            {
                Species      = new[] { "sp1", },
                TreeDefaults = new[]
                {
                    new TreeDefaultValue {
                        SpeciesCode = "sp1", PrimaryProduct = specifProd, Recoverable = 1.1,
                    },
                    new TreeDefaultValue {
                        SpeciesCode = null, PrimaryProduct = specifProd, Recoverable = 1.2,
                    },
                    new TreeDefaultValue {
                        SpeciesCode = "sp1", PrimaryProduct = null, Recoverable = 1.3,
                    },
                    new TreeDefaultValue {
                        SpeciesCode = null, PrimaryProduct = null, Recoverable = 1.4,
                    },
                },
                Subpops = new SubPopulation[] { },
            };

            using var fromDb = init.CreateDatabaseFile(fromPath);
            using var toDb   = new DAL(toPath, true);

            var spProd = new Species_Product
            {
                CruiseID        = init.CruiseID,
                SpeciesCode     = "sp1",
                ContractSpecies = "something",
                PrimaryProduct  = specifProd,
            };

            fromDb.Insert(spProd);


            var downMigrator = new DownMigrator(new[] { new TreeDefaultValueDownMigrate(), });

            downMigrator.MigrateFromV3ToV2(init.CruiseID, fromDb, toDb);

            var tdvs = toDb.From <V2.Models.TreeDefaultValue>().Query().ToArray();

            // all TDVs with our specified product code should have a contract species
            tdvs.Where(x => x.PrimaryProduct == specifProd).Should().OnlyContain(x => x.ContractSpecies != null);
            // no TDVs without our specified product code should have a contract species
            tdvs.Where(x => x.PrimaryProduct != specifProd).Should().OnlyContain(x => x.ContractSpecies == null);
        }
示例#2
0
        public void MigrateFromV3ToV2()
        {
            var initializer = new DatabaseInitializer();
            var fromPath    = GetTempFilePath("MigrateFromV3ToV2.crz3");
            var toPath      = GetTempFilePath("MigrateFromV3ToV2.cruise");

            using var fromDb = initializer.CreateDatabaseFile(fromPath);
            using var toDb   = new DAL(toPath, true);

            var downMigrator = new DownMigrator();

            downMigrator.MigrateFromV3ToV2(initializer.CruiseID, fromDb, toDb);

            ValidateMigration(fromDb, toDb);
        }
        public void MigrateTreeErrors_measureTree()
        {
            var toPath   = GetTempFilePath("MigrateTreeErrors_measureTree.cruise");
            var fromPath = GetTempFilePath("MigrateTreeErrors_measureTree.crz3");


            var init     = new DatabaseInitializer();
            var cruiseID = init.CruiseID;

            using var db = init.CreateDatabaseFile(fromPath);

            var tree = new Tree
            {
                CruiseID        = cruiseID,
                TreeID          = Guid.NewGuid().ToString(),
                CuttingUnitCode = "u1",
                StratumCode     = "st1",
                SampleGroupCode = "sg1",
                TreeNumber      = 1,
                CountOrMeasure  = "M",
            };

            db.Insert(tree);

            var tm = new TreeMeasurment
            {
                TreeID = tree.TreeID,
            };

            db.Insert(tm);


            using var toDb = new DAL(toPath, true);


            var downMigrator = new DownMigrator();

            downMigrator.MigrateFromV3ToV2(cruiseID, db, toDb);

            var errorLogs = toDb.From <CruiseDAL.V2.Models.ErrorLog>().Query().ToArray();

            errorLogs.Should().HaveCount(4);
            errorLogs.Should().Contain(x => x.Message == "Species Code Is Missing");
            errorLogs.Should().Contain(x => x.Message == "Live/Dead Value Is Missing");
            errorLogs.Should().Contain(x => x.Message == "Aleast One Height Parameter Must Be Greater Than 0");
            errorLogs.Should().Contain(x => x.Message == "DBH or DRC must be greater than 0");
        }
示例#4
0
        public void MigrateFromV3ToV2_With_FieldDefaults()
        {
            var initializer = new DatabaseInitializer();
            var fromPath    = GetTempFilePath("MigrateFromV3ToV2.crz3");
            var toPath      = GetTempFilePath("MigrateFromV3ToV2.cruise");

            using var fromDb = initializer.CreateDatabaseFile(fromPath);

            var sg = initializer.SampleGroups.First();

            fromDb.Insert(new TreeFieldSetup()
            {
                CruiseID         = initializer.CruiseID,
                SampleGroupCode  = sg.SampleGroupCode,
                StratumCode      = sg.StratumCode,
                Field            = "DBH",
                DefaultValueReal = 12.0,
            });

            fromDb.Insert(new TreeFieldSetup()
            {
                CruiseID         = initializer.CruiseID,
                StratumCode      = sg.StratumCode,
                Field            = "DBH",
                DefaultValueReal = 11.0,
            });

            fromDb.Insert(new TreeFieldSetup()
            {
                CruiseID         = initializer.CruiseID,
                StratumCode      = sg.StratumCode,
                Field            = "DRC",
                DefaultValueReal = 13.0,
            });

            var tree = new Tree()
            {
                CruiseID        = initializer.CruiseID,
                TreeID          = Guid.NewGuid().ToString(),
                TreeNumber      = 101,
                CuttingUnitCode = initializer.Units.First(),
                StratumCode     = sg.StratumCode,
                SampleGroupCode = sg.SampleGroupCode,
            };

            fromDb.Insert(tree);

            var tm = new TreeMeasurment
            {
                TreeID = tree.TreeID,
            };

            fromDb.Insert(tm);


            using var toDb = new DAL(toPath, true);

            var downMigrator = new DownMigrator();

            downMigrator.MigrateFromV3ToV2(initializer.CruiseID, fromDb, toDb);

            var treeAgain = toDb.From <V2.Models.Tree>().Where("TreeNumber = 101").Query().Single();

            treeAgain.Should().NotBeNull();
            treeAgain.DBH.Should().Be(12.0);
            treeAgain.DRC.Should().Be(13.0);

            ValidateMigration(fromDb, toDb);
        }
示例#5
0
        public void MigrateFromV3ToV2()
        {
            var fromPath = GetTempFilePath(" TreeDefaultValueDownMigrator_MigrateFromV3ToV2.crz3");
            var toPath   = GetTempFilePath(" TreeDefaultValueDownMigrator_MigrateFromV3ToV2.cruise");

            var initializer = new DatabaseInitializer()
            {
                Species      = new[] { "sp1", "sp2", "sp3" },
                TreeDefaults = new[]
                {
                    new TreeDefaultValue {
                        SpeciesCode = "sp1", PrimaryProduct = "01", Recoverable = 1.1,
                    },
                    new TreeDefaultValue {
                        SpeciesCode = null, PrimaryProduct = "01", Recoverable = 1.2,
                    },
                    new TreeDefaultValue {
                        SpeciesCode = "sp1", PrimaryProduct = null, Recoverable = 1.3,
                    },
                    new TreeDefaultValue {
                        SpeciesCode = null, PrimaryProduct = null, Recoverable = 1.4,
                    },
                },
                Subpops = new SubPopulation[] { },
            };

            using var fromDb = initializer.CreateDatabaseFile(fromPath);
            using var toDb   = new DAL(toPath, true);

            var downMigrator = new DownMigrator(new[] { new TreeDefaultValueDownMigrate(), });

            downMigrator.MigrateFromV3ToV2(initializer.CruiseID, fromDb, toDb);

            var prodCount = fromDb.From <LK_Product>().Count();
            var spCount   = initializer.Species.Count();

            // from the one TDV with explicitly set species and prod we should get two TDVs (one live one dead
            var tdvs = toDb.From <V2.Models.TreeDefaultValue>().Where("Species = @p1 AND PrimaryProduct = @p2").Query("sp1", "01").ToArray();

            tdvs.Should().HaveCount(2);
            tdvs.Should().OnlyContain(x => x.Recoverable == 1.1);

            // from the TDV with explicitly set product, we should have 2 TDVs for each species minus the one that was created with explicit sp and prod
            var tdvFromProd = toDb.From <V2.Models.TreeDefaultValue>().Where("PrimaryProduct = @p1 AND Species != @p2 ").Query("01", "sp1").ToArray();

            tdvFromProd.Should().HaveCount((int)((spCount - 1) * 2));
            tdvFromProd.Should().OnlyContain(x => x.Recoverable == 1.2);

            // from the TDV with explicitly set species, we should have 2 TDVs for each product minus the one that was created with explicit sp and prod
            var tdvFromSp = toDb.From <V2.Models.TreeDefaultValue>().Where("Species = @p1 AND PrimaryProduct != @p2").Query("sp1", "01").ToArray();

            tdvFromSp.Should().HaveCount((int)((prodCount - 1) * 2));
            tdvFromSp.Should().OnlyContain(x => x.Recoverable == 1.3);

            // from the TDV with neither species or product defined, we should get (sp -1 * prod - 1) * 2 TDVs
            var tdvFromAnyAny = toDb.From <V2.Models.TreeDefaultValue>().Where("Species != @p1 AND PrimaryProduct != @p2").Query("sp1", "01").ToArray();

            tdvFromAnyAny.Should().HaveCount((int)((spCount - 1) * (prodCount - 1) * 2));
            tdvFromAnyAny.Should().OnlyContain(x => x.Recoverable == 1.4);

            var expectedTDVcount = (1 + (spCount - 1) + (prodCount - 1) + ((spCount - 1) * (prodCount - 1))) * 2;
            var alltdv           = toDb.From <V2.Models.TreeDefaultValue>().Query().ToArray();

            alltdv.Should().HaveCount((int)expectedTDVcount);
        }
        public void CountTree_TreeBased_SingleTallyPop_SingleUnit()
        {
            var fromPath = GetTempFilePath(" CountTree_TreeBased_SingleTallyPop_SingleUnit_MigrateFromV3ToV2.crz3");
            var toPath   = GetTempFilePath(" CountTree_TreeBased_SingleTallyPop_SingleUnit_MigrateFromV3ToV2.cruise");

            var init = new DatabaseInitializer()
            {
                Units  = new[] { "u1" },
                Strata = new[] { new Stratum {
                                     StratumCode = "st1", Method = "STR"
                                 } },
                UnitStrata = new[] { new CuttingUnit_Stratum {
                                         StratumCode = "st1", CuttingUnitCode = "u1"
                                     } },
                SampleGroups = new[] { new SampleGroup {
                                           StratumCode = "st1", SampleGroupCode = "sg1", SamplingFrequency = 101, TallyBySubPop = false
                                       } },
                Subpops = new[] { new SubPopulation {
                                      StratumCode = "st1", SampleGroupCode = "sg1", SpeciesCode = "sp1", LiveDead = "L"
                                  } },
            };

            var expectedCountTreeCount = 1;

            using var fromdb = init.CreateDatabaseFile(fromPath);
            using var todb   = new DAL(toPath, true);

            var unit    = "u1";
            var stratum = "st1";
            var sg      = "sg1";

            var tallyLedgers = new TallyLedger[]
            {
                new TallyLedger {
                    CruiseID = init.CruiseID, CuttingUnitCode = "u1", StratumCode = "st1", SampleGroupCode = "sg1", TreeCount = 101, SpeciesCode = "sp1", LiveDead = "L"
                },
            };

            foreach (var tl in tallyLedgers)
            {
                tl.TallyLedgerID = Guid.NewGuid().ToString();
                fromdb.Insert(tl);
            }

            var tallyPops = fromdb.From <TallyPopulation>().Query().ToArray();

            tallyPops.Should().NotBeEmpty();

            var downMigrator = new DownMigrator();

            downMigrator.MigrateFromV3ToV2(init.CruiseID, fromdb, todb);

            var tls = fromdb.From <TallyLedger>().Query().ToArray();

            tls.Should().HaveCount(1);

            var countTrees = todb.From <V2.Models.CountTree>().Query().ToArray();

            countTrees.Should().HaveCount(expectedCountTreeCount);
            countTrees.Should().OnlyContain(x => x.TreeCount > 0);
        }