forked from RobThree/IdGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MockTimeSource.cs
53 lines (42 loc) · 1.1 KB
/
MockTimeSource.cs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using IdGen;
using System;
using System.Threading;
namespace IdGenTests
{
public class MockTimeSource : ITimeSource
{
private long _current;
private TimeSpan _tickduration;
public MockTimeSource()
: this(0) { }
public MockTimeSource(long current)
: this(current, TimeSpan.FromMilliseconds(1)) { }
public MockTimeSource(TimeSpan tickDuration)
: this(0, tickDuration) { }
public MockTimeSource(long current, TimeSpan tickDuration)
{
_current = current;
_tickduration = tickDuration;
}
public DateTimeOffset Epoch
{
get { return DateTimeOffset.MinValue; }
}
public TimeSpan TickDuration
{
get { return _tickduration; }
}
public long GetTicks()
{
return _current;
}
public void NextTick()
{
Interlocked.Increment(ref _current);
}
public void PreviousTick()
{
Interlocked.Decrement(ref _current);
}
}
}