-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathIntegrationTests.cs
139 lines (117 loc) · 3.7 KB
/
IntegrationTests.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.IO;
using System.Linq;
using GDataDB.Linq;
using NUnit.Framework;
namespace GDataDB.Tests {
[TestFixture]
public class IntegrationTests {
private ITable<IntegrationEntity> table;
private IDatabase db;
private readonly IntegrationEntity e1 = new IntegrationEntity {
DateTimeProp = new DateTime(2001, 1, 1, 5, 6, 7),
StringProp = "ñãá",
IntProp = 1,
};
private readonly IntegrationEntity e2 = new IntegrationEntity {
DateTimeProp = new DateTime(2005, 6, 7, 10, 6, 7),
IntProp = 1000,
};
[TestFixtureSetUp]
public void FixtureSetup() {
Console.WriteLine("Connecting");
var client = new DatabaseClient(
clientEmail: "[email protected]",
privateKey: File.ReadAllBytes(@"xxx.p12"));
const string dbName = "IntegrationTests";
Console.WriteLine("Opening or creating database");
db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
const string tableName = "IntegrationTests";
Console.WriteLine("Opening or creating table");
table = db.GetTable<IntegrationEntity>(tableName) ?? db.CreateTable<IntegrationEntity>(tableName);
}
[SetUp]
public void setup() {
table.Clear();
table.Add(e1);
table.Add(e2);
}
[TestFixtureTearDown]
public void FixtureTearDown() {
//table.Delete();
//db.Delete();
}
[Test]
public void Rename() {
table.Rename("something");
table.Rename("IntegrationTests");
}
[Test]
public void Add() {
table.Add(new IntegrationEntity {
FloatProp = 123.45f,
DecimalProp = 234.56m,
DoubleProp = 333.44,
});
}
[Test]
public void LINQ_orderby_int() {
var q = from r in table.AsQueryable()
orderby r.IntProp
select r;
var l = q.ToList();
Assert.AreEqual(2, l.Count);
Assert.AreEqual(e1.IntProp, l[0].IntProp);
Assert.AreEqual(e2.IntProp, l[1].IntProp);
}
[Test]
public void LINQ_orderby_int_descending() {
var q = from r in table.AsQueryable()
orderby r.IntProp descending
select r;
var l = q.ToList();
Assert.AreEqual(2, l.Count);
Assert.AreEqual(e2.IntProp, l[0].IntProp);
Assert.AreEqual(e1.IntProp, l[1].IntProp);
}
[Test]
public void LINQ_orderby_datetime() {
var q = from r in table.AsQueryable()
orderby r.DateTimeProp
select r;
var l = q.ToList();
Assert.AreEqual(2, l.Count);
Assert.AreEqual(e1.DateTimeProp, l[0].DateTimeProp);
Assert.AreEqual(e2.DateTimeProp, l[1].DateTimeProp);
}
[Test]
public void LINQ_orderby_datetime_descending() {
var q = from r in table.AsQueryable()
orderby r.DateTimeProp descending
select r;
var l = q.ToList();
Assert.AreEqual(2, l.Count);
Assert.AreEqual(e2.DateTimeProp, l[0].DateTimeProp);
Assert.AreEqual(e1.DateTimeProp, l[1].DateTimeProp);
}
[Test]
public void LINQ_orderby_datetime_descending_take() {
var q = table.AsQueryable()
.OrderByDescending(r => r.DateTimeProp)
.Take(1)
.ToList();
Assert.AreEqual(1, q.Count);
Assert.AreEqual(e2.DateTimeProp, q[0].DateTimeProp);
}
[Test]
public void LINQ_orderby_datetime_descending_take_skip() {
var q = table.AsQueryable()
.OrderByDescending(r => r.DateTimeProp)
.Skip(1)
.Take(1)
.ToList();
Assert.AreEqual(1, q.Count);
Assert.AreEqual(e1.DateTimeProp, q[0].DateTimeProp);
}
}
}