Exemplo n.º 1
0
        public void MakeCalcLocationsTest()
        {
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            Random r = new Random(1);
            DeviceCategoryPicker picker = new DeviceCategoryPicker(r, null);
            //var cp = new CalcFactoryParameters(picker);
            //var dict =new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var deviceActions = new ObservableCollection <DeviceAction>();
            //var locdict = new Dictionary<Location, CalcLocation>();
            CalcParameters cp = CalcParametersFactory.MakeGoodDefaults();
            //var mock = new Mock<IOnlineDeviceActivationProcessor>();
            //var iodap = mock.Object;
            var locationDtoDict         = new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>());
            var ltDict                  = new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>());
            CalcLocationDtoFactory cldt = new CalcLocationDtoFactory(cp, picker, locationDtoDict);
            Dictionary <CalcLocationDto, List <IAssignableDevice> > deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();
            LocationDtoDict          calclocdict = new LocationDtoDict();
            List <DeviceCategoryDto> devcat      = new List <DeviceCategoryDto>();

            using CalcRepo calcRepo = new CalcRepo();
            //devcat.Add(new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid()));
            var locdtos = cldt.MakeCalcLocations(locations,
                                                 new HouseholdKey("hh1"),
                                                 EnergyIntensityType.EnergyIntensive,
                                                 deviceLocationDict,
                                                 deviceActions,
                                                 calclocdict,
                                                 devcat);

            locdtos.Count.Should().Be(1);
            locdtos[0].Name.Should().Be(loc.Name);
            CalcLocationFactory clf = new CalcLocationFactory(ltDict, calcRepo);
            //"HH1", EnergyIntensityType.EnergySaving, dict,deviceActions,
            DtoCalcLocationDict dcl = new DtoCalcLocationDict();
            var calclocs            = clf.MakeCalcLocations(locdtos, dcl, calcRepo);

            calclocs.Count.Should().Be(1);
            calclocs[0].Name.Should().Be(loc.Name);
            calclocs[0].Guid.Should().Be(locdtos[0].Guid);
        }
Exemplo n.º 2
0
        public void MakeCalcLocationsTestWithDeviceCategory()
        {
            using WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass());
            var            builder        = new ContainerBuilder();
            var            r              = new Random(1);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(2018, 1, 1)
                                            .SetEndDate(new DateTime(2018, 1, 1, 2, 0, 0)).SetSettlingDays(0).EnableShowSettlingPeriod();
            //CalcFactoryParameters.SetSkipChecking(true);
            //var nr = new NormalRandom(0, 1, r);
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            var devices = new ObservableCollection <RealDevice>();

            var dc  = new DeviceCategory("dc", -1, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), 1, true);
            var rd  = new RealDevice("rd", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);
            var rd2 = new RealDevice("rd2", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);

            dc.SubDevices.Add(rd);
            loc.AddDevice(dc, false);
            loc.AddDevice(rd2, false);
            var deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();

            List <DeviceCategoryDto> devcat = new List <DeviceCategoryDto> {
                new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid())
            };

            devices.Add(rd);
            devices.Add(rd2);
            //var dict =new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var allDeviceActions = new ObservableCollection <DeviceAction>();

            //var locdict = new Dictionary<Location, CalcLocation>();
            builder.Register(x => new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>())).As <CalcLoadTypeDtoDictionary>()
            .SingleInstance();
            builder.Register(x => new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>())).As <CalcLoadTypeDictionary>()
            .SingleInstance();
            builder.Register(x => new DeviceCategoryPicker(r, null)).As <IDeviceCategoryPicker>().SingleInstance();
            builder.Register(x => calcParameters).As <CalcParameters>().SingleInstance();
            //builder.RegisterType<CalcLocationFactory>().As<CalcLocationFactory>().SingleInstance();
            Mock <IOnlineDeviceActivationProcessor> odapmock = new Mock <IOnlineDeviceActivationProcessor>();

            builder.Register(x => odapmock.Object).As <IOnlineDeviceActivationProcessor>().SingleInstance();
            builder.Register(x => r).As <Random>().SingleInstance();
            var idl = wd.InputDataLogger;

            builder.Register(x => idl).As <IInputDataLogger>().SingleInstance();
            string path = wd.WorkingDirectory;

            builder.Register(x => new FileFactoryAndTracker(path, "HH1", idl)).As <FileFactoryAndTracker>()
            .SingleInstance();
            builder.Register(x => new SqlResultLoggingService(path)).As <SqlResultLoggingService>().SingleInstance();
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new OnlineLoggingData(x.Resolve <DateStampCreator>(), x.Resolve <IInputDataLogger>(), x.Resolve <CalcParameters>()))
            .As <OnlineLoggingData>().SingleInstance();
            builder.Register(x => new LogFile(calcParameters,
                                              x.Resolve <FileFactoryAndTracker>())).As <ILogFile>().SingleInstance();
            builder.RegisterType <CalcDeviceFactory>().As <CalcDeviceFactory>().SingleInstance();
            builder.RegisterType <CalcLocationFactory>().As <CalcLocationFactory>().SingleInstance();
            builder.RegisterType <CalcPersonFactory>().As <CalcPersonFactory>().SingleInstance();
            builder.RegisterType <CalcModularHouseholdFactory>().As <CalcModularHouseholdFactory>().SingleInstance();
            builder.RegisterType <CalcLocationDtoFactory>().As <CalcLocationDtoFactory>();
            builder.RegisterType <InputDataLogger>().As <InputDataLogger>().SingleInstance();
            builder.RegisterType <CalcRepo>().As <CalcRepo>().SingleInstance();
            var container = builder.Build();

            using (var scope = container.BeginLifetimeScope()) {
                var             cldt        = scope.Resolve <CalcLocationDtoFactory>();
                var             calcRepo    = scope.Resolve <CalcRepo>();
                LocationDtoDict calclocdict = new LocationDtoDict();
                var             locdtos     = cldt.MakeCalcLocations(locations,
                                                                     new HouseholdKey("HH1"),
                                                                     EnergyIntensityType.EnergySaving,
                                                                     deviceLocationDict,
                                                                     allDeviceActions,
                                                                     calclocdict,
                                                                     devcat);

                CalcLocationFactory clf = scope.Resolve <CalcLocationFactory>();
                DtoCalcLocationDict dtl = new DtoCalcLocationDict();
                var clocations          = clf.MakeCalcLocations(locdtos, dtl, calcRepo);

                clocations.Count.Should().Be(1);
                clocations[0].LightDevices.Count.Should().Be(2);
                foreach (var device in clocations[0].LightDevices)
                {
                    Logger.Info(device.Name);
                }
            }

            wd.CleanUp();
        }
Exemplo n.º 3
0
        public void MakeCalcLocationsTestWithDevice()
        {
            var            builder        = new ContainerBuilder();
            var            r              = new Random(1);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(2018, 1, 1)
                                            .SetEndDate(new DateTime(2018, 1, 1, 2, 0, 0)).SetSettlingDays(0).EnableShowSettlingPeriod();
            var picker = new DeviceCategoryPicker(r, null);

            builder.Register(x => picker).As <DeviceCategoryPicker>().SingleInstance();
            //var nr = new NormalRandom(0, 1, r);
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            var devices = new ObservableCollection <RealDevice>();
            var dc      = new DeviceCategory("dc", -1, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), 1, true);
            List <DeviceCategoryDto> devcat = new List <DeviceCategoryDto> {
                new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid())
            };
            var rd = new RealDevice("rd", 1, string.Empty, dc, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid(), 1);

            loc.AddDevice(rd, false);
            var deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();
            var allDeviceActions   = new ObservableCollection <DeviceAction>();

            //CalcLoadTypeDictionary cltd = CalcLoadTypeFactory.MakeLoadTypes(new ObservableCollection<VLoadType>(),calcParameters.InternalStepsize, calcParameters.LoadTypePriority);
            builder.Register(x => new DateStampCreator(x.Resolve <CalcParameters>())).As <DateStampCreator>().SingleInstance();
            builder.Register(x => new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>())).As <CalcLoadTypeDtoDictionary>()
            .SingleInstance();
            builder.Register(x => new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>())).As <CalcLoadTypeDictionary>()
            .SingleInstance();
            builder.Register(x => new DeviceCategoryPicker(r, null)).As <IDeviceCategoryPicker>().SingleInstance();
            builder.Register(_ => calcParameters).As <CalcParameters>().SingleInstance();
            //builder.RegisterType<CalcLocationFactory>().As<CalcLocationFactory>().SingleInstance();
            Mock <IOnlineDeviceActivationProcessor> odapmock = new Mock <IOnlineDeviceActivationProcessor>();

            builder.Register(x => odapmock.Object).As <IOnlineDeviceActivationProcessor>().SingleInstance();
            builder.Register(x => r).As <Random>().SingleInstance();
            builder.RegisterType <CalcDeviceFactory>().As <CalcDeviceFactory>().SingleInstance();
            builder.RegisterType <CalcLocationFactory>().As <CalcLocationFactory>().SingleInstance();
            builder.RegisterType <CalcLocationDtoFactory>().As <CalcLocationDtoFactory>();
            builder.RegisterType <CalcRepo>().As <CalcRepo>().SingleInstance();
            var container = builder.Build();

            using var scope = container.BeginLifetimeScope();
            var             calcRepo    = scope.Resolve <CalcRepo>();
            var             cldt        = scope.Resolve <CalcLocationDtoFactory>();
            LocationDtoDict calclocdict = new LocationDtoDict();
            var             locdtos     = cldt.MakeCalcLocations(locations,
                                                                 new HouseholdKey("HH1"),
                                                                 EnergyIntensityType.EnergyIntensive,
                                                                 deviceLocationDict,
                                                                 allDeviceActions,
                                                                 calclocdict,
                                                                 devcat);

            //CalcDeviceFactory cdf = scope.Resolve<CalcDeviceFactory>();
            CalcLocationFactory clf = scope.Resolve <CalcLocationFactory>();
            DtoCalcLocationDict dtl = new DtoCalcLocationDict();
            var clocations          = clf.MakeCalcLocations(locdtos, dtl, calcRepo);

            clocations.Count.Should().Be(1);
            clocations[0].LightDevices.Count.Should().Be(2);
        }