You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,19 +11,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
12
12
- Allow `ManualTimeProvider.Start` to be set using property initializers.
13
13
14
-
- Made the timer type created by `ManualTimeProvider`, the `ManualTimer` type, public, and introduced a protected method `CreateManualTimer` on `ManualTimeProvider`. This enables advanced scenarioes where a custom `ManualTimer` is needed.
14
+
- Made the timer type created by `ManualTimeProvider`, the `ManualTimer` type, public, and introduced a protected method `CreateManualTimer` on `ManualTimeProvider`. This enables advanced scenarios where a custom `ManualTimer` is needed.
15
15
16
16
A custom implementation of `ManualTimer` can override the `Change` method and add custom behavior to it.
17
17
18
18
Overriding `CreateManualTimer` makes it possible to intercept a `TimerCallback` and perform actions before and after the timer callback has been invoked.
19
19
20
-
- Replace `AutoAdvanceAmount` property with the `AutoAdvanceBehavior` property on `ManualTimeProvider`, and introduced the `AutoAdvanceBehavior` type. To automatically advance time when `GetUtcNow()` or `GetLocalNow()` is called, set `AutoAdvanceBehavior.UtcNowAdvanceAmount` to a time span larger than zero.
20
+
- Replace the `AutoAdvanceAmount` property with the `AutoAdvanceBehavior` property on `ManualTimeProvider`, and introduce the `AutoAdvanceBehavior` type. To automatically advance the time when `GetUtcNow()` or `GetLocalNow()` is called, set `AutoAdvanceBehavior.UtcNowAdvanceAmount` to a `TimeSpan` larger than zero.
21
21
22
-
- Enable auto advance feature for `GetTimestamp()` and `GetElapsedTime(long)`. To automatically advance time when `GetTimestamp()` or `GetElapsedTime(long)` is called, set `AutoAdvanceBehavior.TimestampAdvanceAmount` to a time span larger than zero.
22
+
- Enable auto advance feature for `GetTimestamp()` and `GetElapsedTime(long)`. To automatically advance the time when `GetTimestamp()` or `GetElapsedTime(long)` is called, set `AutoAdvanceBehavior.TimestampAdvanceAmount` to a `TimeSpan` larger than zero.
23
23
24
24
-`ManualTimer` now exposes its current configuration. `DueTime`, `Period`, `IsActive`, `CallbackTime`, and `CallbackInvokeCount` are now publicly visible.
25
25
26
-
- Enable autoadvance feature for timers. This enables automatically calling timers callback a specified number of times, by setting the `AutoAdvanceBehavior.TimerAutoTriggerCount` property to a number larger than zero.
26
+
- Enable auto-advance feature for timers. This enables automatically calling timers callback a specified number of times, by setting the `AutoAdvanceBehavior.TimerAutoTriggerCount` property to a number larger than zero.
27
27
28
28
## [1.0.0-rc.1]
29
29
@@ -51,9 +51,9 @@ Aligned the public API surface of `ManualTimeProvider` with `Microsoft.Extension
51
51
52
52
## [1.0.0-preview.3]
53
53
54
-
- Changed `ManualTestProvider`sets the local time zone to UTC by default, provides method for overriding during testing.
54
+
- Changed `ManualTestProvider`to set the local time zone to UTC by default, providing a method for overriding during testing.
55
55
56
-
- Changed `ManualTestProvider.ToString()` method to return current date time.
56
+
- Changed the `ManualTestProvider.ToString()` method to return current date time.
57
57
58
58
- Fixed `ITimer` returned by `ManualTestProvider` such that timers created with a due time equal to zero will fire the timer callback immediately.
59
59
@@ -63,9 +63,9 @@ This release adds a dependency on [Microsoft.Bcl.TimeProvider](https://www.nuget
63
63
64
64
When using the `ManualTimeProvider` during testing, be aware of these outstanding issues: https://github.com/dotnet/runtime/issues/85326
65
65
66
-
- Removed `CancelAfter` extension methods. Instead create a CancellationTokenSource via the method `TimeProvider.CreateCancellationTokenSource(TimeSpan delay)` or in .NET 8, using `new CancellationTokenSource(TimeSpan delay, TimeProvider timeProvider).
66
+
- Removed `CancelAfter` extension methods. Instead, create a CancellationTokenSource via the method `TimeProvider.CreateCancellationTokenSource(TimeSpan delay)` or in .NET 8, using `new CancellationTokenSource(TimeSpan delay, TimeProvider timeProvider).
67
67
68
-
**NOTE:** If running on .NET versions earlier than .NET 8.0, there is a constraint when invoking `CancellationTokenSource.CancelAfter(TimeSpan)` on the resultant object. This action will not terminate the initial timer indicated by `delay`. However, this restriction does not apply on .NET 8.0 and later versions.
68
+
**NOTE:** If running on .NET versions earlier than .NET 8.0, there is a constraint when invoking `CancellationTokenSource.CancelAfter(TimeSpan)` on the resultant object. This action will not terminate the initial timer indicated by `delay`. However, this restriction does not apply to .NET 8.0 and later versions.
69
69
70
70
## [0.8.0]
71
71
@@ -80,7 +80,7 @@ When using the `ManualTimeProvider` during testing, be aware of these outstandin
80
80
81
81
- Changed `TestTimeProvider` to `ManualTimeProvider`.
82
82
-`ManualTimeProvider` no longer implements on `IDisposable`.
83
-
- Moving time forward using `ManualTimeProvider` will now move time forward in steps, stopping at each scheduled timer/callback time, set the internal "UtcNow" clock returned from `GetUtcNow()` invoke the callback, and then progress to the next scheduled timer, until the target "UtcNow" is reached.
83
+
- Moving time forward using `ManualTimeProvider` will now move time forward in steps, stopping at each scheduled timer/callback time, setting the internal "UtcNow" clock returned from `GetUtcNow()` to invoke the callback, and then progress to the next scheduled timer, until the target "UtcNow" is reached.
84
84
85
85
## [0.5.0]
86
86
@@ -96,8 +96,8 @@ When using the `ManualTimeProvider` during testing, be aware of these outstandin
96
96
97
97
### Added
98
98
99
-
- Adds support for cancelling a `CancellationTokenSource` after a specific timespan via the `ITimeScheduler.CancelAfter(CancellationTokenSource, TimeSpan)` method.
100
-
- Adds an singleton instance property to `DefaultScheduler` that can be used instead of creating a new instance for every use.
99
+
- Adds support for canceling a `CancellationTokenSource` after a specific timespan via the `ITimeScheduler.CancelAfter(CancellationTokenSource, TimeSpan)` method.
100
+
- Adds a singleton instance property to `DefaultScheduler` that can be used instead of creating a new instance for every use.
101
101
102
102
### Changed
103
103
@@ -106,7 +106,7 @@ When using the `ManualTimeProvider` during testing, be aware of these outstandin
106
106
107
107
## [0.2.0] - 2023-02-21
108
108
109
-
Adds support for `Task.WaitAsync` family of methods.
109
+
Adds support for the `Task.WaitAsync` family of methods.
Copy file name to clipboardExpand all lines: README.md
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@
4
4
5
5
# TimeProvider Extensions
6
6
7
-
Extensions for the [`System.TimeProvider`](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider) API. It includes:
7
+
Testing extensions for the [`System.TimeProvider`](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider) API. It includes:
8
8
9
-
-A test/fake version of `TimeProvider` type, named `ManualTimeProvider`, that allows you to control the progress of time during testing deterministically.
9
+
-An advanced test/fake version of the `TimeProvider` type, named `ManualTimeProvider`, that allows you to control the progress of time during testing deterministically (see the difference to Microsoft's `FakeTimeProvider` below).
10
10
- A backported version of `PeriodicTimer` that supports `TimeProvider` in .NET 6.
11
11
12
12
## Quick start
@@ -15,21 +15,23 @@ This describes how to get started:
15
15
16
16
1. Get the latest release from https://www.nuget.org/packages/TimeProviderExtensions.
17
17
18
-
2. Take a dependency on `TimeProvider` in your code. Inject the production version of `TimeProvider` available via the [`TimeProvider.System`](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider.system?#system-timeprovider-system) property during production.
18
+
2. Take a dependency on `TimeProvider` in your production code. Inject the production version of `TimeProvider` available via the [`TimeProvider.System`](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider.system?#system-timeprovider-system) property during production.
19
19
20
20
3. During testing, inject the `ManualTimeProvider` from this library. This allows you to write tests that run fast and predictably.
21
21
- Advance time by calling `Advance(TimeSpan)` or `SetUtcNow(DateTimeOffset)` or
22
-
- Jump ahead in time using `Jump(TimeSpan)` or `Jump(DateTimeOffset)`
22
+
- Jump ahead in time using `Jump(TimeSpan)` or `Jump(DateTimeOffset)`.
23
23
24
24
4. See the **[`ManualTimeProvider API`](https://github.com/egil/TimeProviderExtensions/blob/main/docs/TimeProviderExtensions.ManualTimeProvider.md) page** for the full API documentation for `ManualTimeProvider`.
25
25
26
26
5. Read the rest of this README for further details and examples.
27
27
28
28
## API Overview
29
29
30
-
These pages has all the details of the API included in this package:
30
+
These pages have all the details of the API included in this package:
@@ -40,10 +42,11 @@ These pages has all the details of the API included in this package:
40
42
41
43
- If running on .NET versions earlier than .NET 8.0, there is a constraint when invoking `CancellationTokenSource.CancelAfter(TimeSpan)` on the `CancellationTokenSource` object returned by `CreateCancellationTokenSource(TimeSpan delay)`. This action will not terminate the initial timer indicated by the `delay` argument initially passed the `CreateCancellationTokenSource` method. However, this restriction does not apply to .NET 8.0 and later versions.
42
44
- To enable controlling `PeriodicTimer` via `TimeProvider` in versions of .NET earlier than .NET 8.0, the `TimeProvider.CreatePeriodicTimer` returns a `PeriodicTimerWrapper` object instead of a `PeriodicTimer` object. The `PeriodicTimerWrapper` type is just a lightweight wrapper around the original `System.Threading.PeriodicTimer` and will behave identically to it.
43
-
- If `ManualTimeProvider` is created via [AutoFixture](https://github.com/AutoFixture/AutoFixture), be aware that will set `AutoAdvanceAmount` to a random positive time span. This behavior can be overridden by providing a customization to AutoFixture, e.g.:
45
+
- If `ManualTimeProvider` is created via [AutoFixture](https://github.com/AutoFixture/AutoFixture), be aware that will set writable properties with random values. This behavior can be overridden by providing a customization to AutoFixture, e.g.:
Copy file name to clipboardExpand all lines: src/TimeProviderExtensions/TimeProviderExtensions.csproj
+22-8Lines changed: 22 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,32 @@
6
6
<Company>Egil Hansen</Company>
7
7
<Authors>Egil Hansen</Authors>
8
8
<Description>
9
-
Extensions for the `System.TimeProvider` API. It includes a test version of the `TimeProvider`, named `ManualTimeProvider`,
10
-
that allows you to control the progress of time during testing deterministically and a backport of the `PeriodicTimer`
11
-
version from .NET 8 to .NET 6/7 that supports `TimeProvider`.
9
+
# TimeProvider Extensions
10
+
11
+
Testing extensions for the [`System.TimeProvider`](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider) API. It includes:
12
+
13
+
- An advanced test/fake version of the `TimeProvider` type, named `ManualTimeProvider`, that allows you to control the progress of time during testing deterministically (see the difference to Microsoft's `FakeTimeProvider` below).
14
+
- A backported version of `PeriodicTimer` that supports `TimeProvider` in .NET 6.
15
+
16
+
## Quick start
17
+
18
+
This describes how to get started:
19
+
20
+
1. Get the latest release from https://www.nuget.org/packages/TimeProviderExtensions.
21
+
22
+
2. Take a dependency on `TimeProvider` in your production code. Inject the production version of `TimeProvider` available via the [`TimeProvider.System`](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider.system?#system-timeprovider-system) property during production.
23
+
24
+
3. During testing, inject the `ManualTimeProvider` from this library. This allows you to write tests that run fast and predictably.
25
+
- Advance time by calling `Advance(TimeSpan)` or `SetUtcNow(DateTimeOffset)` or
26
+
- Jump ahead in time using `Jump(TimeSpan)` or `Jump(DateTimeOffset)`.
27
+
28
+
4. See the **[`ManualTimeProvider API`](https://github.com/egil/TimeProviderExtensions/blob/main/docs/TimeProviderExtensions.ManualTimeProvider.md) page** for the full API documentation for `ManualTimeProvider`.
29
+
30
+
5. Read the [README](https://github.com/egil/TimeProviderExtensions) for further details and examples.
0 commit comments