Ejemplo n.º 1
0
        public void TestReset()
        {
            var mock   = new Mock <Infrastructures.IStopwatch>();
            var called = false;

            mock.Setup(m => m.Reset()).Callback(() => called = true);

            using (var sw = new StopwatchService(mock.Object))
                using (var are = new AutoResetEvent(false))
                {
                    sw.ObserveProperty(x => x.Ellapsed, false)
                    .Subscribe(_ => are.Set());

                    sw.Start();
                    sw.Lap();
                    sw.Lap();
                    sw.Lap();
                    are.WaitOne(10);
                    sw.Reset();

                    Assert.IsTrue(called);
                    Assert.IsTrue(are.WaitOne(10));
                    Assert.AreEqual(TimeSpan.Zero, sw.Ellapsed);
                    Assert.AreEqual(0, sw.LapTimes.Count);
                }
        }
Ejemplo n.º 2
0
        public void TestLap()
        {
            var mock = new Mock <Infrastructures.IStopwatch>();

            using (var sw = new StopwatchService(mock.Object))
            {
                sw.Start();

                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(10));
                sw.Lap();
                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(30));
                sw.Lap();
                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(60));
                sw.Lap();
                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(100));
                sw.Stop();

                Assert.AreEqual(10, sw.LapTimes[0].TotalMilliseconds);
                Assert.AreEqual(20, sw.LapTimes[1].TotalMilliseconds);
                Assert.AreEqual(30, sw.LapTimes[2].TotalMilliseconds);
                Assert.AreEqual(40, sw.LapTimes[3].TotalMilliseconds);
            }
        }
Ejemplo n.º 3
0
        public void TestIsRunning()
        {
            var mock   = new Mock <Infrastructures.IStopwatch>();
            var called = false;

            mock.Setup(m => m.IsRunning).Callback(() => called = true);

            using (var sw = new StopwatchService(mock.Object))
                using (var are = new AutoResetEvent(false))
                {
                    sw.ObserveProperty(x => x.IsRunning, false)
                    .Subscribe(_ => are.Set());

                    var isRunning = sw.IsRunning;
                    Assert.IsTrue(called);

                    sw.Start();
                    Assert.IsTrue(are.WaitOne(10));

                    sw.Stop();
                    Assert.IsTrue(are.WaitOne(10));
                }
        }
Ejemplo n.º 4
0
 public void OnActionExecuting(ActionExecutingContext context)
 {
     watchService.Start("Action Executing");
 }