Skip to content

Commit 06a80d9

Browse files
committed
docs: update docs and move select parts into nuget description
1 parent 329d469 commit 06a80d9

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

CHANGELOG.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Allow `ManualTimeProvider.Start` to be set using property initializers.
1313

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.
1515

1616
A custom implementation of `ManualTimer` can override the `Change` method and add custom behavior to it.
1717

1818
Overriding `CreateManualTimer` makes it possible to intercept a `TimerCallback` and perform actions before and after the timer callback has been invoked.
1919

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.
2121

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.
2323

2424
- `ManualTimer` now exposes its current configuration. `DueTime`, `Period`, `IsActive`, `CallbackTime`, and `CallbackInvokeCount` are now publicly visible.
2525

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.
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.
2727

2828
## [1.0.0-rc.1]
2929

@@ -51,9 +51,9 @@ Aligned the public API surface of `ManualTimeProvider` with `Microsoft.Extension
5151

5252
## [1.0.0-preview.3]
5353

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.
5555

56-
- Changed `ManualTestProvider.ToString()` method to return current date time.
56+
- Changed the `ManualTestProvider.ToString()` method to return current date time.
5757

5858
- Fixed `ITimer` returned by `ManualTestProvider` such that timers created with a due time equal to zero will fire the timer callback immediately.
5959

@@ -63,9 +63,9 @@ This release adds a dependency on [Microsoft.Bcl.TimeProvider](https://www.nuget
6363

6464
When using the `ManualTimeProvider` during testing, be aware of these outstanding issues: https://github.com/dotnet/runtime/issues/85326
6565

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).
6767

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.
6969

7070
## [0.8.0]
7171

@@ -80,7 +80,7 @@ When using the `ManualTimeProvider` during testing, be aware of these outstandin
8080

8181
- Changed `TestTimeProvider` to `ManualTimeProvider`.
8282
- `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.
8484

8585
## [0.5.0]
8686

@@ -96,8 +96,8 @@ When using the `ManualTimeProvider` during testing, be aware of these outstandin
9696

9797
### Added
9898

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.
101101

102102
### Changed
103103

@@ -106,7 +106,7 @@ When using the `ManualTimeProvider` during testing, be aware of these outstandin
106106

107107
## [0.2.0] - 2023-02-21
108108

109-
Adds support for `Task.WaitAsync` family of methods.
109+
Adds support for the `Task.WaitAsync` family of methods.
110110

111111
## [0.1.3-preview] - 2023-01-30
112112

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
# TimeProvider Extensions
66

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:
88

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).
1010
- A backported version of `PeriodicTimer` that supports `TimeProvider` in .NET 6.
1111

1212
## Quick start
@@ -15,21 +15,23 @@ This describes how to get started:
1515

1616
1. Get the latest release from https://www.nuget.org/packages/TimeProviderExtensions.
1717

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.
1919

2020
3. During testing, inject the `ManualTimeProvider` from this library. This allows you to write tests that run fast and predictably.
2121
- 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)`.
2323

2424
4. See the **[`ManualTimeProvider API`](https://github.com/egil/TimeProviderExtensions/blob/main/docs/TimeProviderExtensions.ManualTimeProvider.md) page** for the full API documentation for `ManualTimeProvider`.
2525

2626
5. Read the rest of this README for further details and examples.
2727

2828
## API Overview
2929

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:
3131

3232
- [`ManualTimeProvider`](https://github.com/egil/TimeProviderExtensions/blob/main/docs/TimeProviderExtensions.ManualTimeProvider.md)
33+
- [`AutoAdvanceBehavior`](https://github.com/egil/TimeProviderExtensions/blob/main/docs/TimeProviderExtensions.AutoAdvanceBehavior.md)
34+
- [`ManualTimer`](https://github.com/egil/TimeProviderExtensions/blob/main/docs/TimeProviderExtensions.ManualTimer.md)
3335

3436
**.NET 7 and earlier:**
3537

@@ -40,10 +42,11 @@ These pages has all the details of the API included in this package:
4042

4143
- 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.
4244
- 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.:
4446
```c#
45-
fixture.Customize<ManualTimeProvider>(x => x.With(tp => tp.AutoAdvanceAmount, TimeSpan.Zero));
47+
fixture.Customize<ManualTimeProvider>(x => x.OmitAutoProperties()));
4648
```
49+
or by using the `[NoAutoProperties]` attribute, if using `AutoFixture.Xunit2`.
4750

4851
## Installation and Usage
4952

@@ -52,7 +55,7 @@ Get the latest release from https://www.nuget.org/packages/TimeProviderExtension
5255
### Set up in production
5356

5457
To use in production, pass in `TimeProvider.System` to the types that depend on `TimeProvider`.
55-
This can be done directly or via an IoC Container, e.g. .NETs built-in `IServiceCollection` like so:
58+
This can be done directly or via an IoC Container, e.g., .NETs built-in `IServiceCollection` like so:
5659

5760
```c#
5861
services.AddSingleton(TimeProvider.System);

src/TimeProviderExtensions/TimeProviderExtensions.csproj

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@
66
<Company>Egil Hansen</Company>
77
<Authors>Egil Hansen</Authors>
88
<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.
1231
</Description>
1332
<PackageTags>TimeProvider, testing</PackageTags>
1433
<Copyright>Egil Hansen</Copyright>
1534
<PackageProjectUrl>https://github.com/egil/TimeProviderExtensions</PackageProjectUrl>
16-
<PackageReadmeFile>README.md</PackageReadmeFile>
1735
<RepositoryUrl>https://github.com/egil/TimeProviderExtensions</RepositoryUrl>
1836
<RepositoryType>git</RepositoryType>
1937
<PackageLicenseFile>LICENSE</PackageLicenseFile>
@@ -73,10 +91,6 @@
7391
<Pack>True</Pack>
7492
<PackagePath>\</PackagePath>
7593
</None>
76-
<None Include="..\..\README.md">
77-
<Pack>True</Pack>
78-
<PackagePath>\</PackagePath>
79-
</None>
8094
</ItemGroup>
8195

8296
<ItemGroup>

0 commit comments

Comments
 (0)