Ejemplo n.º 1
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 ModularHouseholdTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(ModularHousehold.TableName);
                db.ClearTable(ModularHouseholdTrait.TableName);
                db.ClearTable(ModularHouseholdPerson.TableName);
                var persons         = new ObservableCollection <Person>();
                var result          = new ObservableCollection <ModularHousehold>();
                var householdTraits = new ObservableCollection <HouseholdTrait>();
                var hht             = new HouseholdTrait("blub", 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 deviceSelections = new ObservableCollection <DeviceSelection>();
                var ds = new DeviceSelection("ds", null, "bla", db.ConnectionString, Guid.NewGuid().ToStrGuid());
                ds.SaveToDB();
                deviceSelections.Add(ds);
                var vacations = db.LoadVacations();
                var hhTags    = db.LoadHouseholdTags();
                var traitTags = db.LoadTraitTags();

                ModularHousehold.LoadFromDatabase(result, db.ConnectionString, householdTraits, deviceSelections, false,
                                                  persons, vacations, hhTags, traitTags);
                (result.Count).Should().Be(0);
                var chh = new ModularHousehold("blub", null, "blub", db.ConnectionString, ds, "src", null, null,
                                               EnergyIntensityType.Random, CreationType.ManuallyCreated, Guid.NewGuid().ToStrGuid());
                chh.SaveToDB();
                chh.AddTrait(hht, ModularHouseholdTrait.ModularHouseholdTraitAssignType.Age, null);
                chh.SaveToDB();
                result.Clear();
                ModularHousehold.LoadFromDatabase(result, db.ConnectionString, householdTraits, deviceSelections, false,
                                                  persons, vacations, hhTags, traitTags);
                (result.Count).Should().Be(1);
                (result[0].Traits.Count).Should().Be(1);
                db.Cleanup();
            }
        }