public void RunTestCurrentVersionIdentical() { // tests with the current database without any changes. this should find nothing to import HouseholdPlan.FailOnIncorrectImport = true; using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var path = Path.Combine(wd.WorkingDirectory, "profilegeneratorNothingImportTest.db3"); if (File.Exists(path)) { File.Delete(path); Thread.Sleep(3000); } File.Copy(DatabaseSetup.GetSourcepath(null), path); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var dbm = new DatabaseMerger(mainSim); dbm.RunFindItems(path, null); Logger.Info("Found " + dbm.ItemsToImport.Count + " items."); if (dbm.ItemsToImport.Count != 0) { throw new LPGException("This should not import anything, since its the same database."); } db.Cleanup(); } wd.CleanUp(); } }
public void CSVImportTest2() { using (var db1 = new DatabaseSetup(Utili.GetCurrentMethodAndClass() + "_export")) { //export using (var wd = SetupDB3(Utili.GetCurrentMethodAndClass())) { const string srcfile = @"v:\work\CHR15a_Sc1.csv"; File.Copy(srcfile, Path.Combine(wd.WorkingDirectory, "hh.csv")); var sim = new Simulator("Data Source=profilegenerator.db3") { MyGeneralConfig = { CSVCharacter = ";" } }; sim.MyGeneralConfig.SaveToDB(); var dbm = new DatabaseMerger(sim); const string importPath = @"v:\work\profilegenerator_hennings.db3"; dbm.RunFindItems(importPath, null); dbm.RunImport(null); ModularHouseholdSerializer.ExportAsCSV(sim.ModularHouseholds[0], sim, Path.Combine(wd.WorkingDirectory, "testexportfile.csv")); //import var arguments = new List <string> { "--ImportHouseholdDefinition", "hh.csv" }; MainSimEngine.Run(arguments.ToArray(), "simulationengine.exe"); db1.Cleanup(); wd.CleanUp(1); } } }
public void TestImport() { const string importPath = @"e:\Haushalt3.db3"; var fi = new FileInfo(importPath); if (!File.Exists(importPath)) { throw new LPGException("Missing file: " + fi.FullName); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var hhNames = mainSim.ModularHouseholds.It.Select(x => x.Name).ToList(); var dbm = new DatabaseMerger(mainSim); dbm.RunFindItems(importPath, null); dbm.RunImport(null); var newHHs = mainSim.ModularHouseholds.It.Where(x => !hhNames.Contains(x.Name)).ToList(); foreach (var newHH in newHHs) { if (newHH.Persons.Count == 0) { throw new LPGException("No persons were imported."); } Logger.Info(newHH.Name); foreach (var hhPerson in newHH.Persons) { Logger.Info("\t" + hhPerson.Name); } } db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
private void MergeDatabase() { if (databaseToMerge != null) { DatabaseMerger.Merge(database, databaseToMerge, conflictingIDRule, mergeProperties, mergeActors, mergeItems, mergeLocations, mergeVariables, mergeConversations); Debug.Log(string.Format("{0}: Merged contents of {1} into {2}.", DialogueDebug.Prefix, databaseToMerge.name, database.name)); databaseToMerge = null; } }
public void Version520TimeLimitImport() { string sourcefilepath = DatabaseSetup.GetImportFileFullPath("profilegenerator520_simon.db3"); CleanTestBase.RunAutomatically(false); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var fi = new FileInfo(sourcefilepath); if (!File.Exists(sourcefilepath)) { throw new LPGException("Missing file: " + fi.FullName); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var dbm = new DatabaseMerger(mainSim); Logger.Info("Full Source: " + fi.FullName); dbm.RunFindItems(sourcefilepath, null); dbm.RunImport(null); var timelimits = dbm.ItemsToImport.Count(x => x.Entry.GetType() == typeof(TimeLimit)); timelimits.Should().BeGreaterThan(0); // ReSharper disable once UnusedVariable #pragma warning disable S1481 // Unused local variables should be removed var mainSim2 = new Simulator(db.ConnectionString); } #pragma warning restore S1481 // Unused local variables should be removed /*mainSim2.MyGeneralConfig.PerformCleanUpChecks = "false"; * var toDelete = new List<DeviceActionGroup>(); * foreach (DeviceActionGroup deviceActionGroup in mainSim2.DeviceActionGroups.It) { * var actions = deviceActionGroup.GetDeviceActions(mainSim2.DeviceActions.It); * if(actions.Count == 0) * toDelete.Add(deviceActionGroup); * } * foreach (DeviceActionGroup deviceActionGroup in toDelete) { * mainSim2.DeviceActionGroups.DeleteItem(deviceActionGroup); * } * var dsttag = mainSim2.TraitTags.It.First(x => x.Name.StartsWith("Living ")); * foreach (ModularHousehold modularHousehold in mainSim2.ModularHouseholds.It) { * var toSet = new List<ModularHouseholdPerson>(); * foreach (ModularHouseholdPerson modularHouseholdPerson in modularHousehold.Persons) { * if (modularHouseholdPerson.TraitTag == null) { * toSet.Add(modularHouseholdPerson); * } * } * foreach (ModularHouseholdPerson person in toSet) { * modularHousehold.SwapPersons(person, person.Person, dsttag); * } * modularHousehold.SaveToDB(); * } * SimIntegrityChecker.Run(mainSim2);*/ wd.CleanUp(); } CleanTestBase.RunAutomatically(true); }
private static void TestImport([JetBrains.Annotations.NotNull] string srcfilename, [JetBrains.Annotations.NotNull] out Simulator mainsim, [JetBrains.Annotations.NotNull] out DatabaseMerger dbm, ClearMode clearTablesMode, bool checkrowcounts, [JetBrains.Annotations.NotNull] out DatabaseSetup db, bool clearDstFolder) { var acceptedUneven = new List <string> { "tblSettings", "tblOptions", "tblHHTTraits", // this is messed up since it would need a sorting of the householdtraits by subtraits "tblLPGVersion", // settings are not imported "tblHouseholdPlanEntries" //nobody cares about the household plans anymore }; if (clearDstFolder) { CleanTestBase.RunAutomatically(false); } DirectoryInfo di = new DirectoryInfo("."); Logger.Info("Current directory:" + di.FullName); var fis = di.GetFiles(); Logger.Info("Files in this directory:"); foreach (var fileInfo in fis) { Logger.Info(fileInfo.Name); } var fi = FindImportFile(srcfilename); db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()); var oldSim = new Simulator(db.ConnectionString); Dictionary <string, int> srctablerowcounts = null; switch (clearTablesMode) { case ClearMode.ClearTable: { var connectionstrOld = "Data Source=" + fi.FullName; srctablerowcounts = GetTableRowCounts(connectionstrOld); ClearAllTables(db); } break; case ClearMode.DeleteOnlyOneRow: { var connectionstrOld = "Data Source=" + fi.FullName; srctablerowcounts = GetTableRowCounts(connectionstrOld); DeleteOneElementFromAllTables(db); } break; case ClearMode.NoClearing: break; default: throw new ArgumentOutOfRangeException(nameof(clearTablesMode), clearTablesMode, null); } var mainSim = new Simulator(db.ConnectionString); dbm = new DatabaseMerger(mainSim); dbm.RunFindItems(fi.FullName, null); dbm.RunImport(null); foreach (var oldAff in oldSim.Affordances.MyItems) { foreach (var newAff in mainSim.Affordances.MyItems) { if (newAff.Name == oldAff.Name) { foreach (var oldDes in oldAff.AffordanceDesires) { var foundDesire = false; foreach (var newDes in newAff.AffordanceDesires) { if (oldDes.Desire.Name == newDes.Desire.Name) { foundDesire = true; } } if (!foundDesire) { Logger.Info("Missing affordance Desire in " + oldAff.Name + " " + oldDes.Desire.Name); } } } } } foreach (var hhg in oldSim.HouseholdTemplates.It) { Logger.Info("HHG 1:" + hhg.Name + " " + hhg.Entries.Count); } foreach (var hhg in mainSim.HouseholdTemplates.It) { Logger.Info("HHG 2:" + hhg.Name + " " + hhg.Entries.Count); } if (checkrowcounts && srctablerowcounts != null) { var dsttablerowcounts = GetTableRowCounts(db.ConnectionString); var errors = new List <string>(); foreach (var srctablerowcount in srctablerowcounts) { if (!acceptedUneven.Contains(srctablerowcount.Key)) { if (!dsttablerowcounts.ContainsKey(srctablerowcount.Key)) { errors.Add(srctablerowcount.Key + " is missing in the dst"); } if (dsttablerowcounts[srctablerowcount.Key] != srctablerowcount.Value) { errors.Add(srctablerowcount.Key + " is missing rows: dst = " + dsttablerowcounts[srctablerowcount.Key] + " src = " + srctablerowcount.Value); } } } var s = string.Empty; foreach (var error in errors) { Logger.Error(error); s += error + Environment.NewLine; } if (s.Length > 0) { throw new LPGException("Errors happened in " + s); } } mainsim = mainSim; // load again to see if anything gets deleted on loading Logger.Threshold = Severity.Debug; var oldSim2 = new Simulator(db.ConnectionString); foreach (var hhg in oldSim2.HouseholdTemplates.It) { Logger.Info("HHG 3:" + hhg.Name + " " + hhg.Entries.Count); } foreach (var hhg in mainSim.HouseholdTemplates.It) { Logger.Info("HHG 4:" + hhg.Name + " " + hhg.Entries.Count); } if (checkrowcounts) { var dsttablerowcounts = GetTableRowCounts(db.ConnectionString); var errors = new List <string>(); if (srctablerowcounts == null) { throw new LPGException("srctablerowcounts was null"); } foreach (var srctablerowcount in srctablerowcounts) { if (!acceptedUneven.Contains(srctablerowcount.Key)) { if (!dsttablerowcounts.ContainsKey(srctablerowcount.Key)) { errors.Add(srctablerowcount.Key + " is missing in the dst"); } if (dsttablerowcounts[srctablerowcount.Key] != srctablerowcount.Value) { errors.Add(srctablerowcount.Key + " is missing rows: dst = " + dsttablerowcounts[srctablerowcount.Key] + " src = " + srctablerowcount.Value); } } } var s = string.Empty; foreach (var error in errors) { Logger.Error(error); #pragma warning disable CC0039 // Don't concatenate strings in loops s += error + Environment.NewLine; #pragma warning restore CC0039 // Don't concatenate strings in loops } if (s.Length > 0) { throw new LPGException("Errors happened in " + s); } } db.Cleanup(); if (clearDstFolder) { CleanTestBase.RunAutomatically(true); } }