File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 4
4
global using Microsoft . AspNetCore . Mvc . Testing ;
5
5
global using Microsoft . AspNetCore . Hosting ;
6
6
global using Microsoft . Extensions . Configuration ;
7
+ global using Bogus ;
Original file line number Diff line number Diff line change
1
+ namespace EvolutionaryArchitecture . Fitnet . Common . IntegrationTestsToolbox . TestEngine . Time ;
2
+
3
+ [ UsedImplicitly ]
4
+ public sealed class FakeTimeProvider ( DateTimeOffset ? now = null ) : TimeProvider
5
+ {
6
+ private DateTimeOffset TimeNowOffset { get ; set ; } = now ?? new Faker ( ) . Date . RecentOffset ( ) . UtcDateTime ;
7
+
8
+ public override DateTimeOffset GetUtcNow ( ) => TimeNowOffset ;
9
+ }
Original file line number Diff line number Diff line change
1
+ namespace EvolutionaryArchitecture . Fitnet . Common . IntegrationTestsToolbox . TestEngine . Time ;
2
+
3
+ using Microsoft . AspNetCore . TestHost ;
4
+ using Microsoft . Extensions . DependencyInjection ;
5
+
6
+ public static class TimeExtensions
7
+ {
8
+ public static WebApplicationFactory < T > WithTime < T > (
9
+ this WebApplicationFactory < T > webApplicationFactory , FakeTimeProvider fakeTimeProvider )
10
+ where T : class => webApplicationFactory
11
+ . WithWebHostBuilder ( builder =>
12
+ builder . ConfigureTestServices ( services => services . AddSingleton < TimeProvider > ( fakeTimeProvider ) ) ) ;
13
+ }
You can’t perform that action at this time.
0 commit comments