public void SummaryWriterFlushTest() { var stream = new StringStream(); var summaryWriter = new SummaryWriter(stream.Writer) { IdleFlushRate = 10, NonIdleFlushRate = 5 }; for (var i = 0; i < 3; i++) { var measurement = new Measurement(new DateTime(2020, 12, 28, 0, 0, i), 2400 + i, 8000 + i); var result = new FlowMeter { Amplitude = i, HighPass = 0, LowPassFast = 2400, LowPassSlow = 2402, Exclude = false, ExcludeAll = false, Flow = false, LowPassOnHighPass = 5 - i, Outlier = false, Drift = false }; summaryWriter.AddMeasurement(measurement, result); summaryWriter.PrepareWrite(); summaryWriter.Write(); Assert.IsTrue(string.IsNullOrEmpty(stream.Content()), "nothing written yet"); } summaryWriter.Flush(); Assert.AreEqual("S,3,0,0,0,2400,2402,3,0,0,0,8001,50790\r\n", stream.Content(), "flush worked"); }
public void SummaryWriterFlowTest() { var stream = new StringStream(); var summaryWriter = new SummaryWriter(stream.Writer) { IdleFlushRate = 10, NonIdleFlushRate = 5 }; for (var i = 0; i < 10; i++) { var measurement = new Measurement(new DateTime(2020, 12, 28, 0, 0, i), 2400 + i, 8000 + i); var result = new FlowMeter { Amplitude = 5 + (i > 7 ? 10 : 0), HighPass = 0, LowPassFast = 2400, LowPassSlow = 2398, Exclude = false, ExcludeAll = false, Flow = i > 7, LowPassOnHighPass = i, Outlier = false, Drift = false }; summaryWriter.AddMeasurement(measurement, result); summaryWriter.PrepareWrite(); summaryWriter.Write(); if (i < 9) { Assert.IsTrue(string.IsNullOrEmpty(stream.Content()), "Nothing written the first 9 data points"); } else { //"S,Measure,Flows,SumAmplitude,SumLPonHP,LowPassFast,LowPassSlow,LPonHP,Outliers,Waits,Excludes,AvgDelay,CRC" Assert.AreEqual("S,10,2,30,17,2400,2398,9,0,0,0,8005,56358\r\n", stream.Content(), "After 10 points, we get a summary with 2 flows, and SumAmplitude and SumLPonP are populated"); } } // Flush should not change anything as we have no more data. summaryWriter.Flush(); Assert.AreEqual("S,10,2,30,17,2400,2398,9,0,0,0,8005,56358\r\n", stream.Content(), "After 10 points, we get a summary with 2 flows, and SumAmplitude and SumLPonP are populated"); }