private static void TestImport([JetBrains.Annotations.NotNull] string path, [JetBrains.Annotations.NotNull] out Simulator mainsim, [JetBrains.Annotations.NotNull] out Database.DatabaseMerger.DatabaseMerger dbm) { var di = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), path)); Logger.Debug(di.FullName); var fi = FindImportFiles(path); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var newpath = Path.Combine(wd.WorkingDirectory, "mergertest.db3"); File.Copy(fi.FullName, newpath); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(newpath, null); dbm.RunImport(null); mainsim = mainSim; db.Cleanup(); } wd.CleanUp(); } }
public void TestImportWithHouseholdTemplateDelete880() { const string srcFileName = "profilegenerator880.db3"; string sourcepath = DatabaseSetup.GetImportFileFullPath(srcFileName); if (!File.Exists(sourcepath)) { throw new LPGException("Missing file!"); } using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var newpath = Path.Combine(wd.WorkingDirectory, "mergertest.db3"); File.Copy(sourcepath, newpath); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); db.ClearTable(HouseholdTemplate.TableName); Database.DatabaseMerger.DatabaseMerger dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(newpath, null); dbm.RunImport(null); db.Cleanup(); } wd.CleanUp(); } }
public void RunTestCurrentDeviceCategory() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { const string path = "profilegeneratorcopy.db3"; if (File.Exists(path)) { File.Delete(path); } string sourcefile = DatabaseSetup.GetSourcepath(null); File.Copy(sourcefile, path); if (!File.Exists(path)) { throw new LPGException("Missing file!"); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(DeviceCategory.TableName); db.ClearTable(AffordanceDevice.TableName); var mainSim = new Simulator(db.ConnectionString); var dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(path, null); foreach (var dbBase in dbm.ItemsToImport) { Logger.Error(dbBase.Entry.Name + " " + dbBase.Import); dbBase.Import = true; } dbm.RunImport(null); var newCategories = mainSim.DeviceCategories.CollectAllDBBaseItems(); var oldCategories = dbm.OldSimulator.DeviceCategories.CollectAllDBBaseItems(); var newcats = new Dictionary <string, DeviceCategory>(); foreach (var newCategory in newCategories) { var cat = (DeviceCategory)newCategory; newcats.Add(cat.ShortName, cat); } foreach (var oldCategory in oldCategories) { Logger.Debug("checking: " + oldCategory.Name); var oldCat = (DeviceCategory)oldCategory; newcats.ContainsKey(oldCat.ShortName).Should().BeTrue(); var newcat = newcats[oldCat.ShortName]; newcat.FullPath.Should().Be(oldCat.FullPath); newcat.ParentCategory?.Name.Should().Be(oldCat.ParentCategory?.Name); } db.Cleanup(); } wd.CleanUp(throwAllErrors: false); } }
public void RunTestCurrentDeviceActions() { using (var dbOriginal = new DatabaseSetup("RunTestCurrentDeviceActionsOriginal")) { var originalSim = new Simulator(dbOriginal.ConnectionString); const string path = "profilegeneratorcopy.db3"; if (File.Exists(path)) { File.Delete(path); } File.Copy(DatabaseSetup.GetSourcepath(null), path); if (!File.Exists(path)) { throw new LPGException("Missing file!"); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(DeviceAction.TableName); db.ClearTable(DeviceActionGroup.TableName); db.ClearTable(DeviceActionProfile.TableName); var mainSim = new Simulator(db.ConnectionString); var dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(path, null); foreach (var dbBase in dbm.ItemsToImport) { Logger.Error(dbBase.Entry.Name + " " + dbBase.Import); dbBase.Import = true; } dbm.RunImport(null); var newActions = mainSim.DeviceActions.It; var nullOldcount = 0; foreach (var oldAction in originalSim.DeviceActions.It) { if (oldAction.DeviceActionGroup == null) { nullOldcount++; } var newAction = newActions.First(x => x.Name == oldAction.Name); if (oldAction.DeviceActionGroup != null) { oldAction.DeviceActionGroup.Name.Should().Be(newAction.DeviceActionGroup?.Name); } } Logger.Info("oldAction total:" + originalSim.DeviceActions.It.Count + " null:" + nullOldcount); dbOriginal.Cleanup(); db.Cleanup(); } } }
public void RunTestCurrentTimeLimits() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var path = Path.Combine(wd.WorkingDirectory, "profilegeneratorcopy.db3"); var sourcepath = DatabaseSetup.GetSourcepath(null); File.Copy(sourcepath, path); if (!File.Exists(path)) { throw new LPGException("Missing file!"); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); mainSim.TimeLimits.DeleteItem(mainSim.TimeLimits[0]); mainSim.TimeLimits.DeleteItem(mainSim.TimeLimits[1]); var dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(path, null); Logger.Debug("importing:"); foreach (var dbBase in dbm.ItemsToImport) { Logger.Debug("importing:" + Environment.NewLine + dbBase.Entry.Name + " " + dbBase.Import); dbBase.Import = true; } dbm.RunImport(null); var allTimeLimits = new Dictionary <string, bool>(); foreach (var timeLimit in mainSim.TimeLimits.MyItems) { allTimeLimits.Add(timeLimit.CombineCompleteString(), true); } foreach (var timeLimit in dbm.OldSimulator.TimeLimits.MyItems) { allTimeLimits.ContainsKey(timeLimit.CombineCompleteString()).Should().BeTrue(); } db.Cleanup(); } wd.CleanUp(); } }