public void AffordanceVariableTests2()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         db.ClearTable(Affordance.TableName);
         db.ClearTable(AffordanceStandby.TableName);
         db.ClearTable(AffordanceDevice.TableName);
         db.ClearTable(AffordanceDesire.TableName);
         db.ClearTable(AffordanceSubAffordance.TableName);
         db.ClearTable(AffordanceTaggingEntry.TableName);
         db.ClearTable(HHTAffordance.TableName);
         db.ClearTable(AffVariableOperation.TableName);
         var v = new Variable("var1", "desc", "unit", db.ConnectionString, Guid.NewGuid().ToStrGuid());
         v.SaveToDB();
         Config.IsInUnitTesting = true;
         var col = new ColorRGB(255, 0, 0);
         var aff = new Affordance("bla", null, null, true, PermittedGender.Female, 0.1m, col,
                                  "affordanceCategory", null, "desc", db.ConnectionString, true, true, 0, 99, false,
                                  ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
         aff.SaveToDB();
         aff.ExecutedVariables.Count.Should().Be(0);
         aff.AddVariableOperation(0, VariableLocationMode.CurrentLocation, null, VariableAction.SetTo, v,
                                  string.Empty,
                                  VariableExecutionTime.Beginning);
         aff.SaveToDB();
         aff.ExecutedVariables.Count.Should().Be(1);
         var sim2             = new Simulator(db.ConnectionString);
         var affordanceLoaded = sim2.Affordances.It[0];
         affordanceLoaded.ExecutedVariables.Count.Should().Be(1);
         affordanceLoaded.ExecutedVariables[0].Name.Should().Be("var1");
         affordanceLoaded.DeleteVariableOperation(affordanceLoaded.ExecutedVariables[0]);
         affordanceLoaded.ExecutedVariables.Count.Should().Be(0);
         var sim3 = new Simulator(db.ConnectionString);
         var affordanceLoaded2 = sim3.Affordances.It[0];
         affordanceLoaded2.ExecutedVariables.Count.Should().Be(0);
         db.Cleanup();
     }
 }
        public void AffordanceStandbyTests2()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(Affordance.TableName);
                db.ClearTable(AffordanceStandby.TableName);
                db.ClearTable(AffordanceDevice.TableName);
                db.ClearTable(AffordanceDesire.TableName);
                db.ClearTable(AffordanceSubAffordance.TableName);
                db.ClearTable(AffordanceTaggingEntry.TableName);
                db.ClearTable(HHTAffordance.TableName);
                db.ClearTable(AffVariableRequirement.TableName);

                Config.IsInUnitTesting = true;
                var col = new ColorRGB(255, 0, 0);
                var aff = new Affordance("bla", null, null, true, PermittedGender.Female, 0.1m, col,
                                         "AffordanceCategory", null, "desc", db.ConnectionString, true, true, 0, 99, false,
                                         ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
                aff.SaveToDB();
                aff.AffordanceStandbys.Count.Should().Be(0);
                var rd2 = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd2.SaveToDB();
                aff.AddStandby(rd2);
                aff.SaveToDB();
                aff.AffordanceStandbys.Count.Should().Be(1);
                var sim2             = new Simulator(db.ConnectionString);
                var loadedAffordance = sim2.Affordances.It[0];
                loadedAffordance.AffordanceStandbys.Count.Should().Be(1);
                loadedAffordance.AffordanceStandbys[0].Device?.Name.Should().Be("rd2");
                loadedAffordance.DeleteStandby(loadedAffordance.AffordanceStandbys[0]);
                loadedAffordance.AffordanceStandbys.Count.Should().Be(0);
                var sim3 = new Simulator(db.ConnectionString);
                var affordanceLoaded2 = sim3.Affordances.It[0];
                affordanceLoaded2.AffordanceStandbys.Count.Should().Be(0);
                db.Cleanup();
            }
        }
        public void CalculateAverageEnergyUseTestDeviceAction()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Config.IsInUnitTesting = true;
                var col     = new ColorRGB(255, 0, 0);
                var devices = new ObservableCollection <RealDevice>();
                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);

                devices.Add(rd2);

                var deviceCategories = new ObservableCollection <DeviceCategory>();
                var deviceActions    = new ObservableCollection <DeviceAction>();
                var aff = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                         string.Empty,
                                         db.ConnectionString, true, true, 0,
                                         100, false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(),
                                         BodilyActivityLevel.Low);
                aff.SaveToDB();

                var tp = new TimeBasedProfile("tp", null, db.ConnectionString, TimeProfileType.Relative, "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 dag = new DeviceActionGroup("dag", db.ConnectionString, string.Empty, Guid.NewGuid().ToStrGuid());
                dag.SaveToDB();
                var da = new DeviceAction("da", null, string.Empty, db.ConnectionString, dag, rd2, Guid.NewGuid().ToStrGuid());
                da.SaveToDB();
                da.AddDeviceProfile(tp, 0, lt, 1);
                deviceActions.Add(da);
                var tbp = new TimeBasedProfile("name", 1, db.ConnectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());
                aff.AddDeviceProfile(dag, tbp, 0, devices, deviceCategories, lt, 1);
                var res = aff.CalculateAverageEnergyUse(deviceActions);
                foreach (var keyValuePair in res)
                {
                    Logger.Info(keyValuePair.Key + ": " + keyValuePair.Value);
                }
                res.Count.Should().Be(1);
                var first = res.First();
                first.Value.Should().Be(666 * 2);
                db.Cleanup();
            }
        }
 public void AffordanceStandbyTests1()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         Config.IsInUnitTesting = true;
         var col = new ColorRGB(255, 0, 0);
         var aff = new Affordance("bla", null, null, true, PermittedGender.Female, 0.1m, col,
                                  "AffordanceCategory", null, "desc", db.ConnectionString, true, true, 0, 99, false,
                                  ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
         aff.SaveToDB();
         aff.AffordanceStandbys.Count.Should().Be(0);
         var rd2 = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
         rd2.SaveToDB();
         aff.AddStandby(rd2);
         aff.AffordanceStandbys.Count.Should().Be(1);
         db.Cleanup();
     }
 }
        public void CalculateMaximumInternalTimeResolutionTestForDeviceAction()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Config.IsInUnitTesting = true;
                var col     = new ColorRGB(255, 0, 0);
                var devices = new ObservableCollection <RealDevice>();
                var rd2     = new RealDevice("rd2", 1, string.Empty, null, string.Empty, false, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                rd2.SaveToDB();
                devices.Add(rd2);

                var deviceCategories = new ObservableCollection <DeviceCategory>();
                var aff = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                         string.Empty,
                                         db.ConnectionString, true, true, 0, 100,
                                         false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
                aff.SaveToDB();

                var tp = new TimeBasedProfile("tp", null, db.ConnectionString, TimeProfileType.Relative, "fake", Guid.NewGuid().ToStrGuid());
                tp.SaveToDB();
                tp.AddNewTimepoint(new TimeSpan(0, 0, 0), 1, false);
                tp.AddNewTimepoint(new TimeSpan(0, 1, 0), 1, false);
                tp.AddNewTimepoint(new TimeSpan(0, 10, 0), 1, false);
                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();
                var dag = new DeviceActionGroup("dag", db.ConnectionString, string.Empty, Guid.NewGuid().ToStrGuid());
                dag.SaveToDB();
                var da = new DeviceAction("da", null, string.Empty, db.ConnectionString, dag, rd2, Guid.NewGuid().ToStrGuid());
                da.SaveToDB();
                da.AddDeviceProfile(tp, 0, lt, 1);
                new ObservableCollection <DeviceAction>().Add(da);
                var tbp = new TimeBasedProfile("name", 1, db.ConnectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());
                aff.AddDeviceProfile(da, tbp, 0, devices, deviceCategories, lt, 1);

                var ts = aff.CalculateMaximumInternalTimeResolution();
                (ts.TotalSeconds).Should().Be(60);
                Logger.Info(ts.ToString());
                db.Cleanup();
            }
        }
        public void AffordanceRequirementVariableTest()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Config.IsInUnitTesting = true;
                var col = new ColorRGB(255, 0, 0);

                var aff = new Affordance("bla", null, null, true, PermittedGender.Female, 0.1m, col,
                                         "affordanceCategory", null, "desc", db.ConnectionString, true, true, 0, 99, false,
                                         ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
                aff.SaveToDB();
                aff.ExecutedVariables.Count.Should().Be(0);
                var va = new Variable("var1", "desc", "unit", db.ConnectionString, Guid.NewGuid().ToStrGuid());
                va.SaveToDB();
                aff.AddVariableRequirement(1, VariableLocationMode.CurrentLocation, null, VariableCondition.Equal, va,
                                           string.Empty);
                aff.RequiredVariables.Count.Should().Be(1);
                db.Cleanup();
            }
        }
 public void LoadFromDatabaseTest()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         var affdev             = new ObservableCollection <AffordanceDevice>();
         var deviceCategories   = new ObservableCollection <DeviceCategory>();
         var realDevices        = new ObservableCollection <RealDevice>();
         var timeBasedProfiles  = new ObservableCollection <TimeBasedProfile>();
         var affordances        = new ObservableCollection <Affordance>();
         var dateBasedProfiles  = db.LoadDateBasedProfiles();
         var timeLimits         = db.LoadTimeLimits(dateBasedProfiles);
         var loadtypes          = db.LoadLoadTypes();
         var deviceActionGroups = db.LoadDeviceActionGroups();
         var deviceActions      = new ObservableCollection <DeviceAction>();
         db.ClearTable(AffordanceDevice.TableName);
         AffordanceDevice.LoadFromDatabase(affdev, db.ConnectionString, deviceCategories, realDevices,
                                           timeBasedProfiles, affordances, loadtypes, deviceActions, deviceActionGroups, false);
         affdev.Count.Should().Be(0);
         var rd = new RealDevice("blub", 1, "1", null, "name", true, false, db.ConnectionString, Guid.NewGuid().ToStrGuid());
         rd.SaveToDB();
         realDevices.Add(rd);
         var tp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative,
                                       "fake", Guid.NewGuid().ToStrGuid());
         tp.SaveToDB();
         timeBasedProfiles.Add(tp);
         var aff = new Affordance("blub", tp, null, true, PermittedGender.All, 0, new ColorRGB(255, 0, 0),
                                  "bla", timeLimits[0], string.Empty, db.ConnectionString, false, false, 0, 99, false,
                                  ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
         aff.SaveToDB();
         affordances.Add(aff);
         var newaffdev = new AffordanceDevice(rd, tp, null, 0, aff.ID, realDevices, deviceCategories,
                                              "blub", loadtypes[0], db.ConnectionString, 1, Guid.NewGuid().ToStrGuid());
         newaffdev.SaveToDB();
         AffordanceDevice.LoadFromDatabase(affdev, db.ConnectionString, deviceCategories, realDevices,
                                           timeBasedProfiles, affordances, loadtypes, deviceActions, deviceActionGroups, false);
         affdev.Count.Should().Be(1);
         affdev[0].LoadType.Should().Be(loadtypes[0]);
         db.Cleanup();
     }
 }