public void GetPlotTreeProxies()
        {
            var unitCode   = "u1";
            var plotNumber = 1;

            using (var db = CreateDatabase())
            {
                var ds     = new CuttingUnitDatastore(db, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(db, CruiseID, TestDeviceInfoService.TEST_DEVICEID));
                var plotid = ds.AddNewPlot(unitCode);

                var plot_stratum = ds.GetPlot_Strata(unitCode, plotNumber).First();

                var tp = ds.GetPlotTallyPopulationsByUnitCode(unitCode, plotNumber).First();

                var firstTreeid = ds.CreatePlotTree(unitCode, plotNumber, tp.StratumCode, tp.SampleGroupCode);
                ds.CreatePlotTree(unitCode, plotNumber, tp.StratumCode, tp.SampleGroupCode);

                var trees = ds.GetPlotTreeProxies(unitCode, plotNumber).ToArray();

                trees.Should().HaveCount(2);
                trees.Select(x => x.TreeNumber).Should().BeInAscendingOrder();

                db.Execute("UPDATE Tree SET TreeNumber = 3 WHERE TreeNumber = 1;");

                var treesAgain = ds.GetPlotTreeProxies(unitCode, plotNumber).ToArray();
                treesAgain.Select(x => x.TreeNumber).Should().BeInAscendingOrder();
            }
        }
示例#2
0
        public void GetPlotTallyPopulationsByUnitCode()
        {
            var init = new DatastoreInitializer();
            var unit = init.Units[0];

            using (var db = init.CreateDatabase())
            {
                var ds = new CuttingUnitDatastore(db, init.CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(db, init.CruiseID, init.DeviceID));

                ds.AddNewPlot(unit);

                var plots = ds.GetPlotsByUnitCode(unit);
                plots.Should().HaveCount(1);
                var plot = plots.Single();

                var plotStrata = ds.GetPlot_Strata(unit, plot.PlotNumber, insertIfNotExists: false);
                plotStrata.Should().HaveCount(2);

                var tallyPops = ds.GetPlotTallyPopulationsByUnitCode(unit, plot.PlotNumber);
                tallyPops.Should().NotBeEmpty();
            }
        }
        public void GetPlotTallyPopulationsByUnitCode_PNT_FIX_noPlot(bool tallyBySp)
        {
            var unitCode = "u3";
            var stCode   = "st5";
            var sgCode   = "sg4";

            var method = CruiseDAL.Schema.CruiseMethods.PNT;

            using (var database = CreateDatabase())
            {
                var saleID   = SaleID;
                var cruiseID = CruiseID;

                var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                InitializeDatabase(
                    database,
                    cruiseID,
                    saleID,
                    new[] { unitCode },
                    new[]
                {
                    new dbModels.Stratum {
                        StratumCode = stCode, Method = method
                    },
                },
                    new[]
                {
                    new dbModels.CuttingUnit_Stratum {
                        CuttingUnitCode = unitCode, StratumCode = stCode
                    },
                },
                    new[]
                {
                    new dbModels.SampleGroup {
                        StratumCode = stCode, SampleGroupCode = sgCode, SamplingFrequency = 101, TallyBySubPop = tallyBySp
                    }
                },
                    // species
                    new[] { "sp4" },
                    new[]
                {
                    new dbModels.TreeDefaultValue {
                        SpeciesCode = "sp4", PrimaryProduct = "01"
                    },
                },
                    new[]
                {
                    new dbModels.SubPopulation {
                        StratumCode = stCode, SampleGroupCode = sgCode, SpeciesCode = "sp4", LiveDead = "L"
                    },
                    new dbModels.SubPopulation {
                        StratumCode = stCode, SampleGroupCode = sgCode, SpeciesCode = "sp4", LiveDead = "D"
                    },
                }
                    );

                {
                    //we are going to check that the tally population returned is vallid for a
                    //tally population with no count tree record associated
                    //it should return one tally pop per sample group in the unit, that is associated with a FIX or PNT stratum
                    var unit3tallyPops = datastore.GetPlotTallyPopulationsByUnitCode(unitCode, 1);

                    if (tallyBySp == false)
                    {
                        unit3tallyPops.Should().HaveCount(1);

                        var tp = unit3tallyPops.Single();
                        tp.SpeciesCode.Should().BeNull("Species");
                        tp.LiveDead.Should().BeNull("liveDead");

                        ValidateTallyPop(tp);
                    }
                    else
                    {
                        unit3tallyPops.Should().HaveCount(2);

                        foreach (var tp in unit3tallyPops)
                        {
                            tp.SpeciesCode.Should().NotBeNullOrWhiteSpace();
                            tp.LiveDead.Should().NotBeNullOrWhiteSpace();
                        }
                    }

                    void ValidateTallyPop(TallyPopulation_Plot tp)
                    {
                        tp.StratumCode.Should().Be(stCode);
                        tp.SampleGroupCode.Should().Be(sgCode);
                        tp.InCruise.Should().BeFalse();
                    }
                }
            }
        }