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); }
public void HouseDeviceOrphanCreatingTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(HouseType.TableName); db.ClearTable(HouseTypeDevice.TableName); var loadTypes = db.LoadLoadTypes(); var devices = new ObservableCollection <RealDevice>(); var deviceCategories = new ObservableCollection <DeviceCategory>(); var timeBasedProfiles = new ObservableCollection <TimeBasedProfile>(); var timeLimits = new ObservableCollection <TimeLimit>(); var variables = db.LoadVariables(); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, devices, loadTypes, deviceActionGroups); var energyStorages = db.LoadEnergyStorages(loadTypes, variables); var trafoDevices = db.LoadTransformationDevices(loadTypes, variables); var dateprofiles = db.LoadDateBasedProfiles(); var generators = db.LoadGenerators(loadTypes, dateprofiles); var houseTypes = new ObservableCollection <HouseType>(); var locations = db.LoadLocations(devices, deviceCategories, loadTypes); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); (houseTypes.Count).Should().Be(0); var housetype = new HouseType("haus1", "blub", 1000, 5, 10, loadTypes[0], db.ConnectionString, 1, 1, loadTypes[1], false, 0, false, 0, 1, 100, Guid.NewGuid().ToStrGuid()); housetype.SaveToDB(); var rd = new RealDevice("test", 1, "bla", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid()); rd.SaveToDB(); devices.Add(rd); var dt = new TimeLimit("blub", db.ConnectionString, Guid.NewGuid().ToStrGuid()); timeLimits.Add(dt); dt.SaveToDB(); var tp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative, "fake", Guid.NewGuid().ToStrGuid()); timeBasedProfiles.Add(tp); tp.SaveToDB(); housetype.AddHouseTypeDevice(rd, dt, tp, 1, loadTypes[0], locations[0], 0, VariableCondition.Equal, variables[0]); houseTypes.Clear(); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); (houseTypes.Count).Should().Be(1); var house3 = houseTypes[0]; (house3.HouseDevices.Count).Should().Be(1); db.ClearTable(HouseType.TableName); houseTypes.Clear(); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); (houseTypes.Count).Should().Be(0); db.Cleanup(); } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var persons = db.LoadPersons(); db.ClearTable(HouseholdTrait.TableName); var affordances = db.LoadAffordances(out var timeBasedProfiles, out _, out var deviceCategories, out var realDevices, out var desires, out var loadTypes, out var timeLimits, out ObservableCollection <DeviceAction> deviceActions, out ObservableCollection <DeviceActionGroup> deviceActionGroups, out var locations, out var variables, out _); var tags = db.LoadTraitTags(); var householdTraits = db.LoadHouseholdTraits(locations, affordances, realDevices, deviceCategories, timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, variables); var hht = new HouseholdTrait("bla", null, "blub", db.ConnectionString, "none", 1, 100, 10, 1, 1, TimeType.Day, 1, 1, TimeType.Day, 1, 0, EstimateType.Theoretical, "", Guid.NewGuid().ToStrGuid()); hht.SaveToDB(); householdTraits.Add(hht); var chht = new ModularHouseholdTrait(null, null, "hallo", db.ConnectionString, householdTraits[0], null, ModularHouseholdTrait.ModularHouseholdTraitAssignType.Age, Guid.NewGuid().ToStrGuid()); chht.DeleteFromDB(); chht.SaveToDB(); var chht1 = new ModularHouseholdTrait(null, null, "hallo2", db.ConnectionString, householdTraits[0], persons[0], ModularHouseholdTrait.ModularHouseholdTraitAssignType.Name, Guid.NewGuid().ToStrGuid()); chht1.SaveToDB(); chht1.DeleteFromDB(); db.Cleanup(); } }
public void HouseholdTemplateGenerationTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var gen = sim.HouseholdTemplates.CreateNewItem(db.ConnectionString); gen.NewHHName = "hh"; var entry = gen.AddEntry(sim.TraitTags[0], 5, 10); TraitTag tt = sim.TraitTags[0]; gen.AddPerson(sim.Persons[0], tt); entry.AddPerson(sim.Persons[0]); gen.SaveToDB(); gen.GenerateHouseholds(sim, true, new List <STTraitLimit>()); foreach (var household in gen.GeneratedHouseholds) { Logger.Info(household.Name); foreach (var trait in household.Traits) { Logger.Info("\t" + trait.HouseholdTrait.Name); } } db.Cleanup(); } }
public void ImportExistingModularTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var newHouseholdTemplate = sim.HouseholdTemplates.CreateNewItem(db.ConnectionString); newHouseholdTemplate.NewHHName = "hh"; var existingHouseholdTemplate = sim.ModularHouseholds.It.FirstOrDefault(x => x.Name.StartsWith("CHS01", StringComparison.Ordinal)); if (existingHouseholdTemplate == null) { throw new LPGException("Could not find chs01"); } newHouseholdTemplate.ImportExistingModularHouseholds(existingHouseholdTemplate); newHouseholdTemplate.SaveToDB(); newHouseholdTemplate.GenerateHouseholds(sim, true, new List <STTraitLimit>()); var total = 0; foreach (var entry in newHouseholdTemplate.Entries) { Logger.Info(entry.PrettyString); total += entry.TraitCountMax; } total.Should().BeGreaterOrEqualTo(existingHouseholdTemplate.Traits.Count); db.Cleanup(); } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(TemperatureProfile.TableName); db.ClearTable(TemperatureValue.TableName); var profiles = new ObservableCollection <TemperatureProfile>(); TemperatureProfile.LoadFromDatabase(profiles, db.ConnectionString, false); foreach (var temperaturProfile in profiles) { temperaturProfile.DeleteFromDB(); } var tp = new TemperatureProfile("tempprofil1", null, "desc1", db.ConnectionString, Guid.NewGuid().ToStrGuid()); tp.SaveToDB(); tp.AddTemperature(new DateTime(2011, 1, 1), 20); tp.AddTemperature(new DateTime(2011, 2, 1), 15); tp.SaveToDB(); TemperatureProfile.LoadFromDatabase(profiles, db.ConnectionString, false); (profiles.Count).Should().Be(1); (profiles[0].TemperatureValues.Count).Should().Be(2); profiles[0].DeleteOneTemperatur(profiles[0].TemperatureValues[0]); (profiles[0].TemperatureValues.Count).Should().Be(1); db.Cleanup(); } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var profiles = db.LoadTimeBasedProfiles(); var realDevices = db.LoadRealDevices(out var deviceCategories, out var loadTypes, profiles); var timeBasedProfiles = db.LoadTimeBasedProfiles(); var desires = db.LoadDesires(); var affordances = new ObservableCollection <Affordance>(); var subaffordances = new ObservableCollection <SubAffordance>(); var dateBasedProfiles = db.LoadDateBasedProfiles(); var timeLimits = db.LoadTimeLimits(dateBasedProfiles); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, realDevices, loadTypes, deviceActionGroups); var locations = db.LoadLocations(realDevices, deviceCategories, loadTypes); var variables = db.LoadVariables(); SubAffordance.LoadFromDatabase(subaffordances, db.ConnectionString, desires, false, locations, variables); Affordance.LoadFromDatabase(affordances, db.ConnectionString, timeBasedProfiles, deviceCategories, realDevices, desires, subaffordances, loadTypes, timeLimits, deviceActions, deviceActionGroups, locations, false, variables); db.Cleanup(); } }
public void LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var generators = new ObservableCollection <Generator>(); var loadTypes = db.LoadLoadTypes(); var dateBasedProfiles = db.LoadDateBasedProfiles(); Generator.LoadFromDatabase(generators, db.ConnectionString, loadTypes, dateBasedProfiles, false); // delete everything and check generators.Clear(); db.ClearTable(Generator.TableName); Generator.LoadFromDatabase(generators, db.ConnectionString, loadTypes, dateBasedProfiles, false); (generators.Count).Should().Be(0); // add one and load again var gen = new Generator("generator1", "gen1 desc", loadTypes[0], 5, dateBasedProfiles[0], db.ConnectionString, Guid.NewGuid().ToStrGuid()); gen.SaveToDB(); Generator.LoadFromDatabase(generators, db.ConnectionString, loadTypes, dateBasedProfiles, false); (generators.Count).Should().Be(1); // delete the loaded one generators[0].DeleteFromDB(); generators.Clear(); Generator.LoadFromDatabase(generators, db.ConnectionString, loadTypes, dateBasedProfiles, false); (generators.Count).Should().Be(0); db.Cleanup(); } }
public void TransportationDeviceTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(TransportationDeviceCategory.TableName); db.ClearTable(TransportationDevice.TableName); var tdc = new TransportationDeviceCategory("tdc1", null, db.ConnectionString, "desc", true, Guid.NewGuid().ToStrGuid()); tdc.SaveToDB(); VLoadType chargingloadType = (VLoadType)VLoadType.CreateNewItem(null, db.ConnectionString); chargingloadType.SaveToDB(); var sl = new TransportationDevice("name", null, db.ConnectionString, "desc", 1, SpeedUnit.Kmh, tdc, 100, 10, 10, 10, chargingloadType, Guid.NewGuid().ToStrGuid()); var slocs = new ObservableCollection <TransportationDevice>(); sl.SaveToDB(); var categories = new ObservableCollection <TransportationDeviceCategory> { tdc }; var loadTypes = new ObservableCollection <VLoadType>(); var mylt = new VLoadType("myloadtype", "", "W", "kWh", 1, 1, new TimeSpan(1, 0, 0), 1, db.ConnectionString, LoadTypePriority.RecommendedForHouseholds, true, Guid.NewGuid().ToStrGuid()); mylt.SaveToDB(); loadTypes.Add(mylt); loadTypes.Add(chargingloadType); sl.AddLoad(mylt, 10); TransportationDevice.LoadFromDatabase(slocs, db.ConnectionString, false, categories, loadTypes); db.Cleanup(); (slocs.Count).Should().Be(1); TransportationDevice td = slocs[0]; (td.ChargingLoadType).Should().Be(chargingloadType); } }
public void RealDeviceLoadCreationAndSaveTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var loadTypes = db.LoadLoadTypes(); var alldevices = new ObservableCollection <RealDevice>(); var deviceCategories = db.LoadDeviceCategories(alldevices, out var dcnone, false); var profiles = db.LoadTimeBasedProfiles(); RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles, false); db.ClearTable(RealDevice.TableName); db.ClearTable(RealDeviceLoadType.TableName); alldevices.Clear(); RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles, false); (alldevices.Count).Should().Be(0); var rd = new RealDevice("bla", 3, "p1", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid()); rd.SaveToDB(); alldevices.Clear(); RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles, false); (alldevices.Count).Should().Be(1); var rd2 = new RealDevice("bla2", 3, "p1", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid()); rd2.SaveToDB(); alldevices.Clear(); RealDevice.LoadFromDatabase(alldevices, deviceCategories, dcnone, db.ConnectionString, loadTypes, profiles, false); (alldevices.Count).Should().Be(2); db.Cleanup(); } }
public void HouseholdPlanEntryTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(HouseholdPlan.TableName); db.ClearTable(HouseholdPlanEntry.TableName); var timeBasedProfiles = db.LoadTimeBasedProfiles(); var desires = db.LoadDesires(); var persons = db.LoadPersons(); var realDevices = db.LoadRealDevices(out var deviceCategories, out _, out var loadTypes, timeBasedProfiles); var locations = db.LoadLocations(realDevices, deviceCategories, loadTypes); var dateBasedProfiles = db.LoadDateBasedProfiles(); var timeLimits = db.LoadTimeLimits(dateBasedProfiles); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, realDevices, loadTypes, deviceActionGroups); var variables = db.LoadVariables(); var affordances = db.LoadAffordances(timeBasedProfiles, out _, deviceCategories, realDevices, desires, loadTypes, timeLimits, deviceActions, deviceActionGroups, locations, variables); var sets = db.LoadAffordanceTaggingSets(affordances, loadTypes); var tags = db.LoadTraitTags(); var traits = db.LoadHouseholdTraits(locations, affordances, realDevices, deviceCategories, timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, variables); var selections = db.LoadDeviceSelections(deviceCategories, realDevices, deviceActions, deviceActionGroups); var vacations = db.LoadVacations(); var hhTags = db.LoadHouseholdTags(); var modularHouseholds = db.LoadModularHouseholds(traits, selections, persons, vacations, hhTags, tags); var plans = new ObservableCollection <HouseholdPlan>(); HouseholdPlan.LoadFromDatabase(plans, db.ConnectionString, false, persons, sets, modularHouseholds); var hh = modularHouseholds[0]; var set = sets[0]; var hhp = new HouseholdPlan("test", set, hh, "blub", db.ConnectionString, System.Guid.NewGuid().ToStrGuid()); hhp.SaveToDB(); hhp.AddNewEntry(hh.Persons[0].Person, set.Tags[0], 1, 1, TimeType.Day); hhp.SaveToDB(); plans.Clear(); HouseholdPlan.LoadFromDatabase(plans, db.ConnectionString, false, persons, sets, modularHouseholds); hhp = plans[0]; hhp.CalcObject.Should().Be(hh); hhp.AffordanceTaggingSet.Should().Be(set); hhp.Entries.Count.Should().Be(1); hhp.DeleteEntry(hhp.Entries[0]); hhp.DeleteFromDB(); plans.Clear(); HouseholdPlan.LoadFromDatabase(plans, db.ConnectionString, false, persons, sets, modularHouseholds); plans.Count.Should().Be(0); db.Cleanup(); } }
public void SiteLocationTest() { using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(Site.TableName); db.ClearTable(SiteLocation.TableName); Location loc = new Location("loc1", null, db.ConnectionString, Guid.NewGuid().ToStrGuid()); loc.SaveToDB(); Site site = new Site("site1", null, db.ConnectionString, "desc", Guid.NewGuid().ToStrGuid()); TransportationDeviceCategory cat = new TransportationDeviceCategory("bla", 1, db.ConnectionString, "desc", true, Guid.NewGuid().ToStrGuid()); VLoadType lt = new VLoadType("mylt", "desc", "w", "kwh", 1, 1, new TimeSpan(0, 1, 0), 1, db.ConnectionString, LoadTypePriority.All, false, Guid.NewGuid().ToStrGuid()); lt.SaveToDB(); cat.SaveToDB(); site.SaveToDB(); //site.AddChargingStation(cat, lt, 1); site.AddLocation(loc); //loading ObservableCollection <Site> slocs = new ObservableCollection <Site>(); ObservableCollection <Location> locs = new ObservableCollection <Location> { loc }; Site.LoadFromDatabase(slocs, db.ConnectionString, false, locs); //Site mysite = slocs[0]; //(mysite.ChargingStations.Count).Should().Be(1); db.Cleanup(); (slocs.Count).Should().Be(1); } }
public void GetCalcManagerHouseTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.OnlyOverallSum); //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.Houses[sim.Houses.MyItems.Count - 1], EnergyIntensityType.Random, false, null, LoadTypePriority.RecommendedForHouses, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(ReportCancelFunc); db.Cleanup(); } wd.CleanUp(); } }
public void TimeLimitLoadCreationAndSaveTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(GeographicLocation.TableName); db.ClearTable(GeographicLocHoliday.TableName); var holidays = db.LoadHolidays(); var geolocs = new ObservableCollection <GeographicLocation>(); var dbp = db.LoadDateBasedProfiles(); var timeLimits = db.LoadTimeLimits(dbp); GeographicLocation.LoadFromDatabase(geolocs, db.ConnectionString, holidays, timeLimits, false); (geolocs.Count).Should().Be(0); var geoloc = new GeographicLocation("bla", 1, 2, 3, 4, 5, 6, "North", "West", db.ConnectionString, timeLimits[0], System.Guid.NewGuid().ToStrGuid()); geoloc.SaveToDB(); geoloc.AddHoliday(holidays[0]); GeographicLocation.LoadFromDatabase(geolocs, db.ConnectionString, holidays, timeLimits, false); (geolocs.Count).Should().Be(1); (geolocs[0].Holidays.Count).Should().Be(1); var gl = geolocs[0]; ("bla").Should().Be(gl.Name); gl.DeleteFromDB(); geolocs.Clear(); GeographicLocation.LoadFromDatabase(geolocs, db.ConnectionString, holidays, timeLimits, false); (geolocs.Count).Should().Be(0); db.Cleanup(); } }
public void HolidayProbabilitesCalculateTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { // test the normal loading var holidays = new ObservableCollection <Holiday>(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); // delete everything and check holidays.Clear(); db.ClearTable(Holiday.TableName); db.ClearTable(HolidayDate.TableName); db.ClearTable(HolidayProbabilities.TableName); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(0); // add one and load again var hd = new Holiday("my holiday", "blub", db.ConnectionString, Guid.NewGuid().ToStrGuid()); hd.SaveToDB(); hd.ProbMonday.Tuesday = 100; hd.ProbMonday.Wednesday = 0; var holiday = new DateTime(2014, 2, 17); hd.AddNewDate(holiday); hd.SaveToDB(); var r = new Random(1); var dts = hd.GetListOfWorkFreeDates(r, "test"); (dts.Count).Should().Be(2); Assert.True(dts.ContainsKey(holiday)); Assert.True(dts.ContainsKey(holiday.AddDays(1))); db.Cleanup(); } }
public void DeviceActionTest() { using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { ObservableCollection <TimeBasedProfile> profiles = db.LoadTimeBasedProfiles(); ObservableCollection <RealDevice> devices = db.LoadRealDevices(out _, out var loadTypes, profiles); ObservableCollection <DeviceAction> das = new ObservableCollection <DeviceAction>(); DeviceActionGroup dag = new DeviceActionGroup("blub", db.ConnectionString, "desc", Guid.NewGuid().ToStrGuid()); dag.SaveToDB(); ObservableCollection <DeviceActionGroup> dags = db.LoadDeviceActionGroups(); // try loading DeviceAction.LoadFromDatabase(das, db.ConnectionString, profiles, devices, loadTypes, dags, false); // clear db db.ClearTable(DeviceActionGroup.TableName); db.ClearTable(DeviceAction.TableName); db.ClearTable(DeviceActionProfile.TableName); // create new one, save, load DeviceAction da = new DeviceAction("bla", null, "desc", db.ConnectionString, dag, devices[0], Guid.NewGuid().ToStrGuid()); da.SaveToDB(); da.AddDeviceProfile(profiles[0], 1, loadTypes[0], 1); das.Clear(); DeviceAction.LoadFromDatabase(das, db.ConnectionString, profiles, devices, loadTypes, dags, false); (das.Count).Should().Be(1); (das[0].Profiles.Count).Should().Be(1); das[0].DeleteProfileFromDB(das[0].Profiles[0]); (das[0].Profiles.Count).Should().Be(0); das[0].DeleteFromDB(); das.Clear(); DeviceAction.LoadFromDatabase(das, db.ConnectionString, profiles, devices, loadTypes, dags, false); (das.Count).Should().Be(0); db.Cleanup(); } }
public void HolidayProbabilitesSaveTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { // test the normal loading var holidays = new ObservableCollection <Holiday>(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); // delete everything and check holidays.Clear(); db.ClearTable(Holiday.TableName); db.ClearTable(HolidayDate.TableName); db.ClearTable(HolidayProbabilities.TableName); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(0); // add one and load again var hd = new Holiday("my holiday", "blub", db.ConnectionString, Guid.NewGuid().ToStrGuid()); hd.SaveToDB(); hd.ProbMonday.Monday = 5; hd.SaveToDB(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(1); (holidays[0].ProbMonday.Monday).Should().Be(5); // delete the loaded one holidays[0].DeleteFromDB(); holidays.Clear(); Holiday.LoadFromDatabase(holidays, db.ConnectionString, false); (holidays.Count).Should().Be(0); db.Cleanup(); } }
public void CalculateAverageEnergyUseTestAbsoluteProfile() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Config.IsInUnitTesting = true; var rd2 = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid()); var lt = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1, db.ConnectionString, LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid()); lt.SaveToDB(); rd2.SaveToDB(); rd2.AddLoad(lt, 666, 0, 0); var tp = new TimeBasedProfile("tp", null, db.ConnectionString, TimeProfileType.Absolute, "fake", Guid.NewGuid().ToStrGuid()); tp.SaveToDB(); tp.AddNewTimepoint(new TimeSpan(0, 0, 0), 100, false); tp.AddNewTimepoint(new TimeSpan(0, 2, 0), 0, false); var allActions = new ObservableCollection <DeviceAction>(); var res = rd2.CalculateAverageEnergyUse(lt, allActions, tp, 1, 1); foreach (var keyValuePair in res) { Logger.Info(keyValuePair.Item1 + ": " + keyValuePair.Item2); } (res.Count).Should().Be(1); var first = res.First(); (first.Item2).Should().Be(200); db.Cleanup(); } }
public void MakeDegreeDaysTest3Years() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var temperaturProfiles = db.LoadTemperatureProfiles(); var startTime = new DateTime(2012, 1, 1); var endTime = new DateTime(2014, 12, 31); var ldd = DbCalcDegreeHour.GetCalcDegreeHours(temperaturProfiles[0], startTime, endTime, 19, 10000, false, 0); double sumHeating = 0; double sumPercentages = 0; var temperatures = temperaturProfiles[0].GetTemperatureArray(startTime, endTime, new TimeSpan(1, 0, 0)); for (var i = 0; i < temperatures.Length; i++) { Math.Abs(ldd[i].AverageTemperature - temperatures[i]).Should().BeLessThan(0.001); } foreach (var day in ldd) { sumHeating += day.CoolingAmount; sumPercentages += day.Percentage; } Math.Abs(30000 - sumHeating).Should().BeLessThan(0.001); Math.Abs(3 - sumPercentages).Should().BeLessThan(0.001); db.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 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 TravelRouteSetTest() { using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(TravelRouteSet.TableName); db.ClearTable(TravelRouteSetEntry.TableName); TravelRouteSet set = new TravelRouteSet("set1", null, db.ConnectionString, "desc", System.Guid.NewGuid().ToStrGuid()); set.SaveToDB(); Site a = new Site("a", null, db.ConnectionString, "desc", System.Guid.NewGuid().ToStrGuid()); a.SaveToDB(); Site b = new Site("b", null, db.ConnectionString, "desc", System.Guid.NewGuid().ToStrGuid()); b.SaveToDB(); TravelRoute route = new TravelRoute(null, db.ConnectionString, "routename", "routedesc", a, b, System.Guid.NewGuid().ToStrGuid(), null); route.SaveToDB(); set.AddRoute(route); //loading ObservableCollection <TravelRoute> routes = new ObservableCollection <TravelRoute> { route }; ObservableCollection <TravelRouteSet> sets = new ObservableCollection <TravelRouteSet>(); TravelRouteSet.LoadFromDatabase(sets, db.ConnectionString, false, routes); db.Cleanup(); (sets.Count).Should().Be(1); } }
public void HouseholdTemplateTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(HouseholdTemplate.TableName); db.ClearTable(HHTemplateEntry.TableName); db.ClearTable(HHTemplateVacation.TableName); db.ClearTable(HHTemplateEntryPerson.TableName); db.ClearTable(HHTemplateTag.TableName); var sim = new Simulator(db.ConnectionString); var hhtemplate = sim.HouseholdTemplates.CreateNewItem(db.ConnectionString); hhtemplate.SaveToDB(); hhtemplate.AddEntry(sim.TraitTags[0], 1, 100); hhtemplate.AddPerson(sim.Persons[0], sim.TraitTags[0]); sim.HouseholdTags.CreateNewItem(sim.ConnectionString); hhtemplate.AddTemplateTag(sim.HouseholdTags[0]); (sim.HouseholdTemplates.It.Count).Should().Be(1); (hhtemplate.Entries.Count).Should().Be(1); var sim2 = new Simulator(db.ConnectionString); (sim2.HouseholdTemplates.It.Count).Should().Be(1); (sim2.HouseholdTemplates[0].Entries.Count).Should().Be(1); (sim2.HouseholdTemplates[0].Persons.Count).Should().Be(1); (sim2.HouseholdTemplates[0].TemplateTags.Count).Should().Be(1); db.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 LoadFromDatabaseTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var desires = new ObservableCollection <Desire>(); Desire.LoadFromDatabase(desires, db.ConnectionString, false); var subAffordances = new ObservableCollection <SubAffordance>(); var locations = new ObservableCollection <Location>(); var variables = new ObservableCollection <Variable>(); SubAffordance.LoadFromDatabase(subAffordances, db.ConnectionString, desires, false, locations, variables); var affordances = new ObservableCollection <Affordance>(); var affordanceSubAffordances = new ObservableCollection <AffordanceSubAffordance>(); var tbp = new ObservableCollection <TimeBasedProfile>(); var dateBasedProfiles = db.LoadDateBasedProfiles(); var timeLimits = db.LoadTimeLimits(dateBasedProfiles); var aic = new AllItemCollections(timeProfiles: tbp, timeLimits: timeLimits); DBBase.LoadAllFromDatabase(affordances, db.ConnectionString, Affordance.TableName, Affordance.AssignFields, aic, false, true); AffordanceSubAffordance.LoadFromDatabase(affordanceSubAffordances, db.ConnectionString, affordances, subAffordances, false); affordanceSubAffordances.Count.Should().BeGreaterThan(1); db.ClearTable(AffordanceSubAffordance.TableName); affordanceSubAffordances.Clear(); AffordanceSubAffordance.LoadFromDatabase(affordanceSubAffordances, db.ConnectionString, affordances, subAffordances, false); affordanceSubAffordances.Count.Should().Be(0); db.Cleanup(); } }
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 HouseTypeLoadCreationAndSave2Test() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(House.TableName); db.ClearTable(HouseTypeDevice.TableName); db.ClearTable(HouseHousehold.TableName); var houses = new CategoryDBBase <House>("blub"); houses.CreateNewItem(db.ConnectionString); var devices = new ObservableCollection <RealDevice>(); var deviceCategories = new ObservableCollection <DeviceCategory>(); var timeBasedProfiles = new ObservableCollection <TimeBasedProfile>(); var timeLimits = new ObservableCollection <TimeLimit>(); var loadTypes = db.LoadLoadTypes(); var variables = db.LoadVariables(); var energyStorages = db.LoadEnergyStorages(loadTypes, variables); var trafoDevices = db.LoadTransformationDevices(loadTypes, variables); var dateprofiles = db.LoadDateBasedProfiles(); var generators = db.LoadGenerators(loadTypes, dateprofiles); var houseTypes = new ObservableCollection <HouseType>(); var locations = db.LoadLocations(devices, deviceCategories, loadTypes); var deviceActionGroups = db.LoadDeviceActionGroups(); var deviceActions = db.LoadDeviceActions(timeBasedProfiles, devices, loadTypes, deviceActionGroups); HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles, timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions, deviceActionGroups, variables); houseTypes.Count.Should().BeGreaterOrEqualTo(1); db.Cleanup(); } }
public void TryCleaningEachTable() { CleanTestBase.RunAutomatically(false); using (var db1 = new DatabaseSetup("TryCleaningEach")) { var alltables = LongtermTests.GetTableList(db1); db1.Cleanup(); for (var index = 0; index < alltables.Count; index++) { Logger.Info("processing table " + index + " out of " + alltables.Count); var table = alltables[index]; if (table == "tblLPGVersion") { continue; } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { DBBase.HideDeleteMessages(); Command.HideDeleteMessages(); db.ClearTable(table); var oldSim = new Simulator(db.ConnectionString); // need to load it for testing Logger.Info(oldSim.ModularHouseholds.It.Count.ToString(CultureInfo.InvariantCulture)); db.Cleanup(); } } } CleanTestBase.RunAutomatically(true); }
public void CheckSimIntegrityCheckerBenchmark() { CleanTestBase.RunAutomatically(false); const int runcount = 1; using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Simulator sim = new Simulator(db.ConnectionString) { MyGeneralConfig = { PerformCleanUpChecks = "True" } }; sim.Should().NotBeNull(); DateTime start = DateTime.Now; for (int i = 0; i < runcount; i++) { SimIntegrityChecker.Run(sim); } DateTime end = DateTime.Now; var duration = end - start; Logger.Info("Duration was:" + duration.TotalMilliseconds / runcount + " milliseconds"); db.Cleanup(); } CleanTestBase.RunAutomatically(true); }
public void MakeDegreeDaysTestWithPrecalcPeriod() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var temperaturProfiles = db.LoadTemperatureProfiles(); var startTime = new DateTime(2011, 12, 27); var endTime = new DateTime(2012, 12, 31); var ldd = MakeDegreeDaysClass.MakeDegreeDays(temperaturProfiles[0], startTime, endTime, 15, 20, 10000, false, 0); double sumHeating = 0; double sumPercentages = 0; var temperatures = temperaturProfiles[0].GetTemperatureArray(startTime, endTime, new TimeSpan(1, 0, 0, 0)); for (var i = 0; i < temperatures.Length; i++) { Math.Abs(ldd[i].AverageTemperature - temperatures[i]).Should().BeLessThan(0.001); } foreach (var day in ldd) { if (day.Date.Year != 2012) { continue; //only count values from 2012 } sumHeating += day.HeatingAmount; sumPercentages += day.Percentage; } Math.Abs(10000 - sumHeating).Should().BeLessThan(0.001); Math.Abs(1 - sumPercentages).Should().BeLessThan(0.001); db.Cleanup(); } }