Ejemplo n.º 1
0
        public void HouseholdTraitTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(HouseholdTrait.TableName);
                db.ClearTable(HHTAutonomousDevice.TableName);
                db.ClearTable(HHTDesire.TableName);
                db.ClearTable(HHTLocation.TableName);
                db.ClearTable(HHTAffordance.TableName);
                db.ClearTable(HHTTag.TableName);
                var timeBasedProfiles = db.LoadTimeBasedProfiles();
                var dateBasedProfiles = db.LoadDateBasedProfiles();
                var devices           = db.LoadRealDevices(out ObservableCollection <DeviceCategory> deviceCategories, out _, out ObservableCollection <VLoadType> loadTypes,
                                                           timeBasedProfiles);

                var timeLimits         = db.LoadTimeLimits(dateBasedProfiles);
                var desires            = db.LoadDesires();
                var deviceActionGroups = db.LoadDeviceActionGroups();
                var deviceActions      = db.LoadDeviceActions(timeBasedProfiles, devices,
                                                              loadTypes, deviceActionGroups);
                var locations   = db.LoadLocations(devices, deviceCategories, loadTypes);
                var variables   = db.LoadVariables();
                var affordances = db.LoadAffordances(timeBasedProfiles, out _,
                                                     deviceCategories, devices, desires, loadTypes, timeLimits, deviceActions, deviceActionGroups, locations,
                                                     variables);
                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();
                var hht2 = new HouseholdTrait("blub2", null, "blub2", db.ConnectionString, "none", 1, 100, 10, 1,
                                              1, TimeType.Day, 1, 1, TimeType.Day, 1, 0, EstimateType.Theoretical, "", Guid.NewGuid().ToStrGuid());
                hht2.SaveToDB();
                var loc = new Location("loc1", -1, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                hht.AddAutomousDevice(devices[0], timeBasedProfiles[0], 0, loadTypes[0], timeLimits[0], loc, 0,
                                      VariableCondition.Equal, variables[0]);

                var hhtl = hht.AddLocation(locations[0]);
                hht.SaveToDB();
                var tag = new TraitTag("tag", db.ConnectionString,
                                       TraitLimitType.NoLimit, TraitPriority.Mandatory, Guid.NewGuid().ToStrGuid());
                tag.SaveToDB();
                hht.AddTag(tag);
                hht.AddAffordanceToLocation(hhtl, affordances[0], timeLimits[0], 100, 0, 0, 0, 0);
                hht.SaveToDB();
                hht.AddDesire(desires[0], 1, "Healthy", 1, 1, 0, 100, PermittedGender.All);
                hht.SaveToDB();
                hht.AddTrait(hht2);
                hht.SaveToDB();
                (hht.SubTraits.Count).Should().Be(1);
                var hhts = new ObservableCollection <HouseholdTrait>();
                var tags = db.LoadTraitTags();
                HouseholdTrait.LoadFromDatabase(hhts, db.ConnectionString, locations, affordances, devices,
                                                deviceCategories,
                                                timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, false,
                                                variables);
                (hhts.Count).Should().Be(2);
                var hht3 = hhts[0];
                (hht3.MinimumPersonsInCHH).Should().Be(1);
                (hht3.MaximumPersonsInCHH).Should().Be(100);
                (hht3.Desires.Count).Should().Be(1);
                (hht3.SubTraits.Count).Should().Be(1);
                (hht3.Classification).Should().Be("none");
                (hht3.Tags.Count).Should().Be(1);
                (hht3.Tags[0].Tag.Name).Should().Be("tag");
                foreach (var trait in hhts)
                {
                    trait.DeleteFromDB();
                }
                hhts.Clear();
                Logger.Info("Loading again...");
                HouseholdTrait.LoadFromDatabase(hhts, db.ConnectionString, locations, affordances, devices,
                                                deviceCategories,
                                                timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, false,
                                                variables);
                (hhts.Count).Should().Be(0);
                db.Cleanup();
            }
        }
Ejemplo n.º 2
0
        public void HouseholdTraitAffordanceTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(HouseholdTrait.TableName);
                db.ClearTable(HHTAutonomousDevice.TableName);
                db.ClearTable(HHTDesire.TableName);
                db.ClearTable(HHTLocation.TableName);
                db.ClearTable(HHTAffordance.TableName);
                db.ClearTable(HHTTrait.TableName);
                db.ClearTable(HHTTag.TableName);
                var timeBasedProfiles = db.LoadTimeBasedProfiles();
                var dateBasedProfiles = db.LoadDateBasedProfiles();
                var devices           = db.LoadRealDevices(out ObservableCollection <DeviceCategory> deviceCategories, out _, out var loadTypes,
                                                           timeBasedProfiles);

                var timeLimits         = db.LoadTimeLimits(dateBasedProfiles);
                var desires            = db.LoadDesires();
                var deviceActionGroups = db.LoadDeviceActionGroups();
                var deviceActions      = db.LoadDeviceActions(timeBasedProfiles, devices,
                                                              loadTypes, deviceActionGroups);
                var locations   = db.LoadLocations(devices, deviceCategories, loadTypes);
                var variables   = db.LoadVariables();
                var affordances = db.LoadAffordances(timeBasedProfiles, out _,
                                                     deviceCategories, devices, desires, loadTypes, timeLimits, deviceActions, deviceActionGroups, locations,
                                                     variables);
                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();

                var loc = new Location("loc1", null, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                locations.Add(loc);
                loc.SaveToDB();
                Logger.Info("adding affordance");
                hht.AddLocation(loc);

                hht.AddAffordanceToLocation(loc, affordances[0], timeLimits[0], 100, 0, 0, 0, 0);
                hht.SaveToDB();
                Logger.Info("reloading ");
                var hhts = new ObservableCollection <HouseholdTrait>();
                var tags = db.LoadTraitTags();

                HouseholdTrait.LoadFromDatabase(hhts, db.ConnectionString, locations, affordances, devices,
                                                deviceCategories,
                                                timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, false,
                                                variables);
                (hhts.Count).Should().Be(1);
                var hht3 = hhts[0];
                (hht3.Locations[0].AffordanceLocations.Count).Should().Be(1);
                Logger.Info("deleting affordance");
                hht3.DeleteAffordanceFromDB(hht3.Locations[0].AffordanceLocations[0]);

                hhts.Clear();
                Logger.Info("Loading again...");
                HouseholdTrait.LoadFromDatabase(hhts, db.ConnectionString, locations, affordances, devices,
                                                deviceCategories,
                                                timeBasedProfiles, loadTypes, timeLimits, desires, deviceActions, deviceActionGroups, tags, false,
                                                variables);
                var hht4 = hhts[0];
                (hht4.Locations[0].AffordanceLocations.Count).Should().Be(0);

                db.Cleanup();
            }
        }