public void DeleteSubpopulation() { var init = new DatastoreInitializer(); init.Subpops = new CruiseDAL.V3.Models.SubPopulation[0]; var db = init.CreateDatabase(); var ds = new SubpopulationDataservice(db, init.CruiseID, init.DeviceID); var sg = init.SampleGroups[0]; var newSubpop = new Subpopulation { SubpopulationID = Guid.NewGuid().ToString(), SampleGroupCode = sg.SampleGroupCode, StratumCode = sg.StratumCode, SpeciesCode = init.Species[0], LiveDead = "L", }; ds.AddSubpopulation(newSubpop); ds.DeleteSubpopulation(newSubpop); var subPops = ds.GetSubpopulations(sg.StratumCode, sg.SampleGroupCode); subPops.Should().BeEmpty(); }
public void UpsertSpecies_Insert() { var speciesCode = "ABC"; var initializer = new DatastoreInitializer(); using var db = initializer.CreateDatabase(); var ds = new TemplateDataservice(db, initializer.CruiseID, initializer.DeviceID); var sp = new Species { SpeciesCode = speciesCode, }; ds.UpsertSpecies(sp); db.ExecuteScalar <int>("SELECT count(*) FROM Species WHERE SpeciesCode = @p1", speciesCode) .Should().Be(1); sp.ContractSpecies = Rand.String(); sp.FIACode = Rand.Word(); ds.UpsertSpecies(sp); var spAgain = db.From <Species>().Where("SpeciesCode = @p1").Query(speciesCode).Single(); spAgain.Should().BeEquivalentTo(sp); }
public void Refresh_test() { var init = new DatastoreInitializer(); using (var database = init.CreateDatabase()) { InitializeFizCNT(database, init.CruiseID); var viewModel = new FixCNTTallyViewModel( new DataserviceProvider(database, new TestDeviceInfoService()) { CruiseID = init.CruiseID }); var navParams = new NavigationParameters($"{NavParams.UNIT}=u1&{NavParams.PLOT_NUMBER}=1&{NavParams.STRATUM}=fixCnt1"); viewModel.Initialize(navParams); viewModel.Load(); viewModel.TallyPopulations.Should().NotBeEmpty(); foreach (var tp in viewModel.TallyPopulations) { tp.Buckets.Should().NotBeEmpty(); foreach (var b in tp.Buckets) { b.Value.Should().NotBe(0.0); } } } }
public void IsTreeNumberAvalible_noPlot() { var init = new DatastoreInitializer(); var unit = init.Units[0]; using var db = init.CreateDatabase(); var ds = new CuttingUnitDatastore(db, init.CruiseID, init.DeviceID, new SamplerInfoDataservice(db, init.CruiseID, init.DeviceID)); ds.IsTreeNumberAvalible(unit, 1).Should().BeTrue(); }
public void GetSpecies() { var initializer = new DatastoreInitializer(); using var db = initializer.CreateDatabase(); var ds = new TemplateDataservice(db, initializer.CruiseID, initializer.DeviceID); var species = ds.GetSpecies(); species.Should().NotBeEmpty(); }
public void GetTreeFieldValues_nonExistantTree() { var initializer = new DatastoreInitializer(); using var db = initializer.CreateDatabase(); var dataservice = new CuttingUnitDatastore(db, initializer.CruiseID, initializer.DeviceID, new SamplerInfoDataservice(db, initializer.CruiseID, initializer.DeviceID)); var treeID = Guid.NewGuid().ToString(); var tfvs = dataservice.GetTreeFieldValues(treeID); tfvs.Should().BeEmpty(); }
public void IsTreeNumberAvalible_Plot_nummberAcrossStrata() { var init = new DatastoreInitializer(); var unit = init.Units[0]; var stratum = init.PlotStrata[0].StratumCode; var altStratum = init.PlotStrata[1].StratumCode; var plotNumber = 1; using var db = init.CreateDatabase(); db.Execute("UPDATE Cruise SET UseCrossStrataPlotTreeNumbering = 1 WHERE CruiseID = @p1;", init.CruiseID); var ds = new CuttingUnitDatastore(db, init.CruiseID, init.DeviceID, new SamplerInfoDataservice(db, init.CruiseID, init.DeviceID)); var newPlot = new Plot() { CruiseID = init.CruiseID, CuttingUnitCode = unit, PlotNumber = plotNumber, PlotID = Guid.NewGuid().ToString(), }; db.Insert(newPlot); var newPlotStratum = new Plot_Stratum() { CruiseID = init.CruiseID, CuttingUnitCode = unit, PlotNumber = newPlot.PlotNumber, StratumCode = stratum, }; db.Insert(newPlotStratum); ds.IsTreeNumberAvalible(unit, 1, newPlotStratum.PlotNumber, newPlotStratum.StratumCode).Should().BeTrue(); ds.IsTreeNumberAvalible(unit, 1, newPlotStratum.PlotNumber, altStratum).Should().BeTrue(); db.Insert(new Tree() { CruiseID = init.CruiseID, TreeID = Guid.NewGuid().ToString(), TreeNumber = 1, CuttingUnitCode = unit, StratumCode = stratum, SampleGroupCode = init.SampleGroups[0].SampleGroupCode, PlotNumber = plotNumber, }); ds.IsTreeNumberAvalible(unit, 1, newPlotStratum.PlotNumber, newPlotStratum.StratumCode).Should().BeFalse(); ds.IsTreeNumberAvalible(unit, 1, newPlotStratum.PlotNumber, altStratum).Should().BeFalse(); }
public void GetCruises_Test() { var initializer = new DatastoreInitializer(); using (var db = initializer.CreateDatabase()) { var cruiseID = initializer.CruiseID; var ds = new SaleDataservice(db, cruiseID, TestDeviceInfoService.TEST_DEVICEID); var cruises = ds.GetCruises(); cruises.Should().HaveCount(1); var cruise = cruises.Single(); cruise.HasPlotStrata.Should().BeTrue(); } }
public void GetTallyPopulationsByUnitCode_multiCruise() { var init1 = new DatastoreInitializer(); var init2 = new DatastoreInitializer("1"); var unitCode = init1.Units[0]; using var db = init1.CreateDatabase(); init2.InitializeCruise(db); var ds = new TallyPopulationDataservice(db, init1.CruiseID, init1.DeviceID); var tp = ds.GetTallyPopulationsByUnitCode(unitCode).ToArray(); tp.Should().HaveCount(4); }
public void AddSpecies() { var speciesCode = "ABC"; var initializer = new DatastoreInitializer(); using var db = initializer.CreateDatabase(); var ds = new TemplateDataservice(db, initializer.CruiseID, initializer.DeviceID); var sp = new Species { SpeciesCode = speciesCode, }; ds.AddSpecies(sp); db.ExecuteScalar <int>("SELECT count(*) FROM Species WHERE SpeciesCode = @p1", speciesCode) .Should().Be(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 Tally() { var init = new DatastoreInitializer(); using (var database = init.CreateDatabase()) { InitializeFizCNT(database, init.CruiseID); var deviceInfo = new TestDeviceInfoService(); var datastore = new CuttingUnitDatastore(database, init.CruiseID, deviceInfo.DeviceID, new SamplerInfoDataservice(database, init.CruiseID, init.DeviceID)); var viewModel = new FixCNTTallyViewModel( new DataserviceProvider(database, deviceInfo) { CruiseID = init.CruiseID, }); var navParams = new NavigationParameters($"{NavParams.UNIT}=u1&{NavParams.PLOT_NUMBER}=1&{NavParams.STRATUM}=fixCnt1"); viewModel.Initialize(navParams); viewModel.Load(); var tallyPop = viewModel.TallyPopulations.First(); tallyPop.Buckets.Should().NotBeEmpty(); var bucket = tallyPop.Buckets.FirstOrDefault(); bucket.Should().NotBeNull(); viewModel.Tally(bucket); bucket.TreeCount.Should().Be(1); viewModel.Initialize(navParams); bucket = tallyPop.Buckets.FirstOrDefault(); bucket.TreeCount.Should().Be(1); } }