-
-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathMockTimeSource.cs
More file actions
27 lines (18 loc) · 783 Bytes
/
MockTimeSource.cs
File metadata and controls
27 lines (18 loc) · 783 Bytes
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
26
27
using IdGen;
using System;
using System.Threading;
namespace IdGenTests.Mocks;
public class MockTimeSource(long current, TimeSpan tickDuration, DateTimeOffset epoch) : ITimeSource
{
public MockTimeSource()
: this(0) { }
public DateTimeOffset Epoch { get; private set; } = epoch;
public TimeSpan TickDuration { get; } = tickDuration;
public MockTimeSource(long current)
: this(current, TimeSpan.FromMilliseconds(1), DateTimeOffset.MinValue) { }
public MockTimeSource(TimeSpan tickDuration)
: this(0, tickDuration, DateTimeOffset.MinValue) { }
public virtual long GetTicks() => current;
public void NextTick() => Interlocked.Increment(ref current);
public void PreviousTick() => Interlocked.Decrement(ref current);
}