Introduce TimeProvider for testable time-dependent behavior#22
Merged
Introduce TimeProvider for testable time-dependent behavior#22
Conversation
Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add constructor for TimeProvider in MiniJwtService
Introduce TimeProvider for testable time-dependent behavior
Dec 22, 2025
jeanlrnt
approved these changes
Dec 22, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces TimeProvider support to enable deterministic testing of JWT token generation timestamps. The implementation adds a new optional constructor parameter that accepts a TimeProvider, with backward compatibility maintained through constructor chaining that defaults to TimeProvider.System.
Key Changes
- Added
TimeProviderfield and constructor overload toMiniJwtServicefor testable time-dependent behavior - Replaced
DateTime.UtcNowwith_timeProvider.GetUtcNow().UtcDateTimein token generation - Added conditional package references for
Microsoft.Bcl.TimeProvider(8.0.1) for .NET 6/7 targets andMicrosoft.Extensions.TimeProvider.Testing(8.10.0) for tests
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/MiniJwt.Core/Services/MiniJwtService.cs | Adds TimeProvider field, new constructor accepting TimeProvider, and updates token generation to use injected time provider |
| src/MiniJwt.Core/MiniJwt.Core.csproj | Adds conditional package reference to Microsoft.Bcl.TimeProvider for .NET 6/7 targets |
| src/MiniJwt.Tests/MiniJwtTests.Service.cs | Adds two new tests demonstrating FakeTimeProvider usage for fixed-time and time-advancement scenarios |
| src/MiniJwt.Tests/MiniJwt.Tests.csproj | Adds Microsoft.Extensions.TimeProvider.Testing package reference |
| docs/examples.md | Adds new testing section with FakeTimeProvider usage example |
| docs/faq.md | Updates testing guidance to mention FakeTimeProvider |
| README.md | Adds new "Testing with TimeProvider" section with usage example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…mpleOptionsMonitor helper Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
jeanlrnt
approved these changes
Dec 22, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.