public void Sync_Sale_Update() { var fromPath = base.GetTempFilePath(".crz3", "Sale_Update_fromFile"); var toPath = base.GetTempFilePath(".crz3", "Sale_Update_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = CruiseID; var saleID = SaleID; using var fromDb = CreateDatabaseFile(fromPath); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var sale = fromDb.From <Sale>() .Where("SaleID = @p1") .Query(saleID) .FirstOrDefault(); sale.Remarks = Rand.String(); fromDb.Update(sale); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var saleAgain = toDb.From <Sale>().Where("SaleID = @p1").Query(saleID).FirstOrDefault(); saleAgain.Should().BeEquivalentTo(sale, x => x.Excluding(y => y.Modified_TS)); }
public void Sync_SampleGroup_Add() { var fromPath = base.GetTempFilePath(".crz3", "SampleGroup_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "SampleGroup_Add_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var sampleGroupID = Guid.NewGuid().ToString(); fromDb.Insert(new SampleGroup() { CruiseID = cruiseID, SampleGroupID = sampleGroupID, SampleGroupCode = "10", StratumCode = Strata[0].StratumCode, }); var newSampleGroup = fromDb.From <SampleGroup>().Where("SampleGroupID = @p1").Query(sampleGroupID).Single(); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var sampleGroupAgain = toDb.From <SampleGroup>().Where("SampleGroupID = @p1") .Query(sampleGroupID).FirstOrDefault(); sampleGroupAgain.Should().BeEquivalentTo(newSampleGroup); }
public void Sync_CuttingUnit_Add() { var fromPath = base.GetTempFilePath(".crz3", "CuttingUnit_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "CuttingUnit_Add_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var cuttingUnitID = Guid.NewGuid().ToString(); fromDb.Insert(new CuttingUnit() { CruiseID = cruiseID, CuttingUnitID = cuttingUnitID, CuttingUnitCode = "10", }); var newCuttingUnit = fromDb.From <CuttingUnit>().Where("CuttingUnitID = @p1").Query(cuttingUnitID).Single(); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var cuttingUnitAgain = toDb.From <CuttingUnit>().Where("CuttingUnitID = @p1") .Query(cuttingUnitID).FirstOrDefault(); cuttingUnitAgain.Should().BeEquivalentTo(newCuttingUnit, x => x.Excluding(y => y.Modified_TS)); }
public void Sync_BiomassEquation_Add() { var fromPath = base.GetTempFilePath(".crz3", "Sync_BiomassEquations_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "Sync_BiomassEquations_Add_toFile"); var syncOptions = new CruiseSyncOptions() { Processing = SyncFlags.InsertUpdate, }; var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var newBiomassEquation = new BiomassEquation { CruiseID = cruiseID, Component = "sfdf", Species = "sp1", Product = "01", LiveDead = "L", }; fromDb.Insert(newBiomassEquation); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); toDb.From <BiomassEquation>().Count().Should().Be(1); }
public void SyncStratumTemplates_Add() { var fromPath = base.GetTempFilePath(".crz3", "SyncStratumTemplates_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "SyncStratumTemplates_Add_toFile"); var syncOptions = new CruiseSyncOptions() { Processing = SyncFlags.Insert, }; var init = new DatabaseInitializer(); var cruiseID = init.CruiseID; var saleID = init.SaleID; using var fromDb = init.CreateDatabaseFile(fromPath); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var st = new StratumTemplate { CruiseID = cruiseID, StratumTemplateName = "something", }; fromDb.Insert(st); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); toDb.From <StratumTemplate>().Count().Should().Be(1); }
public void Sync_Plot_Stratum_Update() { var fromPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_toFile"); var syncOptions = new CruiseSyncOptions() { Design = SyncFlags.Insert, FieldData = SyncFlags.InsertUpdate, }; var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); var plot = new Plot() { CruiseID = cruiseID, PlotID = Guid.NewGuid().ToString(), CuttingUnitCode = Units[0], PlotNumber = 1, }; fromDb.Insert(plot); var plotStratum = new Plot_Stratum() { CruiseID = cruiseID, PlotNumber = plot.PlotNumber, CuttingUnitCode = plot.CuttingUnitCode, StratumCode = PlotStrata[0].StratumCode, }; fromDb.Insert(plotStratum); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); plotStratum.KPI = Rand.Double(); plotStratum.ThreePRandomValue = Rand.Int(); toDb.Update(plotStratum); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var plotStratumAgain = toDb .From <Plot_Stratum>() .Where("Plot_Stratum_CN = @p1") .Query(plotStratum.Plot_Stratum_CN) .FirstOrDefault(); plotStratumAgain.Should().BeEquivalentTo(plotStratum, config => config.Excluding(x => x.Modified_TS)); }
public void Sync_PlotLocation_Update() { var fromPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "Sync_Plot_Add_toFile"); var syncOptions = new CruiseSyncOptions() { Design = SyncFlags.Insert, FieldData = SyncFlags.Update, }; var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); var newPlot = new Plot() { CruiseID = cruiseID, PlotID = Guid.NewGuid().ToString(), CuttingUnitCode = Units[0], PlotNumber = 1, }; fromDb.Insert(newPlot); var plotLocation = new PlotLocation() { PlotID = newPlot.PlotID, }; fromDb.Insert(plotLocation); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); plotLocation.Latitude = Rand.Double(); plotLocation.Longitude = Rand.Double(); fromDb.Update(plotLocation); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var plotLocationAgain = toDb.From <PlotLocation>() .Where("PlotID = @p1") .Query(plotLocation.PlotID) .FirstOrDefault(); plotLocationAgain.Should().BeEquivalentTo(plotLocation, config => config.Excluding(x => x.Modified_TS)); }
public void MigrateFromV2ToV3_Test_With_Existing_File(string fileName) { var filePath = Path.Combine(TestFilesDirectory, fileName); // copy file to test temp dir var tempPath = Path.Combine(TestTempPath, fileName); File.Copy(filePath, tempPath); var newCruisePath = new Migrator().MigrateFromV2ToV3(tempPath); using (var newCruise = new CruiseDatastore_V3(newCruisePath)) { var cruise = newCruise.From <Cruise>().Query().Single(); cruise.CruiseID.Should().NotBeNullOrEmpty(); } }
public void Sync_CuttingUnit_Update() { var fromPath = base.GetTempFilePath(".crz3", "CuttingUnit_Updated_fromFile"); var toPath = base.GetTempFilePath(".crz3", "CuttingUnit_Update_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); // initialize source database using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); var cuttingUnitID = Guid.NewGuid().ToString(); var cuttingUnit = new CuttingUnit() { CruiseID = cruiseID, CuttingUnitID = cuttingUnitID, CuttingUnitCode = "10", }; fromDb.Insert(cuttingUnit); // initialize dest database // as exact copy of source database fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); // modify cutting unit value and save to source database cuttingUnit.Area = Rand.Int(); cuttingUnit.Description = Rand.String(); cuttingUnit.LoggingMethod = "401"; cuttingUnit.PaymentUnit = Rand.AlphaNumeric(3); cuttingUnit.Rx = Rand.AlphaNumeric(3); cuttingUnit.ModifiedBy = Rand.AlphaNumeric(4); fromDb.Update(cuttingUnit); // run sync var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var cuttingUnitAgain = toDb.From <CuttingUnit>().Where("CuttingUnitID = @p1") .Query(cuttingUnitID).FirstOrDefault(); cuttingUnitAgain.Should().BeEquivalentTo(cuttingUnit, x => x.Excluding(y => y.Modified_TS)); }
public void Sync_SubPopulation_Add() { var fromPath = base.GetTempFilePath(".crz3", "SubPopulation_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "SubPopulation_Add_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var sampleGroup = SampleGroups[0]; var subPopID = Guid.NewGuid().ToString(); var newSubpopulation = new SubPopulation() { CruiseID = cruiseID, SubPopulationID = subPopID, StratumCode = sampleGroup.StratumCode, SampleGroupCode = sampleGroup.SampleGroupCode, SpeciesCode = Species[3], LiveDead = "L", }; fromDb.Insert(newSubpopulation); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var subPopulationAgain = toDb.From <SubPopulation>() .Where("SubPopulationID = @p1") .Query(subPopID).FirstOrDefault(); subPopulationAgain.Should().BeEquivalentTo(newSubpopulation, x => x .Excluding(y => y.Modified_TS) .Excluding(y => y.Created_TS) .Excluding(y => y.CreatedBy)); }
public void Sync_SampleGroup_Update_SampleGroupCode() { var fromPath = base.GetTempFilePath(".crz3", "SampleGroup_Update_SGCode_fromFile"); var toPath = base.GetTempFilePath(".crz3", "SampleGroup_Update_SGCode_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); // initialize source database using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); var sampleGroupID = Guid.NewGuid().ToString(); var sampleGroup = new SampleGroup() { CruiseID = cruiseID, SampleGroupID = sampleGroupID, SampleGroupCode = "10", StratumCode = Strata[0].StratumCode, }; fromDb.Insert(sampleGroup); // initialize dest database // as exact copy of source database fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); // modify sample group code on source database sampleGroup.SampleGroupCode = "11"; fromDb.Update(sampleGroup); // run sync var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var sampleGroupAgain = toDb.From <SampleGroup>().Where("SampleGroupID = @p1") .Query(sampleGroupID).FirstOrDefault(); sampleGroupAgain.SampleGroupCode.Should().BeEquivalentTo(sampleGroup.SampleGroupCode); }
public void Sync_Stratum_Update_StratumCode() { var fromPath = base.GetTempFilePath(".crz3", "Stratum_Updated_stCode_fromFile"); var toPath = base.GetTempFilePath(".crz3", "Stratum_Update_stCode_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); // initialize source database using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); var stratumID = Guid.NewGuid().ToString(); var stratum = new Stratum() { CruiseID = cruiseID, StratumID = stratumID, StratumCode = "10", Method = "100", }; fromDb.Insert(stratum); // initialize dest database // as exact copy of source database fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); // modify stratum code and save to source database stratum.StratumCode = "11"; fromDb.Update(stratum); // run sync var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var stratumAgain = toDb.From <Stratum>().Where("StratumID = @p1") .Query(stratumID).FirstOrDefault(); stratumAgain.StratumCode.Should().BeEquivalentTo(stratum.StratumCode); }
public void Sync_Cruise_Add() { var fromPath = base.GetTempFilePath(".crz3", "Cruise_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "Cruise_Add_toFile"); var syncOptions = new CruiseSyncOptions(); var init = new DatabaseInitializer(); var cruiseID = init.CruiseID; var saleID = init.SaleID; var saleNumber = init.SaleNumber; using var fromDb = init.CreateDatabaseFile(fromPath); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var newCruise = new Cruise { CruiseID = Guid.NewGuid().ToString(), CruiseNumber = "123456789", SaleID = saleID, SaleNumber = saleNumber, }; fromDb.Insert(newCruise); newCruise = fromDb.From <Cruise>().Where("CruiseID = @p1") .Query(newCruise.CruiseID).FirstOrDefault(); var syncer = new CruiseSyncer(); syncer.Sync(newCruise.CruiseID, fromDb, toDb, syncOptions); var newCruiseAgain = toDb.From <Cruise>() .Where("CruiseID = @p1") .Query(newCruise.CruiseID).FirstOrDefault(); newCruiseAgain.Should().NotBeNull(); newCruiseAgain.Should().BeEquivalentTo(newCruise, x => x .Excluding(y => y.Modified_TS)); }
public void Sync_CuttingUnit_Update_CuttingUnitCode() { var fromPath = base.GetTempFilePath(".crz3", "CuttingUnit_Updated_code_fromFile"); var toPath = base.GetTempFilePath(".crz3", "CuttingUnit_Update_code_toFile"); var syncOptions = new CruiseSyncOptions(); var cruiseID = Guid.NewGuid().ToString(); var saleID = Guid.NewGuid().ToString(); // initialize source database using var fromDb = CreateDatabaseFile(fromPath, cruiseID, saleID); var cuttingUnitID = Guid.NewGuid().ToString(); var cuttingUnit = new CuttingUnit() { CruiseID = cruiseID, CuttingUnitID = cuttingUnitID, CuttingUnitCode = "10", }; fromDb.Insert(cuttingUnit); // initialize dest database // as exact copy of source database fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); // modify cutting unit value and save to source database cuttingUnit.CuttingUnitCode = "11"; fromDb.Update(cuttingUnit); // run sync var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); var cuttingUnitAgain = toDb.From <CuttingUnit>().Where("CuttingUnitID = @p1") .Query(cuttingUnitID).FirstOrDefault(); cuttingUnitAgain.CuttingUnitCode.Should().BeEquivalentTo(cuttingUnit.CuttingUnitCode); }
public void SyncTreeDefaultValues_Add() { var fromPath = base.GetTempFilePath(".crz3", "SyncTreeDefaultValues_Add_fromFile"); var toPath = base.GetTempFilePath(".crz3", "SyncTreeDefaultValues_Add_toFile"); var syncOptions = new CruiseSyncOptions() { Processing = SyncFlags.Insert, }; var init = new DatabaseInitializer() { TreeDefaults = null, }; var cruiseID = init.CruiseID; var saleID = init.SaleID; using var fromDb = init.CreateDatabaseFile(fromPath); fromDb.CopyTo(toPath, true); using var toDb = new CruiseDatastore_V3(toPath); var tdv = new TreeDefaultValue { CruiseID = cruiseID, SpeciesCode = "sp1", PrimaryProduct = "01", }; fromDb.Insert(tdv); var syncer = new CruiseSyncer(); syncer.Sync(cruiseID, fromDb, toDb, syncOptions); toDb.From <TreeDefaultValue>().Count().Should().Be(1); }
public void RoundTripV2Migration(string fileName) { var filePath = Path.Combine(TestFilesDirectory, fileName); var reconvertPath = Path.Combine(TestTempPath, "again_" + fileName); Output.WriteLine(reconvertPath); // copy file to test temp dir var tempPath = Path.Combine(TestTempPath, fileName); File.Copy(filePath, tempPath, true); var v3Path = new Migrator().MigrateFromV2ToV3(tempPath, true); using (var v2db = new DAL(tempPath)) using (var v3Database = new CruiseDatastore_V3(v3Path)) { var units = v2db.From <V2.Models.CuttingUnit>().Query(); var strata = v2db.From <V2.Models.Stratum>().Query().ToArray(); var samplegroups = v2db.From <V2.Models.SampleGroup>().Query(); var plots = v2db.From <V2.Models.Plot>().Query(); var trees = v2db.From <V2.Models.Tree>().Query(); // var countTrees = v2db.Query<TreeCNTTotals>( //@"SELECT CuttingUnit_CN, SampleGroup_CN, ifnull(TreeDefaultValue_CN, 0) AS TreeDefaultValue_CN, Sum(TreeCount) AS TreeCount, sum(SumKPI) AS SumKPI FROM CountTree //GROUP BY CuttingUnit_CN, SampleGroup_CN, ifnull(TreeDefaultValue_CN, 0);").ToArray(); var treeCounts = v2db.Query <TreeCNTTotals>( @"SELECT cnt.CuttingUnit_CN, cnt.SampleGroup_CN, cnt.TreeDefaultValue_CN, cnt.TreeCount + sum(TreeCNTTotal) AS TreeCNT, cnt.SumKPI FROM CountTree AS cnt JOIN (SELECT CuttingUnit_CN, SampleGroup_CN, TreeDefaultValue_CN, Sum(TreeCount) as TreeCNTTotal FROM Tree GROUP BY CuttingUnit_CN, SampleGroup_CN, ifnull(TreeDefaultValue_CN, 0)) AS tcnt on tcnt.CuttingUnit_CN = cnt.CuttingUnit_CN AND tcnt.SampleGroup_CN = cnt.SampleGroup_CN AND (cnt.TreeDefaultValue_CN IS NULL OR ifnull(tcnt.TreeDefaultValue_CN, 0) = ifnull(cnt.TreeDefaultValue_CN, 0)) GROUP BY cnt.CuttingUnit_CN, cnt.SampleGroup_CN, cnt.TreeDefaultValue_CN ORDER BY cnt.CuttingUnit_CN, cnt.SampleGroup_CN, cnt.TreeDefaultValue_CN;").ToArray(); var cruise = v3Database.From <Cruise>().Query().Single(); var cruiseID = cruise.CruiseID; using (var v2again = new DAL(reconvertPath, true)) { var tableInfo = v2again.GetTableInfo("Sale"); var downMigrator = new DownMigrator(); downMigrator.MigrateFromV3ToV2(cruiseID, v3Database, v2again, "test"); // var countTreesAgain = v2again.Query<TreeCNTTotals>( //@"SELECT CuttingUnit_CN, SampleGroup_CN, ifnull(TreeDefaultValue_CN, 0) AS TreeDefaultValue_CN, Sum(TreeCount) AS TreeCount, sum(SumKPI) AS SumKPI FROM CountTree //GROUP BY CuttingUnit_CN, SampleGroup_CN, ifnull(TreeDefaultValue_CN, 0);").ToArray(); // var countTreeDiff = countTreesAgain.Except(countTrees).ToArray(); // countTreesAgain.Should().BeEquivalentTo(countTrees); var treeCountsAgain = v2again.Query <TreeCNTTotals>( @"SELECT cnt.CuttingUnit_CN, cnt.SampleGroup_CN, cnt.TreeDefaultValue_CN, cnt.TreeCount + sum(TreeCNTTotal) AS TreeCNT, cnt.SumKPI FROM CountTree AS cnt JOIN (SELECT CuttingUnit_CN, SampleGroup_CN, TreeDefaultValue_CN, Sum(TreeCount) as TreeCNTTotal FROM Tree GROUP BY CuttingUnit_CN, SampleGroup_CN, ifnull(TreeDefaultValue_CN, 0)) AS tcnt on tcnt.CuttingUnit_CN = cnt.CuttingUnit_CN AND tcnt.SampleGroup_CN = cnt.SampleGroup_CN AND (cnt.TreeDefaultValue_CN IS NULL OR ifnull(tcnt.TreeDefaultValue_CN, 0) = ifnull(cnt.TreeDefaultValue_CN, 0)) GROUP BY cnt.CuttingUnit_CN, cnt.SampleGroup_CN, cnt.TreeDefaultValue_CN ORDER BY cnt.CuttingUnit_CN, cnt.SampleGroup_CN, cnt.TreeDefaultValue_CN;").ToArray(); var treeCountDiff = treeCountsAgain.Except(treeCounts).ToArray(); treeCountsAgain.Should().BeEquivalentTo(treeCounts); var unitsAgain = v2again.From <V2.Models.CuttingUnit>().Query(); unitsAgain.Should().BeEquivalentTo(units, config => config .Using <string>(x => x.Subject.Should().Be(x.Expectation?.Trim())).WhenTypeIs <string>()// ignore whitespace when type is string .Excluding(x => x.TallyHistory) ); //var strataAgain = v2again.From<V2.Models.Stratum>().Query(); //strataAgain.Should().Should().BeEquivalentTo(strata); var samplegroupsAgain = v2again.From <V2.Models.SampleGroup>().Query(); samplegroupsAgain.Should().BeEquivalentTo(samplegroups, config => config .Excluding(x => x.SampleSelectorState) .Excluding(x => x.SampleSelectorType) .Excluding(x => x.TallyMethod) ); var plotsAgain = v2again.From <V2.Models.Plot>().Query(); plotsAgain.Should().BeEquivalentTo(plots, config => config .Excluding(x => x.Plot_GUID) // Plot_Stratum doesn't have a guid .Using <string>(ctx => ctx.Subject.Should().Be(ctx.Expectation ?? "False")) // v3 will auto populate IsEmpty with False if null .When(info => info.SelectedMemberPath.Equals(nameof(V2.Models.Plot.IsEmpty)))); var treesAgain = v2again.From <V2.Models.Tree>().Query(); treesAgain.Should().BeEquivalentTo(trees, congig => congig .Excluding(x => x.Tree_GUID) .Excluding(x => x.TreeDefaultValue_CN) .Excluding(x => x.ExpansionFactor) .Excluding(x => x.TreeFactor) .Excluding(x => x.PointFactor) .Excluding(x => x.TreeCount) // tree count may get combined into the count tree table ); } } }
public void RoundTripV2Migration_ignoreCountTreeRecordCount(string fileName) { var filePath = Path.Combine(TestFilesDirectory, fileName); var reconvertPath = Path.Combine(TestTempPath, "again_" + fileName); Output.WriteLine(reconvertPath); // copy file to test temp dir var tempPath = Path.Combine(TestTempPath, fileName); File.Copy(filePath, tempPath, true); var v3Path = new Migrator().MigrateFromV2ToV3(tempPath, true); using (var v2db = new DAL(tempPath)) using (var v3Database = new CruiseDatastore_V3(v3Path)) { var units = v2db.From <V2.Models.CuttingUnit>().Query(); var strata = v2db.From <V2.Models.Stratum>().Query().ToArray(); var samplegroups = v2db.From <V2.Models.SampleGroup>().Query(); var plots = v2db.From <V2.Models.Plot>().Query(); var trees = v2db.From <V2.Models.Tree>().Query(); var reports = v2db.From <V2.Models.Reports>().Query(); var cruise = v3Database.From <Cruise>().Query().Single(); var cruiseID = cruise.CruiseID; using (var v2again = new DAL(reconvertPath, true)) { var tableInfo = v2again.GetTableInfo("Sale"); var downMigrator = new DownMigrator(); downMigrator.MigrateFromV3ToV2(cruiseID, v3Database, v2again, "test"); var unitsAgain = v2again.From <V2.Models.CuttingUnit>().Query(); unitsAgain.Should().BeEquivalentTo(units, config => config .Using <string>(x => x.Subject.Should().Be(x.Expectation?.Trim())).WhenTypeIs <string>()// ignore whitespace when type is string .Excluding(x => x.TallyHistory) ); //var strataAgain = v2again.From<V2.Models.Stratum>().Query(); //strataAgain.Should().Should().BeEquivalentTo(strata); var samplegroupsAgain = v2again.From <V2.Models.SampleGroup>().Query(); samplegroupsAgain.Should().BeEquivalentTo(samplegroups, config => config .Excluding(x => x.SampleSelectorState) .Excluding(x => x.SampleSelectorType) .Excluding(x => x.TallyMethod) ); var plotsAgain = v2again.From <V2.Models.Plot>().Query(); plotsAgain.Should().BeEquivalentTo(plots, config => config .Excluding(x => x.Plot_GUID) // Plot_Stratum doesn't have a guid .Using <string>(ctx => ctx.Subject.Should().Be(ctx.Expectation ?? "False")) // v3 will auto populate IsEmpty with False if null .When(info => info.SelectedMemberPath.Equals(nameof(V2.Models.Plot.IsEmpty)))); var treesAgain = v2again.From <V2.Models.Tree>().Query(); treesAgain.Should().BeEquivalentTo(trees, congig => congig .Excluding(x => x.Tree_GUID) .Excluding(x => x.TreeDefaultValue_CN) .Excluding(x => x.ExpansionFactor) .Excluding(x => x.TreeFactor) .Excluding(x => x.PointFactor) .Excluding(x => x.TreeCount) // tree count may get combined into the count tree table .Excluding(x => x.HiddenPrimary) ); var reportsAgain = v2again.From <V2.Models.Reports>().Query(); reportsAgain.Should().BeEquivalentTo(reports); } } }