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
{{ message }}
Repository navigation
docs(ai): prefer MockDateTimeSources over FakeTimeProvider in .NET tests #1260
we should be using MockDateTimeSources where possible Pretty sure IDateTimeSource/ICurrentTimeSource no longer exists
q7 yes. However there's an advancing source isn't there too in MockDateTimeSources?
Problem
ai/global/dotnet.instructions.md currently steers agents to FakeTimeProvider:
Line ~300 maps "Custom TimeProvider fakes" to FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing.
Lines ~449-452 say to use FakeTimeProvider in tests and to migrate code touching ICurrentTimeSource / IDateTimeSource. Those interfaces no longer exist, so that migration line is stale.
Meanwhile lines ~456-464 already document MockDateTimeSources (Past, Future, AdvancingDateTimeUseWithCaution) from FunFair.Test.Common. MockDateTimeSources.* are TimeProvider instances themselves, so they cover most test needs. Agents following the current text added Microsoft.Extensions.TimeProvider.Testing to every test project in recommendations-defi-dashboard. There, FakeTimeProvider is used in 9 test files, but no test calls Advance, SetUtcNow or AutoAdvanceAmount, so every use could be MockDateTimeSources.Past/Future.
Related (closed, introduced the current rule): #763.
Proposed rule
In tests, use MockDateTimeSources.Past / .Future (or .AdvancingDateTimeUseWithCaution when real elapsed time is needed) wherever a TimeProvider is required.
Use FakeTimeProvider only when a test must step the clock deterministically (Advance / SetUtcNow), which the advancing source cannot do because it follows real elapsed time.
Do not add Microsoft.Extensions.TimeProvider.Testing to a test project that does not use FakeTimeProvider.
Remove the stale ICurrentTimeSource / IDateTimeSource migration line, and update the line ~300 mapping to match.
Update the credfeto-dotnet-test-patterns / credfeto-dotnet-coding-conventions skill text if it repeats the old rule.
Correction: the issue body is wrong about MockDateTimeSources. It says AdvancingDateTimeUseWithCaution "follows real elapsed time" and cannot step the clock deterministically, and so proposes keeping a direct FakeTimeProvider for that case. That is not how it works.
From funfair-tech/funfair-server-testsrc/FunFair.Test.Infrastructure/Mocks/MockDateTimeSources.cs:
Every MockDateTimeSources member returns a FakeTimeProvider, so Advance() and SetUtcNow() are available for on-demand clock steps.
AdvancingDateTimeUseWithCaution auto-advances by one day on each read. It has nothing to do with wall-clock time.
FunFair.Test.Infrastructure already depends on Microsoft.Extensions.TimeProvider.Testing, so test projects get the package transitively.
Revised proposed rule:
In tests, always obtain a time provider from MockDateTimeSources (Past, Future, or AdvancingDateTimeUseWithCaution). Use Advance() / SetUtcNow() on it when a test needs to move the clock. Never construct FakeTimeProvider directly.
Do not add an explicit Microsoft.Extensions.TimeProvider.Testing PackageReference to test projects; it comes through FunFair.Test.Infrastructure.
Remove the stale ICurrentTimeSource / IDateTimeSource migration line, and update the line ~300 mapping (custom TimeProvider fakes -> MockDateTimeSources).
ai/global/dotnet.instructions.md - line ~300 mapping: change "Custom TimeProvider fakes" to MockDateTimeSources (Past/Future/AdvancingDateTimeUseWithCaution); lines ~449-452: replace the FakeTimeProvider rule with "always obtain a time provider from MockDateTimeSources, never construct FakeTimeProvider directly, use Advance()/SetUtcNow() on it to move the clock", and remove the stale ICurrentTimeSource/IDateTimeSource migration line (452); lines ~456-464: correct the note that AdvancingDateTimeUseWithCaution follows real time (it auto-advances 1 day per read)
CHANGELOG.md - entry under Unreleased (via the changelog tool)
Approach
Edit the single instruction file so it matches the owner's corrected rule (comment 6989409348): tests always use MockDateTimeSources.* (each returns a FakeTimeProvider), call Advance()/SetUtcNow() when the clock must move, never construct FakeTimeProvider directly, and do not add an explicit Microsoft.Extensions.TimeProvider.Testing PackageReference because it arrives transitively via FunFair.Test.Infrastructure. The obsolete-interface prohibition on line 450 stays; only the stale migration line is removed. A search of ai/ and .ai-instructions found no other occurrences, so no skill text in this repo needs changes.
Test strategy
Docs-only change. Run markdown lint and the pre-commit checks, and grep to confirm no remaining stale FakeTimeProvider/migration wording.
Assumptions
a. The credfeto-dotnet-test-patterns / credfeto-dotnet-coding-conventions skills live outside this repo, so they are out of scope.
b. The owner's correction supersedes the issue body's "use FakeTimeProvider only when stepping" rule.
Activity
credfeto commentedon Nov 18, 2026
Correction: the issue body is wrong about
MockDateTimeSources. It saysAdvancingDateTimeUseWithCaution"follows real elapsed time" and cannot step the clock deterministically, and so proposes keeping a directFakeTimeProviderfor that case. That is not how it works.From
funfair-tech/funfair-server-testsrc/FunFair.Test.Infrastructure/Mocks/MockDateTimeSources.cs:MockDateTimeSourcesmember returns aFakeTimeProvider, soAdvance()andSetUtcNow()are available for on-demand clock steps.AdvancingDateTimeUseWithCautionauto-advances by one day on each read. It has nothing to do with wall-clock time.FunFair.Test.Infrastructurealready depends onMicrosoft.Extensions.TimeProvider.Testing, so test projects get the package transitively.Revised proposed rule:
MockDateTimeSources(Past,Future, orAdvancingDateTimeUseWithCaution). UseAdvance()/SetUtcNow()on it when a test needs to move the clock. Never constructFakeTimeProviderdirectly.Microsoft.Extensions.TimeProvider.TestingPackageReference to test projects; it comes throughFunFair.Test.Infrastructure.ICurrentTimeSource/IDateTimeSourcemigration line, and update the line ~300 mapping (customTimeProviderfakes ->MockDateTimeSources).dnyw4l3n13 commentedon Nov 26, 2026
Implementation Plan
Files to change
ai/global/dotnet.instructions.md- line ~300 mapping: change "CustomTimeProviderfakes" toMockDateTimeSources(Past/Future/AdvancingDateTimeUseWithCaution); lines ~449-452: replace theFakeTimeProviderrule with "always obtain a time provider fromMockDateTimeSources, never constructFakeTimeProviderdirectly, useAdvance()/SetUtcNow()on it to move the clock", and remove the staleICurrentTimeSource/IDateTimeSourcemigration line (452); lines ~456-464: correct the note thatAdvancingDateTimeUseWithCautionfollows real time (it auto-advances 1 day per read)CHANGELOG.md- entry under Unreleased (via the changelog tool)Approach
Edit the single instruction file so it matches the owner's corrected rule (comment 6989409348): tests always use
MockDateTimeSources.*(each returns aFakeTimeProvider), callAdvance()/SetUtcNow()when the clock must move, never constructFakeTimeProviderdirectly, and do not add an explicitMicrosoft.Extensions.TimeProvider.TestingPackageReference because it arrives transitively viaFunFair.Test.Infrastructure. The obsolete-interface prohibition on line 450 stays; only the stale migration line is removed. A search ofai/and.ai-instructionsfound no other occurrences, so no skill text in this repo needs changes.Test strategy
Docs-only change. Run markdown lint and the pre-commit checks, and grep to confirm no remaining stale
FakeTimeProvider/migration wording.Assumptions
a. The
credfeto-dotnet-test-patterns/credfeto-dotnet-coding-conventionsskills live outside this repo, so they are out of scope.b. The owner's correction supersedes the issue body's "use FakeTimeProvider only when stepping" rule.
Open questions
None - ready to proceed pending approval