public void Fetch() { TimeRunner.Run(async(time, th) => { var downloader = new FakeElexonDownloader(); var dir = new FakeDirectory(th); var fetcher = new FetchPhyBmData(th, downloader, dir, time); var cts = new CancellationTokenSource(); Task unused = th.Run(async() => { await th.Delay(NodaTime.Duration.FromMinutes(60)).ConfigureAwait(th); cts.Cancel(); }); await fetcher.Start(false, cts.Token).ConfigureAwaitHideCancel(th); var reader = new PhyBmData.FpnReader(th, dir); Assert.Equal(1031 + 1023, await reader.CountAsync().ConfigureAwait(th)); var cldcwIdHash = EicIds.Hash("CLDCW-1"); var cldcwTask = (await reader.ReadAsync().ConfigureAwait(th)).Where(x => x.ResourceNameHash == cldcwIdHash); var cldcw = await cldcwTask.ToList().ConfigureAwait(th); Assert.Equal(4, cldcw.Count); Assert.Equal(new [] { 13.0, 11.0, 11.0, 9.0 }, cldcw.Select(x => x.LevelTo.Megawatts)); }, startInstant: NodaTime.Instant.FromUtc(2017, 8, 5, 22, 29)); }
public void Download() { TimeRunner.Run(async(time, th) => { var phy = new PhyBmData(th, new FakeElexonDownloader()); var data = await phy.GetAsync(new LocalDate(2017, 8, 6), 1).ConfigureAwait(th); Assert.Equal(1031, data.Count); Assert.Equal(Power.FromMegawatts(-225), data[0].LevelFrom); var fpn0 = new PhyBmData.FpnData("EAS-BGS01", Instant.FromUtc(2017, 8, 5, 23, 0), Power.FromMegawatts(-225), Instant.FromUtc(2017, 8, 5, 23, 30), Power.FromMegawatts(-225)); Assert.Equal(fpn0, data[0]); var fpnLast = new PhyBmData.FpnData("RHAMD-1", Instant.FromUtc(2017, 8, 5, 23, 0), Power.FromMegawatts(-2), Instant.FromUtc(2017, 8, 5, 23, 30), Power.FromMegawatts(-2)); Assert.Equal(fpnLast, data.Last()); var whilw1 = data.Where(x => x.ResourceNameHash == EicIds.Hash("WHILW-1")).ToImmutableList(); Assert.Equal(2, whilw1.Count); var whilw1Fpn0 = new PhyBmData.FpnData("WHILW-1", Instant.FromUtc(2017, 8, 5, 23, 0), Power.FromMegawatts(25), Instant.FromUtc(2017, 8, 5, 23, 1), Power.FromMegawatts(14)); Assert.Equal(whilw1Fpn0, whilw1[0]); var whilw1Fpn1 = new PhyBmData.FpnData("WHILW-1", Instant.FromUtc(2017, 8, 5, 23, 1), Power.FromMegawatts(14), Instant.FromUtc(2017, 8, 5, 23, 30), Power.FromMegawatts(14)); Assert.Equal(whilw1Fpn1, whilw1[1]); }); }
public void DownloadEmpty() { TimeRunner.Run(async(time, th) => { var phy = new PhyBmData(th, new FakeElexonDownloader()); var data = await phy.GetAsync(new LocalDate(2018, 1, 1), 1).ConfigureAwait(th); Assert.Empty(data); }); }
public void ReadCount() { TimeRunner.Run(async(time, th) => { var(dir, _) = BuildData(th); var reader = new Data.Reader(th, dir); Assert.Equal(5, await reader.CountAsync().ConfigureAwait(th)); }); }
public void DownloadEmpty() { TimeRunner.Run(async(time, th) => { var freq = new Freq(th, new FakeElexonDownloader()); var data = await freq.GetAsync(Instant.FromUtc(2018, 1, 1, 0, 0), Instant.FromUtc(2018, 1, 1, 0, 1)).ConfigureAwait(th); Assert.Empty(data); }); }
public void ReadThreeVersions() { TimeRunner.Run(async(time, th) => { var(dir, expected) = BuildData(th); var reader = new Data.Reader(th, dir); var data = await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th); Assert.Equal(expected, data); }); }
public void ReadEmpty() { TimeRunner.Run(async(time, th) => { var dir = new FakeDirectory(th); var reader = new Data.Reader(th, dir); var data = await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th); Assert.Empty(data); }); }
public void WatchTimeoutCancelled() => TimeRunner.Run(async(time, th) => { var dir = new FakeDirectory(th); var cts = new CancellationTokenSource(); var timedOutTask = dir.AwaitChange("", Duration.FromSeconds(10), cts.Token); await th.Delay(Duration.FromSeconds(5)); cts.Cancel(); var cancelled = await timedOutTask.ConfigureAwaitHideCancel(th); Assert.True(cancelled); });
public void WatchTimeout() => TimeRunner.Run(async(time, th) => { var dir = new FakeDirectory(th); var timedOut0 = await dir.AwaitChange("", Duration.FromSeconds(10)).ConfigureAwait(th); Assert.True(timedOut0); var timedOut1Task = dir.AwaitChange("", Duration.FromSeconds(10)); await th.Delay(Duration.FromSeconds(5)); await dir.AppendAsync("afile", new byte[] { 0 }).ConfigureAwait(th); var timedOut1 = await timedOut1Task.ConfigureAwait(th); Assert.False(timedOut1); });
public void Download() { TimeRunner.Run(async(time, th) => { var freq = new Freq(th, new FakeElexonDownloader()); var data = await freq.GetAsync(Instant.FromUtc(2017, 8, 2, 10, 30), Instant.FromUtc(2017, 8, 2, 11, 30)).ConfigureAwait(th); Assert.Equal(60 * 4 + 1, data.Count); Assert.Equal(new Freq.Data(Instant.FromUtc(2017, 8, 2, 10, 30), Frequency.FromHertz(50.014)), data.First()); Assert.Equal(new Freq.Data(Instant.FromUtc(2017, 8, 2, 11, 30), Frequency.FromHertz(50.165)), data.Last()); }); }
public void FewInt() => TimeRunner.Run(async(time, th) => { var reader = new FakeReader <int>(th) { 0, 1, 2, 3 }; using (var db = new Db <int>(th, reader, disableWatch: true)) { await db.InitialiseTask.ConfigureAwait(th); Assert.Equal(new [] { 2, 3 }, db.Where(x => x >= 2).ToImmutableArray()); } });
/// <summary> /// The create. /// </summary> /// <param name="settings"> /// The settings. /// </param> /// <returns> /// The <see cref="BiscuitMakerObject"/>. /// </returns> public static BiscuitMakerObject Create(BiscuitMakerSettings settings = null) { var settingsAreValid = BiscuitMakerSettingsValidator.ValidateSettings(settings, false); if (!settingsAreValid) { return(null); } var components = new List <IBiscuitComponent>(); var switchComponent = Switch.Create(); components.Add(switchComponent); var switcher = new Switcher(); components.Add(switcher); if (settings != null) { var conveyor = Conveyor.Create(count: settings.ConveyorSize); components.Add(conveyor); } if (settings != null) { var oven = Oven.Create(settings.RoomTemperature); components.Add(oven); } var bucket = BiscuitBucket.Create(); components.Add(bucket); var motor = new Motor(); components.Add(motor); var timeRunner = new TimeRunner(); components.Add(timeRunner); var biscuitMaker = BiscuitMakerObject.Create(components, settings); biscuitMaker.FirstSwitcher.RaiseSwitchOn += OvenManager.HandleSwitchOn; biscuitMaker.FirstTimeRunner.RaiseClockTick += OvenManager.HandleClockTick; biscuitMaker.FirstTimeRunner.RaiseClockTick += biscuitMaker.FirstMotor.HandleClockTick; biscuitMaker.FirstMotor.RaisePulse += ConveyorManager.HandleMotorPulse; return(biscuitMaker); }
public void TickTest() { var hasTicked = false; var runner = new TimeRunner(); runner.RaiseClockTick += (s, e) => hasTicked = true; Action act = () => runner.Tick(this.Maker); act.Should().NotThrow(); hasTicked.Should().BeTrue(); }
public void FirstOrDefault() => TimeRunner.Run(async(time, th) => { var reader = new FakeReader <int>(th) { 0, 1, 2, 3 }; using (var db = new Db <int>(th, reader)) { await db.InitialiseTask.ConfigureAwait(th); Assert.Equal(0, db.FirstOrDefault()); Assert.Null(db.Take(0).FirstOrDefault()); } });
public void WriterReadSingleVersion() { TimeRunner.Run(async(time, th) => { var dir = new FakeDirectory(th); var writer = new Data.Writer(th, dir); var reader = new Data.Reader(th, dir); Assert.Empty(await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th)); await writer.AppendAsync(new Data(1, 2, 3)).ConfigureAwait(th); Assert.Equal(new [] { new Data(1, 2, 3) }, await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th)); await writer.AppendAsync(new Data(4, 5, 6)).ConfigureAwait(th); Assert.Equal(new [] { new Data(1, 2, 3), new Data(4, 5, 6) }, await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th)); Assert.Single(await dir.ListFilesAsync().ConfigureAwait(th)); }); }
public void AddEntries() { TimeRunner.Run(async(time, th) => { const string filename = "data.seqid.00000001.version.1.elementsize.8.datastore"; var e = Bits.Empty; var idBits = e.Concat(ImmutableArray.Create(DataStore.ID_BYTE_1, DataStore.ID_BYTE_2)); var data = e.Concat(idBits).Concat(e.AddInt(100).AddFletcher16); var dir = new FakeDirectory(th); var reader = new Data.Reader(th, dir); Assert.Empty(await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th)); await dir.AppendAsync(filename, data); Assert.Equal(1, await reader.CountAsync().ConfigureAwait(th)); Assert.Single(await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th)); await dir.AppendAsync(filename, data); Assert.Equal(2, await reader.CountAsync().ConfigureAwait(th)); Assert.Equal(2, (await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th)).Count()); }); }
public void AppendLines() { TimeRunner.Run(async(time, th) => { var nl = Environment.NewLine; var expected = $"one{nl}two{nl}"; var dir = new FakeDirectory(th); var appender = new RollingFileAppender(dir, "abc", th); await appender.AppendLineAsync("one").ConfigureAwait(th); await appender.AppendLineAsync("two").ConfigureAwait(th); var files = (await dir.ListFilesAsync().ConfigureAwait(th)).ToList(); Assert.Single(files); Assert.Equal(expected.Length, files[0].Length); var stream = await dir.ReadAsync(files[0].Id).ConfigureAwait(th); var ms = new MemoryStream(); await stream.CopyToAsync(ms).ConfigureAwait(th); Assert.Equal(expected, Encoding.UTF8.GetString(ms.ToArray())); }); }
public void StoreAndLoad() { TimeRunner.Run(async(time, th) => { var dir = new FakeDirectory(th); var freq = new Freq(th, new FakeElexonDownloader()); var data = (await freq.GetAsync(Instant.FromUtc(2017, 8, 2, 10, 30), Instant.FromUtc(2017, 8, 2, 11, 30)).ConfigureAwait(th)); var writer = new Freq.Writer(th, dir); var reader = new Freq.Reader(th, dir); Assert.Equal(0, await reader.CountAsync().ConfigureAwait(th)); Assert.Equal(0, await(await reader.ReadAsync().ConfigureAwait(th)).Count().ConfigureAwait(th)); await writer.AppendAsync(data).ConfigureAwait(th); Assert.Equal(60 * 4 + 1, await reader.CountAsync().ConfigureAwait(th)); Assert.Equal(data[0], await(await reader.ReadAsync(0, 1).ConfigureAwait(th)).Single().ConfigureAwait(th)); Assert.Equal(data[10], await(await reader.ReadAsync(10, 11).ConfigureAwait(th)).Single().ConfigureAwait(th)); Assert.Equal(data.Take(10), await(await reader.ReadAsync(0, 10).ConfigureAwait(th)).ToArray().ConfigureAwait(th)); Assert.Equal(data.Skip(50).Take(10), await(await reader.ReadAsync(50, 60).ConfigureAwait(th)).ToArray().ConfigureAwait(th)); Assert.Equal(data, await(await reader.ReadAsync().ConfigureAwait(th)).ToList().ConfigureAwait(th)); }); }
public void StoreAndLoad() { TimeRunner.Run(async(time, th) => { var dir = new FakeDirectory(th); var fuelInstHhCur = new FuelInstHhCur(th, new FakeElexonDownloader()); var data = await fuelInstHhCur.GetAsync().ConfigureAwait(th); var writer = new FuelInstHhCur.Writer(th, dir); var reader = new FuelInstHhCur.Reader(th, dir); Assert.Equal(0, await reader.CountAsync().ConfigureAwait(th)); Assert.Equal(0, await(await reader.ReadAsync().ConfigureAwait(th)).Count().ConfigureAwait(th)); await writer.AppendAsync(data).ConfigureAwait(th); Assert.Equal(1, await reader.CountAsync().ConfigureAwait(th)); Assert.Equal(1, await(await reader.ReadAsync().ConfigureAwait(th)).Count().ConfigureAwait(th)); var data1 = await(await reader.ReadAsync().ConfigureAwait(th)).Last().ConfigureAwait(th); Assert.Equal(data, data1); var data2 = await(await reader.ReadAsync(0, 1).ConfigureAwait(th)).Single().ConfigureAwait(th); Assert.Equal(data, data2); }); }
public void StoreAndLoad() { TimeRunner.Run(async(time, th) => { var dir = new FakeDirectory(th); var phy = new PhyBmData(th, new FakeElexonDownloader()); var data = await phy.GetAsync(new LocalDate(2017, 8, 6), 1).ConfigureAwait(th); var writer = new PhyBmData.FpnWriter(th, dir); var reader = new PhyBmData.FpnReader(th, dir); Assert.Equal(0, await reader.CountAsync().ConfigureAwait(th)); Assert.Equal(0, await(await reader.ReadAsync().ConfigureAwait(th)).Count().ConfigureAwait(th)); await writer.AppendAsync(data).ConfigureAwait(th); Assert.Equal(1031, await reader.CountAsync().ConfigureAwait(th)); Assert.Equal(data[0], await(await reader.ReadAsync(0, 1).ConfigureAwait(th)).Single().ConfigureAwait(th)); Assert.Equal(data[10], await(await reader.ReadAsync(10, 11).ConfigureAwait(th)).Single().ConfigureAwait(th)); Assert.Equal(data.Take(10), await(await reader.ReadAsync(0, 10).ConfigureAwait(th)).ToArray().ConfigureAwait(th)); Assert.Equal(data.Skip(50).Take(10), await(await reader.ReadAsync(50, 60).ConfigureAwait(th)).ToArray().ConfigureAwait(th)); Assert.Equal(data, await(await reader.ReadAsync().ConfigureAwait(th)).ToList().ConfigureAwait(th)); }); }
public void ScheduledActionOverlong() { TimeRunner.Run(async(time, th) => { List <Instant> times = new List <Instant>(); var t0 = time.GetCurrentInstant(); var scheduler = new Scheduler(time, th); while (time.GetCurrentInstant() <= t0 + Duration.FromSeconds(40)) { await scheduler.ScheduleOne(Duration.FromSeconds(10), Duration.FromSeconds(1)).ConfigureAwait(th); times.Add(time.GetCurrentInstant()); await th.Delay(Duration.FromSeconds(15)).ConfigureAwait(th); } var expected = new [] { t0 + S(1), t0 + S(21), t0 + S(41), }; Assert.Equal(expected, times); }); }
public void Download() { TimeRunner.Run(async(time, th) => { var fuelInstHhCur = new FuelInstHhCur(th, new FakeElexonDownloader()); var data = await fuelInstHhCur.GetAsync().ConfigureAwait(th); Assert.Equal(Instant.FromUtc(2017, 5, 11, 17, 55, 0), data.Update); Assert.Equal(Power.FromMegawatts(18384), data.Ccgt); Assert.Equal(Power.FromMegawatts(0), data.Ocgt); Assert.Equal(Power.FromMegawatts(0), data.Oil); Assert.Equal(Power.FromMegawatts(645), data.Coal); Assert.Equal(Power.FromMegawatts(6552), data.Nuclear); Assert.Equal(Power.FromMegawatts(2714), data.Wind); Assert.Equal(Power.FromMegawatts(1193), data.Ps); Assert.Equal(Power.FromMegawatts(254), data.Npshyd); Assert.Equal(Power.FromMegawatts(1443), data.Other); Assert.Equal(Power.FromMegawatts(1997), data.IntFr); Assert.Equal(Power.FromMegawatts(78), data.IntIrl); Assert.Equal(Power.FromMegawatts(989), data.IntNed); Assert.Equal(Power.FromMegawatts(0), data.IntEw); }); }
public void Fetch() { TimeRunner.Run(async(time, th) => { var downloader = new FakeElexonDownloader(); var dir = new FakeDirectory(th); var fetcher = new FetchFreq(th, downloader, dir, time); var cts = new CancellationTokenSource(); Task unused = th.Run(async() => { await th.Delay(NodaTime.Duration.FromMinutes(3)).ConfigureAwait(th); cts.Cancel(); }); await fetcher.Start(false, cts.Token).ConfigureAwaitHideCancel(th); var reader = new Freq.Reader(th, dir); Assert.Equal((60 + 2) * 4, await reader.CountAsync().ConfigureAwait(th)); var data = await(await reader.ReadAsync().ConfigureAwait(th)).ToList().ConfigureAwait(th); Assert.Equal((60 + 2) * 4, data.Count); Assert.Equal(new Freq.Data(NodaTime.Instant.FromUtc(2017, 8, 2, 11, 0, 15), Frequency.FromHertz(49.910)), data.First()); Assert.Equal(new Freq.Data(NodaTime.Instant.FromUtc(2017, 8, 2, 12, 2, 0), Frequency.FromHertz(50.040)), data.Last()); }, startInstant: NodaTime.Instant.FromUtc(2017, 8, 2, 12, 0)); }