Example #1
0
        public AsyncState(IOperation operation)
        {
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (operation == null)
            {
                ThrowHelper.ThrowArgumentNullException(nameof(operation));
            }

            Operation  = operation;
            _stopwatch = LightweightStopwatch.StartNew();
        }
Example #2
0
        public void ElapsedMilliseconds_AfterStart_LowValue()
        {
            // Arrange

            var stopwatch = LightweightStopwatch.StartNew();

            // Act

            var result = stopwatch.ElapsedMilliseconds;

            // Assert

            Assert.True(result < 1000);
        }
Example #3
0
        public void Elapsed_AfterStart_LowValue()
        {
            // Arrange

            var stopwatch = LightweightStopwatch.StartNew();

            // Act

            var result = stopwatch.Elapsed;

            // Assert

            Assert.True(result < TimeSpan.FromSeconds(1));
        }
Example #4
0
        public async Task ElapsedMilliseconds_AfterSleep_ApproximateValue()
        {
            // Arrange

            var stopwatch = LightweightStopwatch.StartNew();

            // Act

            await Task.Delay(1000);

            var result = stopwatch.ElapsedMilliseconds;

            // Assert

            Assert.True(Math.Abs(result - 1000) < 250);
        }
Example #5
0
        public async Task Elapsed_AfterSleep_ApproximateValue()
        {
            // Arrange

            var stopwatch = LightweightStopwatch.StartNew();

            // Act

            await Task.Delay(1000);

            var result = stopwatch.Elapsed;

            // Assert

            Assert.True(Math.Abs((result - TimeSpan.FromSeconds(1)).TotalMilliseconds) < 250);
        }
Example #6
0
        public async Task Restart_AfterStart_LowValue()
        {
            // Arrange

            var stopwatch = LightweightStopwatch.StartNew();
            await Task.Delay(1000);

            Assert.True(stopwatch.ElapsedMilliseconds > 500);

            // Act

            stopwatch.Restart();
            var result = stopwatch.ElapsedMilliseconds;

            // Assert

            Assert.True(result < 1000);
        }