public void SystemDateTime_can_auto_reset() { using (var timeProvider = SystemDateTime.GetTestTimeProvider()) { timeProvider.DateIs(1974, 10, 16); SystemDateTime.UtcNow.Should().Be(new DateTime(1974, 10, 16)); } SystemDateTime.UtcNow.Should().NotBe(new DateTime(1974, 10, 16)); }
static async Task ThreadProc(DateTime dateTime, Int32 worker) { using var timeProvider = SystemDateTime.GetTestTimeProvider(); Debug.WriteLine($"Worker {worker} wants exclusive access to the clock!"); timeProvider.DateIs(dateTime); Debug.WriteLine($"Worker {worker} got exclusive access to the clock!"); for (var i = 0; i < 5; i++) { Debug.WriteLine($"Worker {worker} date is: {SystemDateTime.UtcNow}"); SystemDateTime.UtcNow.Should().Be(dateTime); await Task.Delay(25).ConfigureAwait(false); } }