-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewSequentialIdTests.cs
54 lines (43 loc) · 1.5 KB
/
NewSequentialIdTests.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
54
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace Test
{
public class NewSequentialIdTests
{
[Fact]
public async Task GuidsShouldBeSequential()
{
var guids = new List<SqlGuid>();
const int Count = 1000;
for (var i = 0; i < Count; i++)
{
var guid = new SqlGuid(NewGuid());
guids.Add(guid);
// The SQL Server DATETIME structure values are rounded to increments of
// .000, .003, or .007 seconds. This test assumes that the GUID
// generation algorithm target the DATETIME structure and we delay the
// execution with .004 seconds to make sure we get sequential values.
//
// Note that increasing this value does not cause the test to pass.
await Task.Delay(TimeSpan.FromSeconds(0.004));
}
var current = new SqlGuid(Guid.Empty);
Assert.True(guids.Any());
var result = new List<SqlBoolean>();
foreach (var guid in guids)
{
result.Add(SqlGuid.LessThan(current, guid));
current = guid;
}
Assert.Equal(0, result.Count(item => item.Equals(SqlBoolean.False)));
}
private static Guid NewGuid()
{
return NewSequentialId.NewGuid();
}
}
}