|
| 1 | +namespace HeboTech.Quartz.Tests |
| 2 | +{ |
| 3 | + public class CustomClockTests |
| 4 | + { |
| 5 | + [Fact] |
| 6 | + public void Default_constructor_initialize_with_DateTimeOffset_min_value() |
| 7 | + { |
| 8 | + ISystemClock customClock = new CustomClock(); |
| 9 | + |
| 10 | + Assert.Equal(DateTimeOffset.MinValue, customClock.UtcNow); |
| 11 | + } |
| 12 | + |
| 13 | + [Fact] |
| 14 | + public void Setting_custom_DateTimeOffset_through_constructor_returns_the_custom_time() |
| 15 | + { |
| 16 | + DateTimeOffset time = new(2022, 1, 1, 0, 0, 0, TimeSpan.Zero); |
| 17 | + ISystemClock customClock = new CustomClock(time); |
| 18 | + |
| 19 | + Assert.Equal(time, customClock.UtcNow); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void Setting_custom_DateTimeOffset_func_through_constructor_returns_the_custom_time() |
| 24 | + { |
| 25 | + DateTimeOffset time = new(2022, 1, 1, 0, 0, 0, TimeSpan.Zero); |
| 26 | + ISystemClock customClock = new CustomClock(() => time); |
| 27 | + |
| 28 | + Assert.Equal(time, customClock.UtcNow); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void Setting_custom_DateTime_through_constructor_returns_the_custom_time() |
| 33 | + { |
| 34 | + DateTime time = new(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 35 | + ISystemClock customClock = new CustomClock(time); |
| 36 | + |
| 37 | + Assert.Equal(time, customClock.UtcNow); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public void Setting_custom__DateTime_func_through_constructor_returns_the_custom_time() |
| 42 | + { |
| 43 | + DateTime time = new(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 44 | + ISystemClock customClock = new CustomClock(() => time); |
| 45 | + |
| 46 | + Assert.Equal(time, customClock.UtcNow); |
| 47 | + } |
| 48 | + |
| 49 | + [Fact] |
| 50 | + public void Set_DateTimeOffset_returns_the_custom_time() |
| 51 | + { |
| 52 | + DateTimeOffset time = new(2022, 1, 1, 0, 0, 0, TimeSpan.Zero); |
| 53 | + CustomClock customClock = new CustomClock(); |
| 54 | + customClock.Set(time); |
| 55 | + |
| 56 | + Assert.Equal(time, customClock.UtcNow); |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void Set_DateTimeOffset_func_returns_the_custom_time() |
| 61 | + { |
| 62 | + DateTimeOffset time = new(2022, 1, 1, 0, 0, 0, TimeSpan.Zero); |
| 63 | + CustomClock customClock = new CustomClock(); |
| 64 | + customClock.Set(() => time); |
| 65 | + |
| 66 | + Assert.Equal(time, customClock.UtcNow); |
| 67 | + } |
| 68 | + |
| 69 | + [Fact] |
| 70 | + public void Set_DateTime_returns_the_custom_time() |
| 71 | + { |
| 72 | + DateTime time = new(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 73 | + CustomClock customClock = new CustomClock(); |
| 74 | + customClock.Set(time); |
| 75 | + |
| 76 | + Assert.Equal(time, customClock.UtcNow); |
| 77 | + } |
| 78 | + |
| 79 | + [Fact] |
| 80 | + public void Set_DateTime_func_returns_the_custom_time() |
| 81 | + { |
| 82 | + DateTime time = new(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc); |
| 83 | + CustomClock customClock = new CustomClock(); |
| 84 | + customClock.Set(() => time); |
| 85 | + |
| 86 | + Assert.Equal(time, customClock.UtcNow); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments