예제 #1
0
        public void then_fail_if_started_without_assigning_Tick()
        {
            ITimer timer = new RealtimeFixedIntervalTimer {
                Interval = 200
            };

            timer.Start();
        }
예제 #2
0
        public void then_fail_if_started_with_Interval_below_1()
        {
            ITimer timer = new RealtimeFixedIntervalTimer {
                Interval = 0
            };

            timer.Start();
            Thread.Sleep(10);
        }
예제 #3
0
        public void when_testing_MCD1()
        {
            RealtimeFixedIntervalTimer timer = TimerCreator.MCD(new List <int>()
            {
                8, 4, 2, 12
            });

            timer.Interval.ShouldEqual(2 * 250);
        }
예제 #4
0
        public void then_fail_if_Tick_changed_when_runnig()
        {
            RealtimeFixedIntervalTimer timer = new RealtimeFixedIntervalTimer
            {
                Interval = 100,
                Tick     = new Action(() => { })
            };

            timer.Start();
            timer.Tick = new Action(() => {});
        }
예제 #5
0
        public void then_can_start_timer()
        {
            ITimer timer = new RealtimeFixedIntervalTimer {
                Interval = 100
            };
            object lckTicks = new object();
            int    ticks    = 0;

            timer.Tick = new Action(() =>
            {
                lock (lckTicks)
                    ticks++;
            });
            timer.Start();
            Thread.Sleep(1000);
            lock (lckTicks)
            {
                ticks.ShouldBeGreaterThan(8);
                Debug.WriteLine("Ticks: " + ticks);
            }
        }
예제 #6
0
        public void then_timer_bypass_tick_if_already_running()
        {
            object lckTicks = new object();
            int    ticks    = 0;
            ITimer timer    = new RealtimeFixedIntervalTimer {
                Interval = 100
            };

            timer.Tick = new Action(() =>
            {
                lock (lckTicks)
                    ticks++;
                Thread.Sleep(500);
            });
            timer.Start();
            Thread.Sleep(1000);
            lock (lckTicks)
            {
                ticks.ShouldBeLessThanOrEqualTo(2);
                ticks.ShouldBeGreaterThanOrEqualTo(1);
                Debug.WriteLine("Ticks: " + ticks);
            }
        }
예제 #7
0
        public void then_can_stop_timer()
        {
            object lckTicks = new object();
            int    ticks    = 0;
            ITimer timer    = new RealtimeFixedIntervalTimer {
                Interval = 100
            };

            timer.Tick = new Action(() =>
            {
                lock (lckTicks)
                    ticks++;
            });
            timer.Start();
            Thread.Sleep(100);
            timer.Stop();
            int ticksWhenStop = 0;

            lock (lckTicks)
                ticksWhenStop = ticks;
            Thread.Sleep(1000);
            lock (lckTicks)
                ticks.ShouldEqual(ticksWhenStop);
        }