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); } }
public void UpdatePlotNumber() { var unitCode = Units.First(); //var plotNumber = 1; using (var database = CreateDatabase()) { var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID)); var plotID = datastore.AddNewPlot(unitCode); validatePlot(datastore, unitCode, plotID, 1); var treeID = datastore.CreatePlotTree(unitCode, 1, "st1", "sg1"); datastore.UpdatePlotNumber(plotID, 2); validatePlot(datastore, unitCode, plotID, 2); // verify that plot number updates on tree records var treeAfter = datastore.GetTree(treeID); treeAfter.PlotNumber.Should().Be(2); } }
public void AddPlotRemarks() { var remarks = "something"; var unitCode = Units.First(); var plotNumber = 1; using (var database = CreateDatabase()) { var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID)); var plotID = datastore.AddNewPlot(unitCode); validatePlot(datastore, unitCode, plotID, plotNumber); var plot = datastore.GetPlot(plotID); datastore.AddPlotRemark(plot.CuttingUnitCode, plot.PlotNumber, remarks); var stuff = database.QueryGeneric("select * from plot").ToArray(); var plotAgain = datastore.GetPlot(plotID); plotAgain.Remarks.Should().Be(remarks); datastore.AddPlotRemark(plot.CuttingUnitCode, plot.PlotNumber, remarks); plotAgain = datastore.GetPlot(plotID); plotAgain.Remarks.Should().Be(remarks + ", " + remarks); } }
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(); } }
public void AddNewPlot() { var unitCode = Units.First(); //var plotNumber = 1; using (var database = CreateDatabase()) { var datastore = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID)); var plotID = datastore.AddNewPlot(unitCode); validatePlot(datastore, unitCode, plotID, 1); var plotID2 = datastore.AddNewPlot(unitCode); validatePlot(datastore, unitCode, plotID2, 2); } }
public void IncrementFixCNTTreeCount() { var unitCode = Units.First(); var plotNumber = 1; var fieldName = "DBH"; var value = 10; var subpop = Subpops.First(); var sgCode = subpop.SampleGroupCode; var stCode = subpop.StratumCode; var sp = subpop.SpeciesCode; var ld = subpop.LiveDead; using (var database = CreateDatabase()) { var plotds = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID)); var plotID = plotds.AddNewPlot(unitCode); var ds = new FixCNTDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID); ds.GetTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value) .Should().Be(0); // after incrementing once, tree count should be 1 // and there shold only be one tree in the tree table ds.IncrementFixCNTTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value); ds.GetTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value) .Should().Be(1); database.ExecuteScalar <int>("SELECT count(*) FROM Tree;").Should().Be(1); // after incrementing a second time, tree count should be 2 // and there shold still only be one tree in the tree table ds.IncrementFixCNTTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value); ds.GetTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value) .Should().Be(2); database.ExecuteScalar <int>("SELECT count(*) FROM Tree;").Should().Be(1); var plotTrees = plotds.GetPlotTreeProxies(unitCode, plotNumber); plotTrees.Should().HaveCount(1); } }
public void GetPlot_Strata() { 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); } }
public void DecrementFixCNTTreeCount() { var unitCode = Units.First(); var plotNumber = 1; var fieldName = "DBH"; var value = 10; var subpop = Subpops.First(); var sgCode = subpop.SampleGroupCode; var stCode = subpop.StratumCode; var sp = subpop.SpeciesCode; var ld = subpop.LiveDead; using (var database = CreateDatabase()) { var plotds = new CuttingUnitDatastore(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID, new SamplerInfoDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID)); var plotID = plotds.AddNewPlot(unitCode); var ds = new FixCNTDataservice(database, CruiseID, TestDeviceInfoService.TEST_DEVICEID); // check initial state ds.GetTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value) .Should().Be(0); // increment once ds.IncrementFixCNTTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value); ds.GetTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value) .Should().Be(1); // decrement back to zero ds.DecrementFixCNTTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value); ds.GetTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value) .Should().Be(0); // try to decrement past zero should only result in count of zero ds.DecrementFixCNTTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value); ds.GetTreeCount(unitCode, plotNumber, stCode, sgCode, sp, ld, fieldName, value) .Should().Be(0); } }