Skip to content

Commit a38db15

Browse files
committed
Add test for SQL Server
1 parent e2f789d commit a38db15

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Linq;
3+
using Blaze.Randomization;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace UnitTest.Database
7+
{
8+
[TestClass]
9+
public class SqlServerTest
10+
{
11+
[TestMethod]
12+
public void Data()
13+
{
14+
InsertData();
15+
GetData();
16+
}
17+
18+
static void InsertData()
19+
{
20+
using (var db = new RandomTestDb())
21+
{
22+
for (int i = 0; i < 20; i++)
23+
{
24+
var id = RandomData.GenerateOrderedGuid2();
25+
var idSql = RandomData.GenerateOrderedSqlGuid2();
26+
var name = RandomData.GenerateAlphanumerics(20);
27+
28+
db.Categories.Add(new Category
29+
{
30+
Id = id.Guid.ToString(),
31+
Created = id.DateTime,
32+
Name = name,
33+
});
34+
db.Products.Add(new Product
35+
{
36+
Id = idSql.Guid,
37+
Created = idSql.DateTime,
38+
Name = name,
39+
});
40+
41+
System.Threading.Thread.Sleep(1);
42+
}
43+
44+
db.SaveChanges();
45+
}
46+
}
47+
48+
static void GetData()
49+
{
50+
using (var db = new RandomTestDb())
51+
{
52+
var lower = new DateTime(2014, 4, 10, 14, 54, 59).ToSqlGuid2();
53+
var upper = new DateTime(2014, 4, 10, 14, 55, 1).ToSqlGuid2();
54+
55+
var products = db.Products
56+
.Where(p => p.Id.CompareTo(lower) > 0)
57+
.Where(p => p.Id.CompareTo(upper) < 0)
58+
.ToArray();
59+
60+
foreach (var item in products)
61+
{
62+
Console.WriteLine(item.Created);
63+
}
64+
}
65+
}
66+
}
67+
68+
public static class RandomDataHelper
69+
{
70+
public static Guid ToSqlGuid(this DateTime dateTime)
71+
{
72+
return new Guid(0, 0, 0, dateTime.ToBytesForSqlGuid());
73+
}
74+
75+
public static Guid ToSqlGuid2(this DateTime dateTime)
76+
{
77+
return new Guid(new byte[10].Concat(dateTime.ToBytes2()).ToArray());
78+
}
79+
}
80+
}

RandomData2/UnitTest/UnitTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<Compile Include="Client\HttpHelper.cs" />
7171
<Compile Include="Client\RandomTest.cs" />
7272
<Compile Include="Database\RandomTestDb.cs" />
73+
<Compile Include="Database\SqlServerTest.cs" />
7374
<Compile Include="Properties\AssemblyInfo.cs" />
7475
</ItemGroup>
7576
<ItemGroup>

0 commit comments

Comments
 (0)