Skip to content

Commit

Permalink
Refactor tests for improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
egil committed May 30, 2023
1 parent 52e8ef5 commit 758ce3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ public void DefaultCtor()

var timestamp2 = timeProvider.GetTimestamp();
var frequency2 = timeProvider.TimestampFrequency;
now = timeProvider.GetUtcNow();
var now2 = timeProvider.GetUtcNow();

Assert.Equal(2000, now.Year);
Assert.Equal(1, now.Month);
Assert.Equal(1, now.Day);
Assert.Equal(0, now.Hour);
Assert.Equal(0, now.Minute);
Assert.Equal(0, now.Second);
Assert.Equal(0, now.Millisecond);
Assert.Equal(10_000_000, frequency2);
Assert.Equal(timestamp2, timestamp);
Assert.Equal(now, now2);
Assert.Equal(frequency, frequency2);
Assert.Equal(timestamp, timestamp2);
}

[Fact]
Expand Down Expand Up @@ -77,7 +71,7 @@ public void RichCtor()
Assert.Equal(5, now.Minute);
Assert.Equal(6, now.Second);
Assert.Equal(16, now.Millisecond);
Assert.Equal(10_000_000, frequency2);
Assert.Equal(frequency, frequency2);
Assert.True(pnow2 > pnow);
}

Expand Down Expand Up @@ -173,7 +167,7 @@ public async Task Delay_Timeout()
var timeProvider = new FakeTimeProvider();

var delay = timeProvider.Delay(TimeSpan.FromMilliseconds(1), CancellationToken.None);
timeProvider.Advance();
timeProvider.Advance(TimeSpan.FromMilliseconds(1));
await delay;

Assert.True(delay.IsCompleted);
Expand Down Expand Up @@ -203,7 +197,7 @@ public async Task CreateSource()
var timeProvider = new FakeTimeProvider();

using var cts = timeProvider.CreateCancellationTokenSource(TimeSpan.FromMilliseconds(1));
timeProvider.Advance();
timeProvider.Advance(TimeSpan.FromMilliseconds(1));

await Assert.ThrowsAsync<TaskCanceledException>(() => timeProvider.Delay(TimeSpan.FromTicks(1), cts.Token));
}
Expand All @@ -224,7 +218,7 @@ public async Task WaitAsync()
var t = source.Task.WaitAsync(TimeSpan.FromSeconds(100000), timeProvider, CancellationToken.None);
while (!t.IsCompleted)
{
timeProvider.Advance();
timeProvider.Advance(TimeSpan.FromMilliseconds(1));
await Task.Delay(1);
_ = source.TrySetResult(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void TimerNonPeriodicPeriodZero()
using var timer = timeProvider.CreateTimer(_ => { counter++; }, null, TimeSpan.FromMilliseconds(10), TimeSpan.Zero);

var value1 = counter;

timeProvider.Advance(TimeSpan.FromMilliseconds(20));

var value2 = counter;
Expand All @@ -45,6 +46,7 @@ public void TimerNonPeriodicPeriodInfinite()
using var timer = timeProvider.CreateTimer(_ => { counter++; }, null, TimeSpan.FromMilliseconds(10), Timeout.InfiniteTimeSpan);

var value1 = counter;

timeProvider.Advance(TimeSpan.FromMilliseconds(20));

var value2 = counter;
Expand Down

0 comments on commit 758ce3c

Please sign in to comment.