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 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();
            }
        }