Пример #1
0
        public void CreateMeasureTree()
        {
            var unitCode    = "u1";
            var stratumCode = "st1";
            var sgCode      = "sg1";
            var species     = "sp1";
            var liveDead    = "L";
            //var countMeasure = "C";
            var treeCount = 1;

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

                var treeID = datastore.CreateMeasureTree(unitCode, stratumCode, sgCode, species, liveDead, treeCount);

                var tree = datastore.GetTree(treeID);
                tree.Should().NotBeNull();

                //tree.CuttingUnit_CN.Should().Be(1);
                tree.TreeID.Should().Be(treeID);
                tree.StratumCode.Should().Be(stratumCode);
                tree.SampleGroupCode.Should().Be(sgCode);
                tree.SpeciesCode.Should().Be(species);
                tree.LiveDead.Should().Be(liveDead);
                //tree.CountOrMeasure.Should().Be(countMeasure);
                //tree.TreeCount.Should().Be(treeCount);

                var tds = new TallyDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var tallyLedger = tds.GetTallyEntry(treeID);
                tallyLedger.Should().NotBeNull();
                tallyLedger.CountOrMeasure.Should().Be("M");
            }
        }
        [InlineData("st3", "sg1", "sp1", "L", SampleResult.I)] // tally by subpop - insurance
        public void InsertTallyAction(string stratumCode, string sgCode, string species, string liveDead, SampleResult sampleResult)
        {
            var unitCode  = "u1";
            var treeCount = 50;

            using (var database = CreateDatabase())
            {
                var datastore = new TallyDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));
                var tpds      = new TallyPopulationDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID);
                var cuds      = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID));

                var tallyPops = database.QueryGeneric($"Select * from TallyPopulation WHERE StratumCode = '{stratumCode}';")
                                .ToArray();

                var pop = tpds.GetTallyPopulation(unitCode, stratumCode, sgCode, species, liveDead);

                pop.Should().NotBeNull();

                var tallyAction = new TallyAction(unitCode, pop)
                {
                    SampleResult = sampleResult,
                    TreeCount    = treeCount,
                };

                var entry = datastore.InsertTallyAction(tallyAction);

                entry.TallyLedgerID.Should().NotBeEmpty();

                ValidateTallyEntry(entry, sampleResult == SampleResult.M || sampleResult == SampleResult.I);

                var entryAgain = datastore.GetTallyEntry(entry.TallyLedgerID);

                ValidateTallyEntry(entryAgain, sampleResult == SampleResult.M || sampleResult == SampleResult.I);

                //var tree = database.From<Tree>().Where("TreeID = @p1").Query(entry.TreeID).FirstOrDefault();

                if (sampleResult == SampleResult.M || sampleResult == SampleResult.I)
                {
                    var tree = cuds.GetTree(entry.TreeID);

                    tree.Should().NotBeNull();

                    tree.TreeID.Should().Be(entry.TreeID);
                    tree.StratumCode.Should().Be(stratumCode);
                    tree.SampleGroupCode.Should().Be(sgCode);
                    tree.SpeciesCode.Should().Be(pop.SpeciesCode);
                    tree.LiveDead.Should().Be(pop.LiveDead);
                    tree.CountOrMeasure.Should().Be(sampleResult.ToString());
                }

                var tallyPopulate = tpds.GetTallyPopulationsByUnitCode(unitCode).Where(x => (x.SpeciesCode ?? "") == (species ?? "")).Single();

                tallyPopulate.TreeCount.Should().Be(treeCount);
            }
        }