Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void TestPushedWhenRunning() {
            ThrottledStream<int> stream = new ThrottledStream<int>() {
                Running = true
            };

            stream.Call(1);

            Assert.IsNotEmpty(stream.Items);
        }
Beispiel #3
0
        public void TestIgnoredWhenNotRunning() {
            ThrottledStream<int> stream = new ThrottledStream<int>();

            stream.Call(1);

            Assert.IsEmpty(stream.Items);
        }
Beispiel #4
-1
        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);
        }