aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/TestClock.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-08-04 21:35:04 +0800
committerGitHub <noreply@github.com>2019-08-04 21:35:04 +0800
commitebda3fc381ee4ed9f729fa85c1cee837ce4c5c3b (patch)
treed1c9c7b51353b67b47bb4cd89aa82754ef0a1234 /Timeline.Tests/Helpers/TestClock.cs
parent85d25348c9d6ad527b86c57fd5023829c8b9d6bf (diff)
parent2a32e03a384a30b14988b0b6e40db845f4a5444e (diff)
downloadtimeline-ebda3fc381ee4ed9f729fa85c1cee837ce4c5c3b.tar.gz
timeline-ebda3fc381ee4ed9f729fa85c1cee837ce4c5c3b.tar.bz2
timeline-ebda3fc381ee4ed9f729fa85c1cee837ce4c5c3b.zip
Merge pull request #34 from crupest/token-time
Set token expired time and write unit tests.
Diffstat (limited to 'Timeline.Tests/Helpers/TestClock.cs')
-rw-r--r--Timeline.Tests/Helpers/TestClock.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/Timeline.Tests/Helpers/TestClock.cs b/Timeline.Tests/Helpers/TestClock.cs
new file mode 100644
index 00000000..91523f2b
--- /dev/null
+++ b/Timeline.Tests/Helpers/TestClock.cs
@@ -0,0 +1,25 @@
+using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using Timeline.Services;
+
+namespace Timeline.Tests.Helpers
+{
+ public class TestClock : IClock
+ {
+ public DateTime? MockCurrentTime { get; set; } = null;
+
+ public DateTime GetCurrentTime()
+ {
+ return MockCurrentTime.GetValueOrDefault(DateTime.Now);
+ }
+ }
+
+ public static class TestClockWebApplicationFactoryExtensions
+ {
+ public static TestClock GetTestClock<T>(this WebApplicationFactory<T> factory) where T : class
+ {
+ return factory.Server.Host.Services.GetRequiredService<IClock>() as TestClock;
+ }
+ }
+}