public AsyncState(IOperation operation) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (operation == null) { ThrowHelper.ThrowArgumentNullException(nameof(operation)); } Operation = operation; _stopwatch = LightweightStopwatch.StartNew(); }
public void ElapsedMilliseconds_AfterStart_LowValue() { // Arrange var stopwatch = LightweightStopwatch.StartNew(); // Act var result = stopwatch.ElapsedMilliseconds; // Assert Assert.True(result < 1000); }
public void Elapsed_AfterStart_LowValue() { // Arrange var stopwatch = LightweightStopwatch.StartNew(); // Act var result = stopwatch.Elapsed; // Assert Assert.True(result < TimeSpan.FromSeconds(1)); }
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); }
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); }
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); }