-
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: notify on time changes in MockTimeSystem
#964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b51f3cd
feat: add `StartTime` to the time provider of the `MockTimeSystem`
vbreuss 7a9485d
Merge branch 'main' into topic/add-starttime-to-timeprovider
vbreuss 8bdde28
Add `ITimeProviderFactory` to allow notifications of changes in time
vbreuss e200b02
Add `Elapsed` extension
vbreuss e2dafa4
Merge branch 'main' into topic/add-starttime-to-timeprovider
vbreuss 06057d3
Fix sonar issue
vbreuss 75c55a5
Merge branch 'main' into topic/add-starttime-to-timeprovider
vbreuss da4fbbb
Fix review issue
vbreuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Source/Testably.Abstractions.Testing/NotificationHandlerExtensions.TimeSystem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System; | ||
| using Testably.Abstractions.Testing.TimeSystem; | ||
|
|
||
| namespace Testably.Abstractions.Testing; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for the <see cref="INotificationHandler" /> | ||
| /// </summary> | ||
| public static partial class NotificationHandlerExtensions | ||
| { | ||
| /// <summary> | ||
| /// Callback executed when the mocked time changed after the specified <paramref name="interval" />. | ||
| /// </summary> | ||
| /// <param name="handler">The notification handler.</param> | ||
| /// <param name="interval">The time interval that should elapse in the mock time system.</param> | ||
| /// <param name="callback"> | ||
| /// (optional) The callback to execute after the mocked time changed. | ||
| /// </param> | ||
| /// <returns>A <see cref="IAwaitableCallback{ChangeDescription}" /> to un-register the callback on dispose.</returns> | ||
| public static IAwaitableCallback<DateTime> Elapsed( | ||
| this INotificationHandler handler, | ||
| TimeSpan interval, | ||
| Action<DateTime>? callback = null) | ||
| => handler.TimeChanged(callback, (s, d) => d - s >= interval); | ||
|
|
||
| /// <summary> | ||
| /// Callback executed when the mocked time changed. | ||
| /// </summary> | ||
| /// <param name="handler">The notification handler.</param> | ||
| /// <param name="callback"> | ||
| /// (optional) The callback to execute after the mocked time changed. | ||
| /// </param> | ||
| /// <param name="predicate"> | ||
| /// (optional) A predicate used to filter which changes should be notified.<br /> | ||
| /// If set to <see langword="null" /> (default value) all changes are notified. | ||
| /// </param> | ||
| /// <returns>A <see cref="IAwaitableCallback{TimeSpan}" /> to un-register the callback on dispose.</returns> | ||
| public static IAwaitableCallback<DateTime> TimeChanged( | ||
| this INotificationHandler handler, | ||
| Action<DateTime>? callback = null, | ||
| Func<DateTime, bool>? predicate = null) | ||
| => handler.TimeChanged(callback, predicate is null ? null : (_, d) => predicate(d)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Source/Testably.Abstractions.Testing/TimeSystem/ITimeProviderFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using System; | ||
|
|
||
| namespace Testably.Abstractions.Testing.TimeSystem; | ||
|
|
||
| /// <summary> | ||
| /// The factory for creating the time provider for the <see cref="MockTimeSystem" /> | ||
| /// </summary> | ||
| public interface ITimeProviderFactory | ||
| { | ||
| /// <summary> | ||
| /// Creates a time provider for the <see cref="MockTimeSystem" />. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The <paramref name="onTimeChanged" /> callback is called whenever the time provider's time is changed. The callback | ||
| /// receives the new time as a parameter. | ||
| /// </remarks> | ||
| ITimeProvider Create(Action<DateTime> onTimeChanged); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.