public void ShouldDiscardAllButMostRecentStaleInputParametersAfterStalenessInterval() { var c = new Controller(); var mc = new FakeMulticlampCommander(); var mcd = new MultiClampDevice(mc, c, UNUSED_BACKGROUND_DICTIONARY); mcd.BindStream(new DAQInputStream(UNUSED_NAME)); var data1 = new MultiClampInterop.MulticlampData(); var expected2 = new MultiClampInterop.MulticlampData(); var expected = new MultiClampInterop.MulticlampData(); var marker = DateTimeOffset.Now.ToUniversalTime(); mc.FireParametersChanged(marker.Subtract(TimeSpan.FromSeconds(MultiClampDevice.ParameterStalenessInterval.TotalSeconds * 3)), data1); mc.FireParametersChanged(marker.Subtract(TimeSpan.FromSeconds(MultiClampDevice.ParameterStalenessInterval.TotalSeconds * 2)), expected); mc.FireParametersChanged(marker, expected2); Assert.That(((MultiClampParametersChangedArgs)mcd.DeviceParametersForInput(DateTimeOffset.Now)).Data, Is.EqualTo(expected2)); var oldTime = DateTimeOffset.Now.Subtract(MultiClampDevice.ParameterStalenessInterval); Assert.That(((MultiClampParametersChangedArgs)mcd.DeviceParametersForInput(oldTime)).Data, Is.EqualTo(expected)); var veryOldTime = marker.Subtract(TimeSpan.FromSeconds(MultiClampDevice.ParameterStalenessInterval.TotalSeconds * 3)); Assert.Throws <MultiClampDeviceException>(() => mcd.DeviceParametersForInput(veryOldTime)); }
public void ShouldTakeMostRecentParametersForInput() { var c = new Controller(); var mc = new FakeMulticlampCommander(); var mcd = new MultiClampDevice(mc, c, UNUSED_BACKGROUND_DICTIONARY); mcd.BindStream(new DAQInputStream(UNUSED_NAME)); var data1 = new MultiClampInterop.MulticlampData(); var expected = new MultiClampInterop.MulticlampData(); var data3 = new MultiClampInterop.MulticlampData(); mc.FireParametersChanged(DateTimeOffset.Now.Subtract(TimeSpan.FromHours(1)), data1); mc.FireParametersChanged(DateTimeOffset.Now.Subtract(TimeSpan.FromMilliseconds(1)), expected); mc.FireParametersChanged(DateTimeOffset.Now.Add(TimeSpan.FromHours(1)), data3); Assert.That(((MultiClampParametersChangedArgs)mcd.DeviceParametersForInput(DateTimeOffset.Now)).Data, Is.EqualTo(expected)); }
public void ShouldDiscardAllButMostRecentStaleInputParametersAfterStalenessInterval() { var c = new Controller(); var mc = new FakeMulticlampCommander(); var mcd = new MultiClampDevice(mc, c, UNUSED_BACKGROUND_DICTIONARY); mcd.BindStream(new DAQInputStream(UNUSED_NAME)); var data1 = new MultiClampInterop.MulticlampData(); var expected2 = new MultiClampInterop.MulticlampData(); var expected = new MultiClampInterop.MulticlampData(); var marker = DateTimeOffset.Now.ToUniversalTime(); mc.FireParametersChanged(marker.Subtract(TimeSpan.FromSeconds(MultiClampDevice.ParameterStalenessInterval.TotalSeconds * 3)), data1); mc.FireParametersChanged(marker.Subtract(TimeSpan.FromSeconds(MultiClampDevice.ParameterStalenessInterval.TotalSeconds * 2)), expected); mc.FireParametersChanged(marker, expected2); Assert.That(((MultiClampParametersChangedArgs)mcd.DeviceParametersForInput(DateTimeOffset.Now)).Data, Is.EqualTo(expected2)); var oldTime = DateTimeOffset.Now.Subtract(MultiClampDevice.ParameterStalenessInterval); Assert.That(((MultiClampParametersChangedArgs)mcd.DeviceParametersForInput(oldTime)).Data, Is.EqualTo(expected)); var veryOldTime = marker.Subtract(TimeSpan.FromSeconds(MultiClampDevice.ParameterStalenessInterval.TotalSeconds * 3)); Assert.Throws<MultiClampDeviceException>(() => mcd.DeviceParametersForInput(veryOldTime)); }