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);
            }
        }
        public void CalculateAverageEnergyUseTestAbsoluteProfile()
        {
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                Config.IsInUnitTesting = true;
                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);
                var tp = new TimeBasedProfile("tp", null, db.ConnectionString,
                                              TimeProfileType.Absolute, "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 allActions = new ObservableCollection <DeviceAction>();

                var res = rd2.CalculateAverageEnergyUse(lt, allActions, tp, 1, 1);
                foreach (var keyValuePair in res)
                {
                    Logger.Info(keyValuePair.Item1 + ": " + keyValuePair.Item2);
                }
                (res.Count).Should().Be(1);
                var first = res.First();
                (first.Item2).Should().Be(200);
                db.Cleanup();
            }
        }
Exemple #3
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);
     }
 }
        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 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 TransportationDeviceSetTest()
        {
            using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(TransportationDeviceSet.TableName);
                db.ClearTable(TransportationDevice.TableName);
                db.ClearTable(TransportationDeviceCategory.TableName);
                TransportationDeviceSet tds =
                    new TransportationDeviceSet("transportationdeviceset", null, db.ConnectionString, "desc",
                                                System.Guid.NewGuid().ToStrGuid());
                tds.SaveToDB();

                TransportationDeviceCategory tdc = new TransportationDeviceCategory("transportationdevicecategory",
                                                                                    null, db.ConnectionString, "desc", true, System.Guid.NewGuid().ToStrGuid());
                tdc.SaveToDB();
                VLoadType vlt = (VLoadType)VLoadType.CreateNewItem(null, db.ConnectionString);
                vlt.SaveToDB();
                TransportationDevice tdev = new TransportationDevice("mydevice", null, db.ConnectionString, "", 1, SpeedUnit.Kmh,
                                                                     tdc, 1000, 10, 100, 100, vlt,
                                                                     System.Guid.NewGuid().ToStrGuid());
                tdev.SaveToDB();
                ObservableCollection <TransportationDevice> transportationDevices = new ObservableCollection <TransportationDevice>
                {
                    tdev
                };
                tds.AddDevice(tdev);

                /*ObservableCollection<TransportationDeviceCategory> categories = new ObservableCollection<TransportationDeviceCategory>
                 * {
                 *  tdc
                 * };*/
                ObservableCollection <TransportationDeviceSet> result = new ObservableCollection <TransportationDeviceSet>();
                TransportationDeviceSet.LoadFromDatabase(result, db.ConnectionString, false, transportationDevices);
                db.Cleanup();
                (result.Count).Should().Be(1);
                (result[0].TransportationDeviceSetEntries.Count).Should().Be(1);
            }
        }
Exemple #7
0
 public void VLoadTypeTest()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         db.ClearTable(VLoadType.TableName);
         var loadts = new ObservableCollection <VLoadType>();
         VLoadType.LoadFromDatabase(loadts, db.ConnectionString, false);
         (loadts.Count).Should().Be(0);
         var loadType = new VLoadType("loadtype1", "blub", "bla", "blu", 1000, 1, new TimeSpan(1, 0, 0), 1,
                                      db.ConnectionString, LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
         loadType.SaveToDB();
         VLoadType.LoadFromDatabase(loadts, db.ConnectionString, false);
         (loadts.Count).Should().Be(1);
         var lt = loadts[0];
         lt.Name.Should().Be("loadtype1");
         (lt.Description).Should().Be("blub");
         lt.DeleteFromDB();
         loadts.Clear();
         VLoadType.LoadFromDatabase(loadts, db.ConnectionString, false);
         (loadts.Count).Should().Be(0);
         db.Cleanup();
     }
 }
        public void RunChargingStationSetTests()
        {
            using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(ChargingStationSet.TableName);
                Location loc = new Location("loc1", null, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                loc.SaveToDB();
                ChargingStationSet sl = new ChargingStationSet("blub", null, db.ConnectionString, "desc", Guid.NewGuid().ToStrGuid());
                sl.SaveToDB();
                TransportationDeviceCategory tdc = new TransportationDeviceCategory("tdc", null, db.ConnectionString, "desc", false, Guid.NewGuid().ToStrGuid());
                tdc.SaveToDB();
                VLoadType vlt = (VLoadType)VLoadType.CreateNewItem(s => false, db.ConnectionString);
                vlt.SaveToDB();
                Site site = (Site)Site.CreateNewItem(_ => false, db.ConnectionString);
                site.SaveToDB();
                sl.AddChargingStation(tdc, vlt, 10, site, vlt);

                ObservableCollection <VLoadType> lts = new ObservableCollection <VLoadType>
                {
                    vlt
                };
                ObservableCollection <TransportationDeviceCategory> cats = new ObservableCollection <TransportationDeviceCategory>
                {
                    tdc
                };
                ObservableCollection <ChargingStationSet> css = new ObservableCollection <ChargingStationSet>();
                ObservableCollection <Site> sites             = new ObservableCollection <Site>
                {
                    site
                };
                ChargingStationSet.LoadFromDatabase(css,
                                                    db.ConnectionString, false, lts, cats, sites);
                db.Cleanup();
                (css.Count).Should().Be(1);
                (css[0].ChargingStations.Count).Should().Be(1);
            }
        }