public void GetDuplicateCalcManagerHouseholdTest() { using (var wd1 = new WorkingDir("GetDuplicateCalcManagerHouseholdTest1")) { CalculateOneHousehold(wd1.WorkingDirectory); using (var wd2 = new WorkingDir("GetDuplicateCalcManagerHouseholdTest2")) { CalculateOneHousehold(wd2.WorkingDirectory); var hhkeys = HouseholdKeyLogger.Load(wd1.SqlResultLoggingService); var afts1 = new CalcDeviceDtoLogger(wd1.SqlResultLoggingService); var aft1 = afts1.Load(hhkeys.Where(x => x.KeyType == HouseholdKeyType.Household).ToList()); var afts2 = new CalcDeviceDtoLogger(wd2.SqlResultLoggingService); var aft2 = afts2.Load(hhkeys.Where(x => x.KeyType == HouseholdKeyType.Household).ToList()); var devices1 = aft1.Select(x => x.Name).OrderBy(x => x).ToList(); var devices2 = aft2.Select(x => x.Name).OrderBy(x => x).ToList(); devices1.Should().BeEquivalentTo(devices2); var rfel1 = new ResultFileEntryLogger(wd1.SqlResultLoggingService); var rfes1 = rfel1.Load(); var rfel2 = new ResultFileEntryLogger(wd2.SqlResultLoggingService); var rfes2 = rfel2.Load(); rfes1.Should().BeEquivalentTo(rfes2, o => o.Excluding( x => x.SelectedMemberPath.EndsWith("FullFileName", StringComparison.InvariantCultureIgnoreCase))); CompareCsv(rfes1, rfes2); wd1.CleanUp(); wd2.CleanUp(); } } }
public void RunDoubleActivationTest() { var rnd = new Random(1); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); HouseholdKey key = new HouseholdKey("hh1"); using (var calcRepo = SetupFullWorkingTransportationExample(wd, rnd, out _, out var srcloc, out var dstloc, out var dstSite, out var transportationHandler, out var abt, calcParameters, key)) { //make sure there is a travel route const string personname = "activator"; TimeStep ts = new TimeStep(0, 0, false); var travelroute = transportationHandler.GetTravelRouteFromSrcLoc(srcloc, dstSite, ts, personname, calcRepo); Assert.NotNull(travelroute); // find if busy var isbusy = abt.IsBusy(ts, srcloc, personname, false); isbusy.Should().BeFalse(); var affs = dstloc.Affordances.ToList(); Logger.Info("Activating affordance for time 0"); affs[0].Activate(ts, personname, srcloc, out _); } //should throw exception the second time. Logger.Info("Activating affordance again for time 0"); //this should throw, since it is already busy //Assert.Throws<LPGException>(() =>affs[0].Activate(0, "activator", null, srcloc, new Dictionary<int, CalcProfile>(), out _)); CalcAffordance.DoubleCheckBusyArray = false; wd.CleanUp(); } }
public void RegisterDeviceActivationTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new DeviceActivationEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); CalcParameters cp = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod(); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hhname", wd.InputDataLogger)) { var key = new HouseholdKey(" hh1"); fft.HouseholdRegistry.RegisterHousehold(key, "hh key", HouseholdKeyType.Household, wd.InputDataLogger, "desc", null, null); fft.HouseholdRegistry.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, wd.InputDataLogger, "desc", null, null); DateStampCreator dsc = new DateStampCreator(cp); using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, cp); fft.HouseholdRegistry.RegisterHousehold(key, "hh key", HouseholdKeyType.Household, wd.InputDataLogger, "desc", null, null); CalcLoadTypeDto clt = new CalcLoadTypeDto("lt", "unitofpower", "unitofsum", 1, true, "guid".ToStrGuid()); TimeStep ts = new TimeStep(1, 1, true); CalcDeviceDto cdd = new CalcDeviceDto("devname", "".ToStrGuid(), key, OefcDeviceType.Device, "devcatname", "", Guid.NewGuid().ToStrGuid(), "locguid".ToStrGuid(), "locname"); DeviceActivationEntry aeue = new DeviceActivationEntry("affname", clt, 1, "activatorname", 1, ts, cdd); old.RegisterDeviceActivation(aeue); old.FinalSaveToDatabase(); } wd.CleanUp(); } }
public void RunTransportDecoratorTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); Config.IsInUnitTesting = true; var rnd = new Random(1); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); HouseholdKey key = new HouseholdKey("hh1"); using (var calcRepo = SetupFullWorkingTransportationExample(wd, rnd, out _, out var srcloc, out var dstloc, out var dstSite, out var transportationHandler, out var abt, calcParameters, key)) { //make sure there is a travel route const string personName = "activator"; TimeStep ts = new TimeStep(0, 0, false); var travelroute = transportationHandler.GetTravelRouteFromSrcLoc(srcloc, dstSite, ts, personName, calcRepo); Assert.NotNull(travelroute); // find if busy var isbusy = abt.IsBusy(ts, srcloc, "", false); isbusy.Should().BeFalse(); var affs = dstloc.Affordances.ToList(); Logger.Info("Activating affordance for time 0"); travelroute.GetDuration(ts, personName, new List <CalcTransportationDevice>()); affs[0].Activate(ts, "activator", srcloc, out var _); } //should throw exception the second time. Logger.Info("Activating affordance again for time 0"); CalcAffordance.DoubleCheckBusyArray = false; wd.CleanUp(); } }
private static void TestImport([JetBrains.Annotations.NotNull] string path, [JetBrains.Annotations.NotNull] out Simulator mainsim, [JetBrains.Annotations.NotNull] out Database.DatabaseMerger.DatabaseMerger dbm) { var di = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), path)); Logger.Debug(di.FullName); var fi = FindImportFiles(path); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var newpath = Path.Combine(wd.WorkingDirectory, "mergertest.db3"); File.Copy(fi.FullName, newpath); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(newpath, null); dbm.RunImport(null); mainsim = mainSim; db.Cleanup(); } wd.CleanUp(); } }
public void GetCalcManagerHouseTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.OnlyOverallSum); //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.Houses[sim.Houses.MyItems.Count - 1], EnergyIntensityType.Random, false, null, LoadTypePriority.RecommendedForHouses, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(ReportCancelFunc); db.Cleanup(); } wd.CleanUp(); } }
public void RunJsonCalculatorTestForExternalTimeResolutionJsonFile() { Logger.Get().StartCollectingAllMessages(); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { Directory.SetCurrentDirectory(wd.WorkingDirectory); using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { string dbPath = wd.Combine("my.db3"); File.Copy(db.FileName, dbPath); Logger.Info("DB File Path: " + dbPath); JsonCalcSpecification jcs = new JsonCalcSpecification(); if (jcs.CalcOptions == null) { throw new LPGException("Calcoptions was null"); } jcs.DefaultForOutputFiles = OutputFileDefault.NoFiles; jcs.CalcOptions.Add(CalcOption.SumProfileExternalIndividualHouseholdsAsJson); jcs.StartDate = new DateTime(2019, 1, 1); jcs.EndDate = new DateTime(2019, 1, 3); jcs.ExternalTimeResolution = "00:15:00"; jcs.LoadTypePriority = LoadTypePriority.RecommendedForHouses; Simulator sim = new Simulator(db.ConnectionString); JsonCalculator jc = new JsonCalculator(); jc.StartHousehold(sim, jcs, sim.Houses[0].GetJsonReference(), null); } Directory.SetCurrentDirectory(wd.PreviousCurrentDir); wd.CleanUp(); } }
public void RunTestCurrentVersionIdentical() { // tests with the current database without any changes. this should find nothing to import HouseholdPlan.FailOnIncorrectImport = true; using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var path = Path.Combine(wd.WorkingDirectory, "profilegeneratorNothingImportTest.db3"); if (File.Exists(path)) { File.Delete(path); Thread.Sleep(3000); } File.Copy(DatabaseSetup.GetSourcepath(null), path); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var dbm = new DatabaseMerger(mainSim); dbm.RunFindItems(path, null); Logger.Info("Found " + dbm.ItemsToImport.Count + " items."); if (dbm.ItemsToImport.Count != 0) { throw new LPGException("This should not import anything, since its the same database."); } db.Cleanup(); } wd.CleanUp(); } }
public void CalcParameterLoggerTest() { CalcParameters cp = CalcParameters.GetNew(); cp.SetStartDate(2017, 1, 1); cp.SetEndDate(2018, 1, 1); cp.Enable(CalcOption.ActivationsPerHour); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); CalcParameterLogger cpl = new CalcParameterLogger(srls); cpl.Run(Constants.GeneralHouseholdKey, cp); GC.Collect(); GC.WaitForPendingFinalizers(); CalcParameters cp2 = cpl.Load(); GC.Collect(); GC.WaitForPendingFinalizers(); string s1 = JsonConvert.SerializeObject(cp, Formatting.Indented); string s2 = JsonConvert.SerializeObject(cp2, Formatting.Indented); s1.Should().Be(s2); cp2.IsSet(CalcOption.ActivationsPerHour).Should().BeTrue(); Assert.NotNull(cp2); wd.CleanUp(); } }
public void CalcAffordanceDtoLoggerTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { CalcAffordanceDtoLogger ael = new CalcAffordanceDtoLogger(wd.SqlResultLoggingService); HouseholdKey key = new HouseholdKey("hhkey"); List <IDataSaverBase> savers = new List <IDataSaverBase> { ael }; InputDataLogger idl = new InputDataLogger(savers.ToArray()); //CalcLoadTypeDto cldto = new CalcLoadTypeDto("loadtype", 1, "kw", "kwh", 1, true, "guid"); CalcProfileDto cpd = new CalcProfileDto("name", 1, ProfileType.Absolute, "source", Guid.NewGuid().ToStrGuid()); AvailabilityDataReferenceDto adrd = new AvailabilityDataReferenceDto("blub", "availguid".ToStrGuid()); CalcAffordanceDto cadto = new CalcAffordanceDto("blub", 1, cpd, "locname", "locguid".ToStrGuid(), true, new List <CalcDesireDto>(), 1, 100, PermittedGender.All, true, 1, 1, 1, 1, "affcat", false, false, new List <CalcAffordanceVariableOpDto>(), new List <VariableRequirementDto>(), ActionAfterInterruption.GoBackToOld, "timelimitname", 100, true, "srctrait", "guid".ToStrGuid(), adrd, key, BodilyActivityLevel.Low); cadto.AddDeviceTuple("devname", "deviguid".ToStrGuid(), cpd, "calcloadtypename", "loadtypeguid".ToStrGuid(), 1, new TimeSpan(0, 1, 0), 1, 1); List <IHouseholdKey> aes = new List <IHouseholdKey> { cadto }; idl.SaveList(aes); var res = ael.Load(key); var s1 = JsonConvert.SerializeObject(aes, Formatting.Indented); var s2 = JsonConvert.SerializeObject(res, Formatting.Indented); s1.Should().Be(s2); wd.CleanUp(); } }
public void ReadTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { DeviceActivationEntryLogger ael = new DeviceActivationEntryLogger(wd.SqlResultLoggingService); HouseholdKey key = new HouseholdKey("hhkey"); List <IDataSaverBase> savers = new List <IDataSaverBase> { ael }; InputDataLogger idl = new InputDataLogger(savers.ToArray()); CalcLoadTypeDto cldto = new CalcLoadTypeDto("loadtype", "kw", "kwh", 1, true, "guid".ToStrGuid()); TimeStep ts = new TimeStep(1, 1, true); CalcDeviceDto cdd = new CalcDeviceDto("devicename", "device".ToStrGuid(), key, OefcDeviceType.Device, "devicecategoryname", "additionalname", "deviceguid".ToStrGuid(), "locationguid".ToStrGuid(), "locationname"); DeviceActivationEntry ae1 = new DeviceActivationEntry("affordancename", cldto, 1, "activator", 1, ts, cdd); List <IHouseholdKey> aes = new List <IHouseholdKey> { ae1 }; idl.SaveList(aes); var res = ael.Read(key); var s1 = JsonConvert.SerializeObject(aes, Formatting.Indented); var s2 = JsonConvert.SerializeObject(res, Formatting.Indented); s1.Should().Be(s2); wd.CleanUp(); } }
public void TestLocationEntryBasics() { Config.IsInUnitTesting = true; using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(1000); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod(); calcParameters.Options.Add(CalcOption.LocationsEntries); //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory,"blub",wd.InputDataLogger); //CalcLocation cl = new CalcLocation("blub", 1, Guid.NewGuid().ToStrGuid()); //Mock<ILogFile> lf = new Mock<ILogFile>(); //CalcPerson cp = MakeCalcPerson(cl,calcParameters,lf.Object); HouseholdKey key = new HouseholdKey("hh1"); TimeStep ts = new TimeStep(1, 0, false); LocationEntry le = new LocationEntry(key, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); DateStampCreator dsc = new DateStampCreator(calcParameters); using (OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService)); old.AddLocationEntry(le); old.FinalSaveToDatabase(); } var lel = new LocationEntryLogger(wd.SqlResultLoggingService); var e = lel.Load(key); e.Count.Should().Be(1); wd.CleanUp(); } }
public void RunTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { ActionEntryLogger ael = new ActionEntryLogger(wd.SqlResultLoggingService); HouseholdKey key = new HouseholdKey("hhkey"); List <IDataSaverBase> savers = new List <IDataSaverBase> { ael }; InputDataLogger idl = new InputDataLogger(savers.ToArray()); TimeStep ts = new TimeStep(1, 0, true); ActionEntry ae1 = new ActionEntry("blub", key, ts, DateTime.Now, "123".ToStrGuid(), "name", false, "affname", "affguid".ToStrGuid(), 0, BodilyActivityLevel.Low); List <IHouseholdKey> aes = new List <IHouseholdKey> { ae1 }; idl.SaveList(aes); var res = ael.Read(key); var s1 = JsonConvert.SerializeObject(aes, Formatting.Indented); var s2 = JsonConvert.SerializeObject(res, Formatting.Indented); s1.Should().Be(s2); wd.CleanUp(); } }
public void OnlineDeviceActivationProcessorArrayTest() { var rnd = new Random(1); var nr = new NormalRandom(0, 1, rnd); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); var calcParameters = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod(); //calcParameters.Enable(CalcOption.ActionsLogfile); calcParameters.Enable(CalcOption.DeviceProfilesIndividualHouseholds); calcParameters.Enable(CalcOption.DetailedDatFiles); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh1", wd.InputDataLogger)) { //SqlResultLoggingService srls = new SqlResultLoggingService(Path.Combine(wd.WorkingDirectory, "results.sqlite")); var dsc = new DateStampCreator(calcParameters); using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { var hhkey = new HouseholdKey("HH1"); fft.RegisterHousehold(Constants.GeneralHouseholdKey, "generalhousehold", HouseholdKeyType.General, "Description", null, null); fft.RegisterHousehold(hhkey, "hh1", HouseholdKeyType.Household, "Description", null, null); var odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var deviceGuid = "devguid".ToStrGuid(); var locationGuid = "locationGuid".ToStrGuid(); var loadtypeGuid = "ltguid".ToStrGuid(); var cdd = new CalcDeviceDto("devicename", "devcatguid".ToStrGuid(), hhkey, OefcDeviceType.Device, "devcatname", "", deviceGuid, locationGuid, "loc"); var key = new OefcKey(cdd, loadtypeGuid); var clt = new CalcLoadType("lt1", "W", "kWh", 1, true, loadtypeGuid); odap.RegisterDevice(clt.ConvertToDto(), cdd); double[] stepValues = { 1.0, 0 }; var valueList = new List <double>(stepValues); var cp = new CalcProfile("myCalcProfile", Guid.NewGuid().ToStrGuid(), valueList, ProfileType.Absolute, "synthetic"); var ts1 = new TimeStep(1, 0, false); var cdl = new CalcDeviceLoad("", 1, clt, 0, 0); var sv = StepValues.MakeStepValues(cp, 10, RandomValueProfile.MakeStepValues(cp.StepValues.Count, nr, 0), cdl); odap.AddNewStateMachine(ts1, clt.ConvertToDto(), "name1", "p1", key, cdd, sv); double[] resultValues = { 0, 10.0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (var i = 0; i < 10; i++) { var ts = new TimeStep(i, 0, true); var filerows = odap.ProcessOneTimestep(ts); filerows.Count.Should().Be(1); filerows[0].EnergyEntries.Count.Should().Be(1); Logger.Info(filerows[0].EnergyEntries[0].ToString(CultureInfo.CurrentCulture)); resultValues[i].Should().Be(filerows[0].EnergyEntries[0]); foreach (var fileRow in filerows) { fileRow.Save(odap.BinaryOutStreams[fileRow.LoadType]); } } } } Logger.Info(wd.WorkingDirectory); wd.CleanUp(); } }
public void TestImportWithHouseholdTemplateDelete880() { const string srcFileName = "profilegenerator880.db3"; string sourcepath = DatabaseSetup.GetImportFileFullPath(srcFileName); if (!File.Exists(sourcepath)) { throw new LPGException("Missing file!"); } using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var newpath = Path.Combine(wd.WorkingDirectory, "mergertest.db3"); File.Copy(sourcepath, newpath); using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); db.ClearTable(HouseholdTemplate.TableName); Database.DatabaseMerger.DatabaseMerger dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(newpath, null); dbm.RunImport(null); db.Cleanup(); } wd.CleanUp(); } }
public void RunTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { HouseholdKeyLogger ael = new HouseholdKeyLogger(wd.SqlResultLoggingService); HouseholdKey key = new HouseholdKey("hhkey"); List <IDataSaverBase> savers = new List <IDataSaverBase> { ael }; InputDataLogger idl = new InputDataLogger(savers.ToArray()); HouseholdKeyEntry ae1 = new HouseholdKeyEntry(key, "hhname", HouseholdKeyType.House, "desc", null, null); idl.Save(ae1); List <HouseholdKeyEntry> aes = new List <HouseholdKeyEntry> { ae1 }; var res = ael.Load(); var s1 = JsonConvert.SerializeObject(aes, Formatting.Indented); var s2 = JsonConvert.SerializeObject(res, Formatting.Indented); s1.Should().Be(s2); wd.CleanUp(); } }
public void PickRandomAffordanceFromEquallyAttractiveOnesTest() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults(); calcParameters.AffordanceRepetitionCount = 0; wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); //DateStampCreator dsc = new DateStampCreator(calcParameters); Random rnd = new Random(); //OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters); using (var lf = new LogFile(calcParameters, fft)) { CalcProfile cp = new CalcProfile("cp1", Guid.NewGuid().ToStrGuid(), TimeSpan.FromMinutes(1), ProfileType.Absolute, "bla"); CalcVariableRepository crv = new CalcVariableRepository(); BitArray isBusy = new BitArray(calcParameters.InternalTimesteps, false); using CalcRepo calcRepo = new CalcRepo(lf: lf, calcParameters: calcParameters, rnd: rnd); CalcAffordance aff1 = new CalcAffordance("aff1", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true, 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 900, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); CalcAffordance aff2 = new CalcAffordance("aff2", cp, null, false, new List <CalcDesire>(), 10, 20, PermittedGender.All, true, 1, LPGColors.AliceBlue, null, false, false, null, null, ActionAfterInterruption.GoBackToOld, "", 100, false, "", Guid.NewGuid().ToStrGuid(), crv, new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo); List <ICalcAffordanceBase> affs = new List <ICalcAffordanceBase> { aff1, aff2 }; int aff1C = 0; int aff2C = 0; BitArray isSick = new BitArray(calcParameters.InternalTimesteps); BitArray isOnVacation = new BitArray(calcParameters.InternalTimesteps); CalcPersonDto calcPerson = CalcPersonDto.MakeExamplePerson(); CalcPerson cperson = new CalcPerson(calcPerson, null, isSick, isOnVacation, calcRepo); TimeStep ts = new TimeStep(1, 0, true); for (int i = 0; i < 1000; i++) { ICalcAffordanceBase cab = cperson.PickRandomAffordanceFromEquallyAttractiveOnes(affs, ts, null, new HouseholdKey("bla")); if (cab == aff1) { aff1C++; } if (cab == aff2) { aff2C++; } } aff1C.Should().BeApproximatelyWithinPercent(900, 0.1); Logger.Info("Number of selections for 90%:" + aff1C + ", 10%:" + aff2C); } } wd.CleanUp(); } }
public void GetCalcManagerModularHousehold03Test() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { Config.IsInUnitTesting = true; var sim = new Simulator(db.ConnectionString); sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.ReasonableWithChartsAndPDF); DeviceCategory light = null; foreach (var deviceCategory in sim.DeviceCategories.MyItems) { deviceCategory.RefreshSubDevices(); if (deviceCategory.Name.Contains("Light")) { light = deviceCategory; } } if (light != null) { Logger.Info(light.SubDevices.Count.ToString(CultureInfo.CurrentCulture)); } sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerLoadtype); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerDevice); sim.MyGeneralConfig.Enable(CalcOption.MakePDF); sim.MyGeneralConfig.Enable(CalcOption.HouseholdContents); sim.Should().NotBeNull(); var cmf = new CalcManagerFactory(); ModularHousehold chs3 = null; foreach (var modularHousehold in sim.ModularHouseholds.MyItems) { if (modularHousehold.Name.StartsWith("CHS01", StringComparison.Ordinal)) { chs3 = modularHousehold; } } if (chs3 == null) { throw new LPGException("Could not find the household CHS01"); } Logger.Info(chs3.ToString()); CalculationProfiler calculationProfiler = new CalculationProfiler(); CalcStartParameterSet csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], chs3, EnergyIntensityType.Random, false, null, LoadTypePriority.Mandatory, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 15), new DateTime(2015, 1, 18), new TimeSpan(0, 1, 0), ";", -1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(ReportCancelFunc); cm.Dispose(); db.Cleanup(); } wd.CleanUp(); } }
public void GetLatestVersionTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { UpdateChecker uc = new UpdateChecker(); string s = uc.GetLatestVersion(out _); Logger.Info(s); wd.CleanUp(); } }
public void Version520TimeLimitImport() { string sourcefilepath = DatabaseSetup.GetImportFileFullPath("profilegenerator520_simon.db3"); CleanTestBase.RunAutomatically(false); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var fi = new FileInfo(sourcefilepath); if (!File.Exists(sourcefilepath)) { throw new LPGException("Missing file: " + fi.FullName); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var mainSim = new Simulator(db.ConnectionString); var dbm = new DatabaseMerger(mainSim); Logger.Info("Full Source: " + fi.FullName); dbm.RunFindItems(sourcefilepath, null); dbm.RunImport(null); var timelimits = dbm.ItemsToImport.Count(x => x.Entry.GetType() == typeof(TimeLimit)); timelimits.Should().BeGreaterThan(0); // ReSharper disable once UnusedVariable #pragma warning disable S1481 // Unused local variables should be removed var mainSim2 = new Simulator(db.ConnectionString); } #pragma warning restore S1481 // Unused local variables should be removed /*mainSim2.MyGeneralConfig.PerformCleanUpChecks = "false"; * var toDelete = new List<DeviceActionGroup>(); * foreach (DeviceActionGroup deviceActionGroup in mainSim2.DeviceActionGroups.It) { * var actions = deviceActionGroup.GetDeviceActions(mainSim2.DeviceActions.It); * if(actions.Count == 0) * toDelete.Add(deviceActionGroup); * } * foreach (DeviceActionGroup deviceActionGroup in toDelete) { * mainSim2.DeviceActionGroups.DeleteItem(deviceActionGroup); * } * var dsttag = mainSim2.TraitTags.It.First(x => x.Name.StartsWith("Living ")); * foreach (ModularHousehold modularHousehold in mainSim2.ModularHouseholds.It) { * var toSet = new List<ModularHouseholdPerson>(); * foreach (ModularHouseholdPerson modularHouseholdPerson in modularHousehold.Persons) { * if (modularHouseholdPerson.TraitTag == null) { * toSet.Add(modularHouseholdPerson); * } * } * foreach (ModularHouseholdPerson person in toSet) { * modularHousehold.SwapPersons(person, person.Person, dsttag); * } * modularHousehold.SaveToDB(); * } * SimIntegrityChecker.Run(mainSim2);*/ wd.CleanUp(); } CleanTestBase.RunAutomatically(true); }
public void SetTimeprofileTest() { DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(10); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate); CalcLoadType clt = MakeCalcLoadType(); CalcLocation cloc = new CalcLocation("blub", Guid.NewGuid().ToStrGuid()); CalcDeviceLoad cdl = new CalcDeviceLoad("cdl1", 1, clt, 1, 0.1); List <CalcDeviceLoad> cdls = new List <CalcDeviceLoad>(); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); using (FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh1", wd.InputDataLogger)) { fft.RegisterHousehold(Constants.GeneralHouseholdKey, "General", HouseholdKeyType.General, "desc", null, null); //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); DateStampCreator dsc = new DateStampCreator(calcParameters); using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { cdls.Add(cdl); OnlineDeviceActivationProcessor odap = new OnlineDeviceActivationProcessor(old, calcParameters, fft); var deviceCategoryGuid = Guid.NewGuid().ToStrGuid(); CalcDeviceDto cdd = new CalcDeviceDto("bla", deviceCategoryGuid , new HouseholdKey("HH-6"), OefcDeviceType.Device, "category", string.Empty, Guid.NewGuid().ToStrGuid(), cloc.Guid, cloc.Name); using CalcRepo calcRepo = new CalcRepo(odap: odap, calcParameters: calcParameters, normalRandom: NormalRandom); CalcDevice cd = new CalcDevice(cdls, cloc, cdd, calcRepo); CalcProfile cp = MakeCalcProfile5Min100(); TimeStep ts1 = new TimeStep(1, calcParameters); cd.SetAllLoadTypesToTimeprofile(cp, ts1, "test", "name1", 1); TimeStep ts = new TimeStep(0, calcParameters); cd.IsBusyDuringTimespan(ts, 1, 1, clt).Should().BeFalse(); cd.IsBusyDuringTimespan(ts.AddSteps(1), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(2), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(3), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(4), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(5), 1, 1, clt).Should().BeTrue(); cd.IsBusyDuringTimespan(ts.AddSteps(6), 0, 1, clt).Should().BeFalse(); } } wd.CleanUp(); } }
public void RunTestCurrentDeviceCategory() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { const string path = "profilegeneratorcopy.db3"; if (File.Exists(path)) { File.Delete(path); } string sourcefile = DatabaseSetup.GetSourcepath(null); File.Copy(sourcefile, path); if (!File.Exists(path)) { throw new LPGException("Missing file!"); } using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { db.ClearTable(DeviceCategory.TableName); db.ClearTable(AffordanceDevice.TableName); var mainSim = new Simulator(db.ConnectionString); var dbm = new Database.DatabaseMerger.DatabaseMerger(mainSim); dbm.RunFindItems(path, null); foreach (var dbBase in dbm.ItemsToImport) { Logger.Error(dbBase.Entry.Name + " " + dbBase.Import); dbBase.Import = true; } dbm.RunImport(null); var newCategories = mainSim.DeviceCategories.CollectAllDBBaseItems(); var oldCategories = dbm.OldSimulator.DeviceCategories.CollectAllDBBaseItems(); var newcats = new Dictionary <string, DeviceCategory>(); foreach (var newCategory in newCategories) { var cat = (DeviceCategory)newCategory; newcats.Add(cat.ShortName, cat); } foreach (var oldCategory in oldCategories) { Logger.Debug("checking: " + oldCategory.Name); var oldCat = (DeviceCategory)oldCategory; newcats.ContainsKey(oldCat.ShortName).Should().BeTrue(); var newcat = newcats[oldCat.ShortName]; newcat.FullPath.Should().Be(oldCat.FullPath); newcat.ParentCategory?.Name.Should().Be(oldCat.ParentCategory?.Name); } db.Cleanup(); } wd.CleanUp(throwAllErrors: false); } }
public void VariableLogfileTests1() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new VariableEntryLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService)); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod(); using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger)) { HouseholdKey key = new HouseholdKey("hh1"); fft.RegisterGeneralHouse(); fft.RegisterHousehold(key, "householdname", HouseholdKeyType.Household, "desc", null, null); DateStampCreator dsc = new DateStampCreator(calcParameters); using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { CalcVariableRepository cvr = new CalcVariableRepository(); //using (LogFile lf = new LogFile(calcParameters,fft, old,wd.SqlResultLoggingService, true)) CalcLocation cloc = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid()); CalcVariable cv = new CalcVariable("mycalcvar", Guid.NewGuid().ToStrGuid(), 0, cloc.Name, cloc.Guid, key); cvr.RegisterVariable(cv); TimeStep ts = new TimeStep(0, calcParameters); old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 1, cv.LocationName, cv.LocationGuid, cv.HouseholdKey, ts)); old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 2, cv.LocationName, cv.LocationGuid, cv.HouseholdKey, ts)); old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 3, cv.LocationName, cv.LocationGuid, cv.HouseholdKey, ts)); old.FinalSaveToDatabase(); } VariableEntryLogger vel = new VariableEntryLogger(wd.SqlResultLoggingService); var varEntries = vel.Read(key); foreach (CalcVariableEntry entry in varEntries) { Logger.Info(entry.Value.ToString(CultureInfo.InvariantCulture)); } varEntries[0].Value.Should().Be(1); varEntries[1].Value.Should().Be(2); varEntries[2].Value.Should().Be(3); } /*old. * cloc.Add(); * cloc[0].Variables.Add("trig1", 1.0); * tlf.WriteLine(0, cloc); * cloc[0].Variables["trig1"] = 2.0; * tlf.WriteLine(1, cloc); * lf.Close(null);*/ wd.CleanUp(); } }
public void MakeNRWChartTest() { CleanTestBase.RunAutomatically(false); using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var versions = sim.CalculationOutcomes.It.Select(x => x.LPGVersion).Distinct().ToList(); versions.Sort(); var dstversion = versions.Last(); //ChartLocalizer.ShouldTranslate = false; var se1 = new MakeNRWChart.SeriesEntry(0.1, "EnergyIntensivePreferMeasured", "Energieintensive Gerätewahl", dstversion); var se2 = new MakeNRWChart.SeriesEntry(-0.1, "EnergySavingPreferMeasured", "Energiesparende Gerätewahl", dstversion); //MakeNRWChart.SeriesEntry se3 = new MakeNRWChart.SeriesEntry(-0.1, "EnergyIntensive","EnergyIntensive Gerätewahl", dstversion); //MakeNRWChart.SeriesEntry se4 = new MakeNRWChart.SeriesEntry(-0.1, "EnergySaving", "EnergySaving Gerätewahl", dstversion); var seriesEntries = new List <MakeNRWChart.SeriesEntry> { se1, se2 }; // seriesEntries.Add(se3); // seriesEntries.Add(se4); CalculationProfiler cp = new CalculationProfiler(); foreach (var version in versions) { var v = version; var versionEntries = sim.CalculationOutcomes.It.Where(x => x.LPGVersion == v).ToList(); if (versionEntries.Count == 0) { throw new LPGException("No Entries Found"); } var mnc = new MakeNRWChart(150, 1000, 1600, cp); var pngname = Path.Combine(wd.WorkingDirectory, "testchart." + version + ".png"); // string pdfname = Path.Combine(wd.WorkingDirectory, "testchart." + version + ".pdf"); mnc.MakeScatterChart(versionEntries, pngname, seriesEntries); } var imagefiles = FileFinder.GetRecursiveFiles(new DirectoryInfo(wd.WorkingDirectory), "testchart.*.png"); imagefiles.Count.Should().BeGreaterOrEqualTo(1); db.Cleanup(); } wd.CleanUp(); } CleanTestBase.RunAutomatically(true); }
public void RunBrokenHouseholdCalcTest() { Config.IsInHeadless = true; using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var db = new FileInfo(@"V:\Dropbox\LPG\ImportFiles\profilegenerator900.db3"); string fullDstPath = Path.Combine(wd.WorkingDirectory, "profilegenerator.db3"); db.CopyTo(fullDstPath); Directory.SetCurrentDirectory(wd.WorkingDirectory); Simulator sim = new Simulator("Data Source=" + fullDstPath); sim.Should().NotBeNull(); wd.CleanUp(); } }
public void DumpHouseholdContentsToTextTest() { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { using (var wd1 = new WorkingDir(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString) { MyGeneralConfig = { StartDateUIString = "01.01.2015", EndDateUIString = "02.01.2015", InternalTimeResolution = "00:01:00", ExternalTimeResolution = "00:15:00", RandomSeed = 5 } }; sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.NoFiles); sim.MyGeneralConfig.Enable(CalcOption.TotalsPerDevice); sim.MyGeneralConfig.CSVCharacter = ";"; //ConfigSetter.SetGlobalTimeParameters(sim.MyGeneralConfig); sim.Should().NotBeNull(); SimIntegrityChecker.Run(sim); CalcManagerFactory.DoIntegrityRun = false; var cmf = new CalcManagerFactory(); var calculationProfiler = new CalculationProfiler(); var csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.Random, false, null, LoadTypePriority.RecommendedForHouses, null, null, null, sim.MyGeneralConfig.AllEnabledOptions(), new DateTime(2015, 1, 1), new DateTime(2015, 1, 2), new TimeSpan(0, 1, 0), ";", 5, new TimeSpan(0, 15, 0), false, false, false, 3, 3, calculationProfiler, wd1.WorkingDirectory, false); var cm = cmf.GetCalcManager(sim, csps, false); //,, wd1.WorkingDirectory, sim.ModularHouseholds[0], false, //sim.TemperatureProfiles[0], sim.GeographicLocations[0], EnergyIntensityType.Random, version, //LoadTypePriority.RecommendedForHouses, null,null var dls = new DayLightStatus(new BitArray(100)); if (cm.CalcObject == null) { throw new LPGException("xxx"); } cm.CalcObject.Init(dls, 1); CalcManager.ExitCalcFunction = true; cm.CalcObject.DumpHouseholdContentsToText(); cm.Dispose(); db.Cleanup(); wd1.CleanUp(); } } }
public void CreateTableFromFieldlistTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.ClearDirectory(); var srl = new SqlResultLoggingService(wd.WorkingDirectory); SqlResultLoggingService.FieldDefinition fd = new SqlResultLoggingService.FieldDefinition("name", "text"); List <SqlResultLoggingService.FieldDefinition> fields = new List <SqlResultLoggingService.FieldDefinition> { fd }; srl.MakeTableForListOfFields(fields, new HouseholdKey("hh0"), "tbl1"); wd.CleanUp(); } }
public void Run() { using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass())) { var sim = new Simulator(db.ConnectionString); var calculationProfiler = new CalculationProfiler(); var csps = new CalcStartParameterSet(sim.GeographicLocations[0], sim.TemperatureProfiles[0], sim.ModularHouseholds[0], EnergyIntensityType.EnergySaving, false, null, LoadTypePriority.OptionalLoadtypes, null, null, null, new List <CalcOption>(), new DateTime(2018, 1, 1), new DateTime(2018, 1, 10), new TimeSpan(0, 1, 0), ";", 1, new TimeSpan(0, 1, 0), false, false, false, 3, 3, calculationProfiler, wd.WorkingDirectory, false); var cmf = new CalcManagerFactory(); var cm = cmf.GetCalcManager(sim, csps, false); cm.Run(null); var mq = new Mock <ICalculationProfiler>(); wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService)); //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory,"objname",cm.Logfile.FileFactoryAndTracker); //fft.RegisterHouseholdKey(Constants.GeneralHouseholdKey,"general"); //fft.RegisterHouseholdKey(Constants.GeneralHouseholdKey,"general"); var pcm = new PostProcessingManager(mq.Object, cm.CalcRepo.FileFactoryAndTracker); //Debug.Assert(calcResult != null, nameof(calcResult) + " != null"); pcm.Run(wd.WorkingDirectory); db.Cleanup(); } wd.CleanUp(); } }
public void SaveDictionaryCalcParametersTest() { using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.ClearDirectory(); var srl = new SqlResultLoggingService(wd.WorkingDirectory); var hhkey = new HouseholdKey("hh0"); ResultTableDefinition rtd = new ResultTableDefinition("tbl1", ResultTableID.AffordanceDefinitions, "tabledesc", CalcOption.BasicOverview); SaveableEntry se = new SaveableEntry(hhkey, rtd); se.AddField("Name", SqliteDataType.Text); se.AddField("Json", SqliteDataType.Text); se.AddRow(RowBuilder.Start("Name", "first").Add("Json", "[]").ToDictionary()); srl.SaveResultEntry(se); wd.CleanUp(); } }
public void TestLocationEntryBasicsWithFile() { Config.IsInUnitTesting = true; using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService)); DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(1000); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod(); calcParameters.Options.Add(CalcOption.LocationsEntries); //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hhname", wd.InputDataLogger); //LocationsLogFile llf = new LocationsLogFile(true, fft, calcParameters); //CalcLocation cl = new CalcLocation("blub", 1, Guid.NewGuid().ToStrGuid()); //Mock<ILogFile> lf = new Mock<ILogFile>(); //CalcPerson cp = MakeCalcPerson(cl,calcParameters,lf.Object); //LocationEntry le = new LocationEntry(cp, 1, cl,calcParameters); //llf.WriteEntry(le, new HouseholdKey("HH1")); //llf.WriteEntry(le, new HouseholdKey("HH2")); //llf.WriteEntry(le, new HouseholdKey("HH3")); //llf.Close(); HouseholdKey key1 = new HouseholdKey("hh1"); TimeStep ts = new TimeStep(1, 0, false); LocationEntry le1 = new LocationEntry(key1, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); HouseholdKey key2 = new HouseholdKey("hh2"); LocationEntry le2 = new LocationEntry(key2, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); HouseholdKey key3 = new HouseholdKey("hh3"); LocationEntry le3 = new LocationEntry(key3, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); DateStampCreator dsc = new DateStampCreator(calcParameters); using (OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { old.AddLocationEntry(le1); old.AddLocationEntry(le2); old.AddLocationEntry(le3); old.FinalSaveToDatabase(); } LocationEntryLogger lel = new LocationEntryLogger(wd.SqlResultLoggingService); var le = lel.Load(key1); Logger.Info("count: " + le.Count); string prev = JsonConvert.SerializeObject(le1, Formatting.Indented); string loaded = JsonConvert.SerializeObject(le[0], Formatting.Indented); loaded.Should().Be(prev); wd.CleanUp(); } }