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();
            }
        }
Beispiel #2
0
 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();
     }
 }
Beispiel #3
0
        public void VacationTest()
        {
            using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(Vacation.TableName);
                db.ClearTable(VacationTime.TableName);
                Vacation vac = new Vacation("name", null, db.ConnectionString, 1, 99, CreationType.ManuallyCreated, Guid.NewGuid().ToStrGuid());
                DateTime dt  = new DateTime(2010, 1, 1);
                vac.SaveToDB();
                vac.AddVacationTime(dt, dt, VacationType.GoAway);
                ObservableCollection <Vacation> vacations = new ObservableCollection <Vacation>();
                Vacation.LoadFromDatabase(vacations, db.ConnectionString, false);
                (vacations.Count).Should().Be(1);
                Vacation v1 = vacations[0];
                (v1.Name).Should().Be("name");
                (v1.VacationTimes.Count).Should().Be(1);
                VacationTime vt = v1.VacationTimes[0];
                (vt.Start).Should().Be(dt);
                (vt.End).Should().Be(dt);
                v1.DeleteVacationTime(vt);
#pragma warning disable S1854   // Dead stores should be removed
#pragma warning disable IDE0059 // Value assigned to symbol is never used
                v1 = null;      // to enable garbage collection immidiately
#pragma warning restore IDE0059 // Value assigned to symbol is never used
#pragma warning restore S1854   // Dead stores should be removed
                ObservableCollection <Vacation> vacations1 = new ObservableCollection <Vacation>();
                Vacation.LoadFromDatabase(vacations1, db.ConnectionString, false);
                (vacations.Count).Should().Be(1);
                Vacation v2 = vacations[0];
                (v2.Name).Should().Be("name");
                (v2.VacationTimes.Count).Should().Be(0);

                db.Cleanup();
            }
        }
        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();
            }
        }
Beispiel #5
0
 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();
     }
 }
Beispiel #6
0
 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();
     }
 }
Beispiel #7
0
        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 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);
            }
        }
Beispiel #9
0
 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();
     }
 }
Beispiel #10
0
        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 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();
            }
        }
Beispiel #12
0
        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();
            }
        }
Beispiel #13
0
 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);
     }
 }
Beispiel #14
0
        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();
            }
        }
Beispiel #15
0
 public void LoadFromDatabaseTest()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         var storages  = new ObservableCollection <EnergyStorage>();
         var loadTypes = db.LoadLoadTypes();
         var variables = db.LoadVariables();
         EnergyStorage.LoadFromDatabase(storages, db.ConnectionString, loadTypes, variables, false);
         // delete everything and check
         storages.Clear();
         db.ClearTable(EnergyStorage.TableName);
         db.ClearTable(EnergyStorageSignal.TableName);
         EnergyStorage.LoadFromDatabase(storages, db.ConnectionString, loadTypes, variables, false);
         (storages.Count).Should().Be(0);
         // add one and load again
         var stor = new EnergyStorage("tdlt", "desc", loadTypes[0], 10, 10, 0, 10, 0, 10,
                                      db.ConnectionString, Guid.NewGuid().ToStrGuid());
         stor.SaveToDB();
         stor.AddSignal(variables[0], 100, 50, 60);
         EnergyStorage.LoadFromDatabase(storages, db.ConnectionString, loadTypes, variables, false);
         (storages.Count).Should().Be(1);
         (storages[0].Signals.Count).Should().Be(1);
         // delete the loaded one
         storages[0].DeleteFromDB();
         storages.Clear();
         EnergyStorage.LoadFromDatabase(storages, db.ConnectionString, loadTypes, variables, false);
         (storages.Count).Should().Be(0);
         db.Cleanup();
     }
 }
        public void HouseEnergyStorageLoadCreationAndSaveTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(HouseType.TableName);
                db.ClearTable(HouseTypeDevice.TableName);
                db.ClearTable(HouseTypeTransformationDevice.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 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().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();

                HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles,
                                           timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions,
                                           deviceActionGroups,
                                           variables);
                (houseTypes.Count).Should().Be(1);
                var house2 = houseTypes[0];
                (house2.HouseTransformationDevices.Count).Should().Be(0);
                var es = energyStorages[0];
                house2.AddEnergyStorage(es);
                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.HouseEnergyStorages.Count).Should().Be(1);
                house3.DeleteHouseEnergyStorage(house3.HouseEnergyStorages[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 house4 = houseTypes[0];
                (house4.HouseEnergyStorages.Count).Should().Be(0);
                db.Cleanup();
            }
        }
Beispiel #17
0
        public void TravelRouteTest()
        {
            using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(TravelRoute.TableName);
                db.ClearTable(TravelRouteStep.TableName);
                Location loc = new Location("loc1", null, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                loc.SaveToDB();
                Site siteA = new Site("site1", null, db.ConnectionString, "desc", Guid.NewGuid().ToStrGuid());
                siteA.SaveToDB();

                Site siteB = new Site("site2", null, db.ConnectionString, "desc", Guid.NewGuid().ToStrGuid());
                siteB.SaveToDB();

                TransportationDeviceCategory td = new
                                                  TransportationDeviceCategory("transportationdevicecategory", null, db.ConnectionString, "desc", true, Guid.NewGuid().ToStrGuid());
                td.SaveToDB();
                TravelRoute tr = new TravelRoute(null, db.ConnectionString, "route", "desc", siteA, siteB,
                                                 Guid.NewGuid().ToStrGuid(), null);
                tr.SaveToDB();
                tr.AddStep("name1", td, 100, 1, "key1");
                tr.AddStep("name3", td, 100, 10, "key3");
                tr.AddStep("name2", td, 100, 2, "key2");
                //test the  sorting of steps while adding based on step number
                ("name1").Should().Be(tr.Steps[0].Name);
                ("name2").Should().Be(tr.Steps[1].Name);
                ("name3").Should().Be(tr.Steps[2].Name);
                ("key1").Should().Be(tr.Steps[0].StepKey);
                ("key2").Should().Be(tr.Steps[1].StepKey);
                ("key3").Should().Be(tr.Steps[2].StepKey);
                foreach (TravelRouteStep step in tr.Steps)
                {
                    Logger.Info(step.Name);
                }
                //loading
                ObservableCollection <Site> sites = new ObservableCollection <Site>
                {
                    siteA,
                    siteB
                };
                ObservableCollection <TransportationDeviceCategory> transportationDeviceCategories = new ObservableCollection <TransportationDeviceCategory>
                {
                    td
                };
                ObservableCollection <TravelRoute> routes = new ObservableCollection <TravelRoute>();
                TravelRoute.LoadFromDatabase(routes, db.ConnectionString, false, transportationDeviceCategories, sites);
                (routes.Count).Should().Be(1);
                tr = routes[0];
                ("name1").Should().Be(tr.Steps[0].Name);
                ("name2").Should().Be(tr.Steps[1].Name);
                ("name3").Should().Be(tr.Steps[2].Name);
                ("key1").Should().Be(tr.Steps[0].StepKey);
                ("key2").Should().Be(tr.Steps[1].StepKey);
                ("key3").Should().Be(tr.Steps[2].StepKey);
                db.Cleanup();
            }
        }
        public void HouseLoadCreationAndSaveTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Logger.Threshold = Severity.Warning;
                db.ClearTable(HouseType.TableName);
                db.ClearTable(HouseTypeDevice.TableName);
                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 loadTypes         = db.LoadLoadTypes();
                var energyStorages    = db.LoadEnergyStorages(loadTypes, variables);
                var trafoDevices      = db.LoadTransformationDevices(loadTypes,
                                                                     variables);
                var dateprofiles = db.LoadDateBasedProfiles();
                var generators   = db.LoadGenerators(loadTypes, dateprofiles);

                var locations          = db.LoadLocations(devices, deviceCategories, loadTypes);
                var deviceActionGroups = db.LoadDeviceActionGroups();
                var deviceActions      = db.LoadDeviceActions(timeBasedProfiles,
                                                              devices, loadTypes, deviceActionGroups);
                var dt = new TimeLimit("blub", db.ConnectionString, Guid.NewGuid().ToStrGuid());
                dt.SaveToDB();
                timeLimits.Add(dt);
                var rd = new RealDevice("blub", 1, string.Empty, null, string.Empty, true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd.SaveToDB();
                devices.Add(rd);
                var tbp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative,
                                               "fake", Guid.NewGuid().ToStrGuid());
                tbp.SaveToDB();
                timeBasedProfiles.Add(tbp);
                var tempP = new TemperatureProfile("blub", null, string.Empty, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                tempP.SaveToDB();
                var houseTypes = new ObservableCollection <HouseType>();
                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();
                housetype.AddHouseTypeDevice(rd, dt, tbp, 1, loadTypes[0], locations[0], 0, VariableCondition.Equal,
                                             variables[0]);
                HouseType.LoadFromDatabase(houseTypes, db.ConnectionString, devices, deviceCategories, timeBasedProfiles,
                                           timeLimits, loadTypes, trafoDevices, energyStorages, generators, false, locations, deviceActions,
                                           deviceActionGroups, variables);
                (houseTypes.Count).Should().Be(1);
                (houseTypes[0].HouseDevices.Count).Should().Be(1);
                var house2 = houseTypes[0];
                (house2.Name).Should().Be("haus1");
                (house2.Description).Should().Be("blub");
                db.Cleanup();
            }
        }
Beispiel #19
0
        public void DeviceSelectionTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(DeviceSelection.TableName);
                db.ClearTable(DeviceSelectionItem.TableName);
                db.ClearTable(DeviceSelectionDeviceAction.TableName);
                var timeBasedProfiles = db.LoadTimeBasedProfiles();
                var devices           = db.LoadRealDevices(out var deviceCategories, out _, out var loadTypes,
                                                           timeBasedProfiles);

                var deviceSelections = new ObservableCollection <DeviceSelection>();
                var groups           = db.LoadDeviceActionGroups();
                var deviceActions    = db.LoadDeviceActions(timeBasedProfiles, devices,
                                                            loadTypes, groups);
                DeviceSelection.LoadFromDatabase(deviceSelections, db.ConnectionString, deviceCategories, devices,
                                                 deviceActions, groups, false);

                var ds = new DeviceSelection("blub", null, "bla", db.ConnectionString, Guid.NewGuid().ToStrGuid());
                ds.SaveToDB();
                ds.AddItem(deviceCategories[0], devices[0]);

                ds.AddAction(groups[0], deviceActions[0]);
                ds.SaveToDB();
                (ds.Items.Count).Should().Be(1);
                (ds.Actions.Count).Should().Be(1);

                // loading test
                deviceSelections = new ObservableCollection <DeviceSelection>();
                DeviceSelection.LoadFromDatabase(deviceSelections, db.ConnectionString, deviceCategories, devices,
                                                 deviceActions, groups, false);

                ds = deviceSelections[0];
                (ds.Actions.Count).Should().Be(1);
                (ds.Items.Count).Should().Be(1);
                ds.DeleteItemFromDB(ds.Items[0]);
                ds.DeleteActionFromDB(ds.Actions[0]);
                (ds.Items.Count).Should().Be(0);
                (ds.Actions.Count).Should().Be(0);

                // deleting and loading
                deviceSelections = new ObservableCollection <DeviceSelection>();
                DeviceSelection.LoadFromDatabase(deviceSelections, db.ConnectionString, deviceCategories, devices,
                                                 deviceActions, groups, false);
                (ds.Items.Count).Should().Be(0);
                ds = deviceSelections[0];
                ds.DeleteFromDB();

                // deleting
                deviceSelections = new ObservableCollection <DeviceSelection>();
                DeviceSelection.LoadFromDatabase(deviceSelections, db.ConnectionString, deviceCategories, devices,
                                                 deviceActions, groups, false);
                (deviceSelections.Count).Should().Be(0);
                db.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);
            }
        }
Beispiel #21
0
        public void HouseholdTemplateTest2()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(HouseholdTemplate.TableName);
                db.ClearTable(HHTemplateEntry.TableName);
                db.ClearTable(HHTemplateEntryPerson.TableName);
                var cat = new CategoryDBBase <HouseholdTemplate>("Household Generator");

                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 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();
                var affordances = db.LoadAffordances(timeBasedProfiles, out _,
                                                     deviceCategories, realDevices, desires, loadTypes, timeLimits, deviceActions, deviceActionGroups,
                                                     locations, variables);

                var traittags = db.LoadTraitTags();
                var traits    = db.LoadHouseholdTraits(locations, affordances, realDevices,
                                                       deviceCategories, timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups,
                                                       traittags, variables);
                var vacations         = db.LoadVacations();
                var templateTags      = db.LoadHouseholdTags();
                var datebasedProfiles = db.LoadDateBasedProfiles();
                HouseholdTemplate.LoadFromDatabase(cat.It, db.ConnectionString, traits, false, persons, traittags,
                                                   vacations,
                                                   templateTags, datebasedProfiles);
                (cat.MyItems.Count).Should().Be(0);

                var gen   = cat.CreateNewItem(db.ConnectionString);
                var entry = gen.AddEntry(traittags[0], 0, 10);
                entry.AddPerson(persons[0]);
                cat.SaveToDB();
                var generators = new ObservableCollection <HouseholdTemplate>();
                HouseholdTemplate.LoadFromDatabase(generators, db.ConnectionString, traits, false, persons, traittags,
                                                   vacations, templateTags, datebasedProfiles);
                (generators.Count).Should().Be(1);
                (generators[0].Entries.Count).Should().Be(1);
                (generators[0].Entries[0].Persons.Count).Should().Be(1);

                db.Cleanup();
            }
        }
        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 HouseLoadCreationAndSave2Test()
        {
            Config.ShowDeleteMessages = false;
            Logger.Threshold          = Severity.Error;
            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 houses1            = new ObservableCollection <House>();
                var devices            = new ObservableCollection <RealDevice>();
                var deviceCategories   = new ObservableCollection <DeviceCategory>();
                var timeBasedProfiles  = new ObservableCollection <TimeBasedProfile>();
                var timeLimits         = new ObservableCollection <TimeLimit>();
                var persons            = new ObservableCollection <Person>();
                var temperaturProfiles = new ObservableCollection <TemperatureProfile>();
                var loadTypes          = db.LoadLoadTypes();
                var variables          = db.LoadVariables();
                var geoLocs            = db.LoadGeographicLocations(out _, timeLimits);
                var energyStorages     = db.LoadEnergyStorages(loadTypes, variables);
                var trafoDevices       = db.LoadTransformationDevices(loadTypes,
                                                                      variables);

                var dateprofiles       = db.LoadDateBasedProfiles();
                var generators         = db.LoadGenerators(loadTypes, dateprofiles);
                var locations          = db.LoadLocations(devices, deviceCategories, loadTypes);
                var deviceActionGroups = db.LoadDeviceActionGroups();
                var deviceActions      = db.LoadDeviceActions(timeBasedProfiles, devices,
                                                              loadTypes, deviceActionGroups);
                var houseTypes = db.LoadHouseTypes(devices, deviceCategories, timeBasedProfiles,
                                                   timeLimits, loadTypes, trafoDevices, energyStorages, generators, locations, deviceActions,
                                                   deviceActionGroups, variables);
                var householdTraits   = new ObservableCollection <HouseholdTrait>();
                var deviceSelections  = new ObservableCollection <DeviceSelection>();
                var vacations         = db.LoadVacations();
                var householdTags     = db.LoadHouseholdTags();
                var traitTags         = db.LoadTraitTags();
                var modularHouseholds = db.LoadModularHouseholds(householdTraits,
                                                                 deviceSelections, persons, vacations, householdTags, traitTags);
                db.LoadTransportation(locations, out var transportationDeviceSets, out var travelRouteSets,
                                      out var _,
                                      out var _, loadTypes, out var chargingStationSets);
                House.LoadFromDatabase(houses1, db.ConnectionString,
                                       temperaturProfiles, geoLocs, houseTypes,
                                       modularHouseholds, chargingStationSets, transportationDeviceSets, travelRouteSets, false);
                (houses1.Count).Should().Be(1);
                db.Cleanup();
            }
        }
Beispiel #24
0
        public void AffordanceTaggingSetTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(AffordanceTaggingSet.TableName);
                db.ClearTable(AffordanceTaggingEntry.TableName);
                db.ClearTable(AffordanceTag.TableName);
                db.ClearTable(AffordanceTagReference.TableName);
                db.ClearTable(AffordanceTaggingSetLoadType.TableName);
                var profiles    = db.LoadTimeBasedProfiles();
                var realDevices = db.LoadRealDevices(out var deviceCategories, out var loadTypes,
                                                     profiles);
                var timeBasedProfiles = db.LoadTimeBasedProfiles();
                var desires           = db.LoadDesires();
                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();
                var affordances = db.LoadAffordances(timeBasedProfiles, out _,
                                                     deviceCategories, realDevices, desires, loadTypes, timeLimits, deviceActions, deviceActionGroups,
                                                     locations, variables);
                var ats = new ObservableCollection <AffordanceTaggingSet>();
                AffordanceTaggingSet.LoadFromDatabase(ats, db.ConnectionString, false, affordances, loadTypes);
                var ats1 = new AffordanceTaggingSet("test", "desc", db.ConnectionString, true, System.Guid.NewGuid().ToStrGuid());
                ats1.SaveToDB();
                var tag = ats1.AddNewTag("newtag");
                if (tag == null)
                {
                    throw new LPGException("Tag was null");
                }
                ats1.SaveToDB();
                ats1.AddTaggingEntry(tag, affordances[0]);
                ats1.AddTagReference(tag, PermittedGender.Male, 1, 99, 0.15);
                ats1.SaveToDB();
                ats.Clear();
                AffordanceTaggingSet.LoadFromDatabase(ats, db.ConnectionString, false, affordances, loadTypes);
                ats1 = ats[0];
                ats1.DeleteTag(ats1.Tags[0]);
                ats1.DeleteFromDB();
                ats.Clear();
                AffordanceTaggingSet.LoadFromDatabase(ats, db.ConnectionString, false, affordances, loadTypes);
                ats.Count.Should().Be(0);
                db.Cleanup();
            }
        }
Beispiel #25
0
        public void TransformationDeviceLoadCreationAndSaveTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                var tdlts     = new ObservableCollection <TransformationDevice>();
                var loadTypes = db.LoadLoadTypes();
                var variables = db.LoadVariables();
                TransformationDevice.LoadFromDatabase(tdlts, db.ConnectionString, loadTypes, variables, false);
                // delete everything and check
                tdlts.Clear();
                db.ClearTable(TransformationDevice.TableName);
                db.ClearTable(TransformationDeviceLoadType.TableName);
                db.ClearTable(TransformationDeviceCondition.TableName);
                db.ClearTable(TransformationFactorDatapoint.TableName);
                TransformationDevice.LoadFromDatabase(tdlts, db.ConnectionString, loadTypes, variables, false);
                (tdlts.Count).Should().Be(0);
                // add one and load again
                var tdlt = new TransformationDevice("tdlt", "desc", loadTypes[0], -1000000, 1000000,
                                                    db.ConnectionString, -100000, 100000, Guid.NewGuid().ToStrGuid());
                tdlt.SaveToDB();
                tdlt.AddOutTransformationDeviceLoadType(loadTypes[1], 2, TransformationFactorType.FixedFactor);
                tdlt.AddTransformationDeviceCondition(variables[0], 0, 100);
                tdlt.AddDataPoint(2, 1);

                TransformationDevice.LoadFromDatabase(tdlts, db.ConnectionString, loadTypes, variables, false);
                (tdlts.Count).Should().Be(1);
                (tdlts[0].LoadTypesOut.Count).Should().Be(1);
                (tdlts[0].Conditions.Count).Should().Be(1);
                (tdlts[0].FactorDatapoints.Count).Should().Be(1);
                // delete the loaded one
                tdlts[0].DeleteTransformationLoadtypeFromDB(tdlts[0].LoadTypesOut[0]);
                tdlts[0].DeleteTransformationDeviceCondition(tdlts[0].Conditions[0]);
                tdlts[0].DeleteFactorDataPoint(tdlts[0].FactorDatapoints[0]);
                (tdlts[0].LoadTypesOut.Count).Should().Be(0);
                (tdlts[0].Conditions.Count).Should().Be(0);
                (tdlts[0].FactorDatapoints.Count).Should().Be(0);
                tdlts[0].DeleteFromDB();

                tdlts.Clear();
                TransformationDevice.LoadFromDatabase(tdlts, db.ConnectionString, loadTypes, variables, false);
                (tdlts.Count).Should().Be(0);
                var tdlt2 =
                    new ObservableCollection <TransformationDeviceLoadType>();
                TransformationDeviceLoadType.LoadFromDatabase(tdlt2, db.ConnectionString, loadTypes, false);
                (tdlt2.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 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 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();
     }
 }
Beispiel #30
0
        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);
        }