blob: 0082171e97af6e49128dc3c1baf36096a76976a2 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 | using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using System;
using Timeline.Services;
namespace Timeline.Tests.Mock.Services
{
    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;
        }
    }
}
 |