public void TestFlushToCorrectOrder() { AutoResetEvent reset = new AutoResetEvent(false); List<int> flushedItems = new List<int>(); ThrottledStream<int> stream = new ThrottledStream<int>() { Interval = new TimeSpan(0, 0, 0, 0, 100), FlushTo = items => { flushedItems = items; reset.Set(); } }; stream.Start(); stream.Call(1); stream.Call(2); stream.Call(3); Assert.IsTrue(reset.WaitOne(500)); Assert.AreEqual(new List<int>() { 1, 2, 3 }, flushedItems); }
public void TestStart() { ThrottledStream<int> stream = new ThrottledStream<int>(); stream.Start(); Assert.IsTrue(stream.Running); Assert.IsNotNull(stream.IntervalTick); }
public void TestStopWhileRunning() { ThrottledStream<int> stream = new ThrottledStream<int>() { FlushTo = items => { } }; stream.Start(); stream.Stop(); Assert.IsFalse(stream.Running); Assert.IsNull(stream.IntervalTick); Assert.IsNull(stream.FlushTo); }
public void TestFlushToIsCalled() { AutoResetEvent reset = new AutoResetEvent(false); bool isFlushToCalled = false; ThrottledStream<int> stream = new ThrottledStream<int>() { Interval = new TimeSpan(0, 0, 0, 0, 10), FlushTo = items => { isFlushToCalled = true; reset.Set(); } }; stream.Start(); stream.Call(1); Assert.IsTrue(reset.WaitOne(500)); Assert.IsTrue(isFlushToCalled); }