Exemplo n.º 1
0
        public void TestMethod1()
        {
            var debugStopwatch = new MockStopwatch(new []
            {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(4),
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(6),
                TimeSpan.FromSeconds(7),
                TimeSpan.FromSeconds(8),
            });

            var asyncDetector = new AsyncDetector(debugStopwatch);

            using (asyncDetector.BeignScope())
            {
                using (asyncDetector.BeignScope())
                {
                    using (asyncDetector.BeignScope())
                    {
                    }

                    using (asyncDetector.BeignScope())
                    {
                    }
                }
            }

            Assert.AreEqual(4, asyncDetector.MaxAsyncDegree);
            Assert.AreEqual(1, asyncDetector.AsyncGroupCount);
        }
Exemplo n.º 2
0
        public void Elapsed_GetNextValue()
        {
            _stopwatch = MockStopwatch.StartNew(Enumerable.Range(1, 10).Select(i => TimeSpan.FromSeconds(i)));

            Assert.IsTrue(_stopwatch.IsRunning);
            Assert.AreEqual(TimeSpan.FromSeconds(0), _stopwatch.Elapsed);
            Assert.AreEqual(TimeSpan.FromSeconds(1), _stopwatch.Elapsed);
            Assert.AreEqual(TimeSpan.FromSeconds(2), _stopwatch.Elapsed);
        }
Exemplo n.º 3
0
        public void Stop_Elapsed_GetsSameValue()
        {
            _stopwatch = MockStopwatch.StartNew(Enumerable.Range(1, 10).Select(i => TimeSpan.FromSeconds(i)));

            _stopwatch.Elapsed.Noop();
            _stopwatch.Elapsed.Noop();
            _stopwatch.Elapsed.Noop();
            _stopwatch.Stop();

            Assert.IsFalse(_stopwatch.IsRunning);
            Assert.AreEqual(TimeSpan.FromSeconds(2), _stopwatch.Elapsed);
            Assert.AreEqual(TimeSpan.FromSeconds(2), _stopwatch.Elapsed);
        }
Exemplo n.º 4
0
        public void ResetStopped_Elapsed_GetsOnlyFirst()
        {
            _stopwatch = MockStopwatch.StartNew(Enumerable.Range(1, 10).Select(i => TimeSpan.FromSeconds(i)));

            _stopwatch.Elapsed.Noop();
            _stopwatch.Elapsed.Noop();
            _stopwatch.Elapsed.Noop();
            _stopwatch.Stop();

            _stopwatch.Reset();

            Assert.IsFalse(_stopwatch.IsRunning);
            Assert.AreEqual(TimeSpan.FromSeconds(0), _stopwatch.Elapsed);
            Assert.AreEqual(TimeSpan.FromSeconds(0), _stopwatch.Elapsed);
        }
Exemplo n.º 5
0
 public void TestInitialize()
 {
     _stopwatch = MockStopwatch.StartNew(Enumerable.Range(1, 10).Select(i => TimeSpan.FromSeconds(i)));
 }