Esempio n. 1
0
        public void Timer_Enabled_SetDesignModeAfterEnabling_GetReturnsExpected(bool value)
        {
            using var timer = new SubTimer();
            var mockSite = new Mock <ISite>(MockBehavior.Strict);

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(true);
            timer.Site = mockSite.Object;
            Assert.True(timer.DesignMode);

            timer.Start();

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(false);

            timer.Enabled = value;
            Assert.Equal(value, timer.Enabled);

            // Set same.
            timer.Enabled = value;
            Assert.Equal(value, timer.Enabled);

            // NB: disposing the component with strictly mocked object causes tests to fail
            // Moq.MockException : ISite.Container invocation failed with mock behavior Strict. All invocations on the mock must have a corresponding setup.
            timer.Site = null;
        }
Esempio n. 2
0
        public void Stop_Restart_Success(bool designMode)
        {
            var timer    = new SubTimer();
            var mockSite = new Mock <ISite>(MockBehavior.Strict);

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(designMode);
            timer.Site = mockSite.Object;
            Assert.Equal(designMode, timer.DesignMode);

            // Start
            timer.Start();
            Assert.True(timer.Enabled);

            // Stop.
            timer.Stop();
            Assert.False(timer.Enabled);

            // Start again.
            timer.Start();
            Assert.True(timer.Enabled);

            // Stop again.
            timer.Stop();
            Assert.False(timer.Enabled);
        }
Esempio n. 3
0
        public void Timer_Stop_MultipleTimes_Success(bool designMode)
        {
            using var timer = new SubTimer();
            var mockSite = new Mock <ISite>(MockBehavior.Strict);

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(designMode);
            timer.Site = mockSite.Object;
            Assert.Equal(designMode, timer.DesignMode);

            // Start
            timer.Start();
            Assert.True(timer.Enabled);

            // Stop.
            timer.Stop();
            Assert.False(timer.Enabled);

            // Stop again.
            timer.Stop();
            Assert.False(timer.Enabled);

            // NB: disposing the component with strictly mocked object causes tests to fail
            // Moq.MockException : ISite.Container invocation failed with mock behavior Strict. All invocations on the mock must have a corresponding setup.
            timer.Site = null;
        }
Esempio n. 4
0
 public void Timer_Ctor_Default()
 {
     using var timer = new SubTimer();
     Assert.Null(timer.Container);
     Assert.False(timer.DesignMode);
     Assert.False(timer.Enabled);
     Assert.Equal(100, timer.Interval);
     Assert.Null(timer.Site);
     Assert.Null(timer.Tag);
 }
Esempio n. 5
0
 public void Timer_Ctor_IContainer()
 {
     using var container = new Container();
     using var timer     = new SubTimer(container);
     Assert.Same(container, timer.Container);
     Assert.False(timer.DesignMode);
     Assert.False(timer.Enabled);
     Assert.Equal(100, timer.Interval);
     Assert.NotNull(timer.Site);
     Assert.Null(timer.Tag);
 }
Esempio n. 6
0
        // Init
        //----------------------------------------
        private apTimer()
        {
            for (int i = 0; i < NUM_TIME_TYPE; i++)
            {
                _stopWatch[i] = new Stopwatch();
                _stopWatch[i].Start();
                _deltaTimeCount[i] = 0;
                _prevDeltaTime[i]  = 0.0f;

                _subTimer[i] = new SubTimer();
            }
            _fps = 0;
        }
Esempio n. 7
0
        public void Enabled_SetDesignMode_GetReturnsExpected(bool value)
        {
            var timer    = new SubTimer();
            var mockSite = new Mock <ISite>(MockBehavior.Strict);

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(true);
            timer.Site = mockSite.Object;
            Assert.True(timer.DesignMode);

            timer.Enabled = value;
            Assert.Equal(value, timer.Enabled);

            // Set same.
            timer.Enabled = value;
            Assert.Equal(value, timer.Enabled);
        }
Esempio n. 8
0
        public void Tag_SetDesignMode_GetReturnsExpected(object value)
        {
            var timer    = new SubTimer();
            var mockSite = new Mock <ISite>(MockBehavior.Strict);

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(true);
            timer.Site = mockSite.Object;
            Assert.True(timer.DesignMode);

            timer.Tag = value;
            Assert.Same(value, timer.Tag);

            // Set same.
            timer.Tag = value;
            Assert.Same(value, timer.Tag);
        }
Esempio n. 9
0
        public void OnTick_Invoke_CallsTick()
        {
            var          timer     = new SubTimer();
            var          eventArgs = new EventArgs();
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(timer, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            // Call with handler.
            timer.Tick += handler;
            timer.OnTick(eventArgs);
            Assert.Equal(1, callCount);

            // Remove handler.
            timer.Tick -= handler;
            timer.OnTick(eventArgs);
            Assert.Equal(1, callCount);
        }
Esempio n. 10
0
        public void Interval_SetDesignModeAfterEnabling_GetReturnsExpected(int value)
        {
            var timer    = new SubTimer();
            var mockSite = new Mock <ISite>(MockBehavior.Strict);

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(true);
            timer.Site = mockSite.Object;
            Assert.True(timer.DesignMode);

            timer.Start();

            mockSite
            .Setup(s => s.DesignMode)
            .Returns(false);

            timer.Interval = value;
            Assert.Equal(value, timer.Interval);

            // Set same.
            timer.Interval = value;
            Assert.Equal(value, timer.Interval);
        }