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"); } }
public void GetTallyEntriesByUnitCode() { var unit = Units.First(); var subpop = Subpops[0]; var stratum = subpop.StratumCode; var sampleGroup = subpop.SampleGroupCode; var species = subpop.SpeciesCode; var liveDead = subpop.LiveDead; 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 pop = tpds.GetTallyPopulation(unit, stratum, sampleGroup, species, liveDead); // insert entry using InsertTallyAction datastore.InsertTallyAction(new TallyAction(unit, pop)); var tallyEntries = datastore.GetTallyEntriesByUnitCode(unit); tallyEntries.Should().HaveCount(1); // add another entry using insertTallyLedger datastore.InsertTallyLedger(new TallyLedger(unit, pop)); tallyEntries = datastore.GetTallyEntriesByUnitCode(unit); tallyEntries.Should().HaveCount(2); // inset a tally ledger with plot number // and conferm that GetTallyEntriesByUnitCode doesn't return plot tally entries cuds.AddNewPlot(unit); datastore.InsertTallyAction(new TallyAction(unit, 1, pop)); tallyEntries = datastore.GetTallyEntriesByUnitCode(unit); tallyEntries.Should().HaveCount(2); } }
[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); } }
public void DeleteTallyEntry() { var unitCode = "u1"; var stratumCode = "st3"; var sgCode = "sg1"; var species = "sp1"; var liveDead = "L"; var tree_guid = Guid.NewGuid().ToString(); var tallyLedgerID = Guid.NewGuid().ToString(); var treeCount = 1; var cruiseID = CruiseID; 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 tallyPop = tpds.GetTallyPopulation(unitCode, stratumCode, sgCode, species, liveDead); tallyPop.Should().NotBeNull("tallyPop"); var tallyEntry = new TallyAction(unitCode, tallyPop) { TreeCount = treeCount }; var entry = datastore.InsertTallyAction(tallyEntry); datastore.DeleteTallyEntry(entry.TallyLedgerID); var tallyPopAgain = tpds.GetTallyPopulationsByUnitCode(unitCode) .Where(x => x.StratumCode == stratumCode && x.SampleGroupCode == sgCode && x.SpeciesCode == species).Single(); tallyPopAgain.TreeCount.Should().Be(0, "TreeCount"); tallyPopAgain.SumKPI.Should().Be(0, "SumKPI"); database.ExecuteScalar <int>("SELECT count(*) FROM Tree WHERE TreeID = @p1", entry.TreeID).Should().Be(0, "tree should be deleted"); } }
public void InsertTallyLedger() { string unitCode = UnitStrata[0].CuttingUnitCode; string stratum = UnitStrata[0].StratumCode; string sampleGroup = Subpops[0].SampleGroupCode; string species = Subpops[0].SpeciesCode; string liveDead = Subpops[0].LiveDead; int treeCountDiff = 1; int kpi = 1; 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 pop = tpds.GetTallyPopulation(unitCode, stratum, sampleGroup, species, liveDead); pop.Should().NotBeNull(); VerifyTallyPopulation(pop); pop.TreeCount.Should().Be(0); pop.SumKPI.Should().Be(0); var tallyLedger = new TallyLedger(unitCode, pop); tallyLedger.TreeCount = treeCountDiff; tallyLedger.KPI = 1; datastore.InsertTallyLedger(tallyLedger); database.ExecuteScalar <int>("SELECT count(*) FROM TallyLedger;").Should().Be(1); database.ExecuteScalar <int>("SELECT sum(TreeCount) FROM TallyLedger;").Should().Be(treeCountDiff); var popAfter = tpds.GetTallyPopulation(unitCode, stratum, sampleGroup, species, liveDead); popAfter.TreeCount.Should().Be(treeCountDiff); popAfter.SumKPI.Should().Be(kpi); } }