-
Notifications
You must be signed in to change notification settings - Fork 12
/
ShortcutTests.cs
206 lines (171 loc) · 9.57 KB
/
ShortcutTests.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PoweredSoft.DynamicLinq;
using PoweredSoft.DynamicLinq.Test.Helpers;
namespace PoweredSoft.DynamicLinq.Test
{
[TestClass]
public class ShortcutTests
{
internal List<MockPersonObject> Persons = new List<MockPersonObject>
{
new MockPersonObject { FirstName = "David", LastName = "Lebee", Age = 28 },
new MockPersonObject { FirstName = "Michaela", LastName = "Vickar", Age = 27 },
new MockPersonObject { FirstName = "John", LastName = "Doe", Age = 28 },
new MockPersonObject { FirstName = "Chuck", LastName = "Norris", Age = 50 },
new MockPersonObject { FirstName = "Michael", LastName = "Jackson", Age = 58 }
};
[TestMethod]
public void Equal()
{
// test simple
var q1 = Persons.AsQueryable().Query(t => t.Equal("FirstName", "David"));
var q1b = Persons.AsQueryable().Where(t => t.FirstName == "David");
QueryableAssert.AreEqual(q1, q1b);
// test and
var q2 = Persons.AsQueryable().Query(t => t.Equal("FirstName", "David").AndEqual("LastName", "Lebee"));
var q2b = Persons.AsQueryable().Where(t => t.FirstName == "David" && t.LastName == "Lebee");
QueryableAssert.AreEqual(q2, q2b);
// test or
var q3 = Persons.AsQueryable().Query(t => t.Equal("FirstName", "David").OrEqual("FirstName", "Michaela"));
var q3b = Persons.AsQueryable().Where(t => t.FirstName == "David" || t.FirstName == "Michaela");
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void NotEqual()
{
// test simple
var q1 = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "David"));
var q1b = Persons.AsQueryable().Where(t => t.FirstName != "David");
QueryableAssert.AreEqual(q1, q1b);
// test and
var q2 = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "David").AndNotEqual("FirstName", "Michaela"));
var q2b = Persons.AsQueryable().Where(t => t.FirstName != "David" && t.FirstName != "Michaela");
QueryableAssert.AreEqual(q2, q2b);
// test or
var q3 = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "David").OrNotEqual("LastName", "Lebee"));
var q3b = Persons.AsQueryable().Where(t => t.FirstName != "David" || t.LastName != "Lebee");
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void GreatThan()
{
var q1 = Persons.AsQueryable().Query(t => t.GreaterThan("Age", 28));
var q1b = Persons.AsQueryable().Where(t => t.Age > 28);
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.GreaterThan("Age", 28).AndGreaterThan("Age", 50));
var q2b = Persons.AsQueryable().Where(t => t.Age > 28 && t.Age > 50);
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.GreaterThan("Age", 28).OrGreaterThan("Age", 50));
var q3b = Persons.AsQueryable().Where(t => t.Age > 28 || t.Age > 50);
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void GreatThanOrEqual()
{
var q1 = Persons.AsQueryable().Query(t => t.GreaterThanOrEqual("Age", 28));
var q1b = Persons.AsQueryable().Where(t => t.Age >= 28);
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.GreaterThanOrEqual("Age", 28).AndGreaterThanOrEqual("Age", 50));
var q2b = Persons.AsQueryable().Where(t => t.Age >= 28 && t.Age >= 50);
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.GreaterThanOrEqual("Age", 28).OrGreaterThanOrEqual("Age", 50));
var q3b = Persons.AsQueryable().Where(t => t.Age >= 28 || t.Age >= 50);
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void LessThan()
{
var q1 = Persons.AsQueryable().Query(t => t.LessThan("Age", 50));
var q1b = Persons.AsQueryable().Where(t => t.Age < 50);
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.LessThan("Age", 28).AndLessThan("Age", 50));
var q2b = Persons.AsQueryable().Where(t => t.Age < 28 && t.Age < 50);
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.LessThan("Age", 28).OrLessThan("Age", 50));
var q3b = Persons.AsQueryable().Where(t => t.Age < 28 || t.Age < 50);
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void LessThanOrEqual()
{
var q1 = Persons.AsQueryable().Query(t => t.LessThanOrEqual("Age", 50));
var q1b = Persons.AsQueryable().Where(t => t.Age <= 50);
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.LessThanOrEqual("Age", 28).AndLessThanOrEqual("Age", 50));
var q2b = Persons.AsQueryable().Where(t => t.Age <= 28 && t.Age <= 50);
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.LessThanOrEqual("Age", 28).OrLessThanOrEqual("Age", 50));
var q3b = Persons.AsQueryable().Where(t => t.Age <= 28 || t.Age <= 50);
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void StartsWith()
{
var q1 = Persons.AsQueryable().Query(t => t.StartsWith("FirstName", "Mi"));
var q1b = Persons.AsQueryable().Where(t => t.FirstName.StartsWith("Mi"));
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.StartsWith("FirstName", "Mi").AndStartsWith("LastName", "Vi"));
var q2b = Persons.AsQueryable().Where(t => t.FirstName.StartsWith("Mi") && t.LastName.StartsWith("Vi"));
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.StartsWith("FirstName", "Mi").OrStartsWith("FirstName", "Da"));
var q3b = Persons.AsQueryable().Where(t => t.FirstName.StartsWith("Mi") || t.FirstName.StartsWith("Da"));
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void EndsWith()
{
var q1 = Persons.AsQueryable().Query(t => t.EndsWith("LastName", "ee"));
var q1b = Persons.AsQueryable().Where(t => t.LastName.EndsWith("ee"));
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.EndsWith("LastName", "ee").AndEndsWith("FirstName", "vid"));
var q2b = Persons.AsQueryable().Where(t => t.LastName.EndsWith("ee") && t.FirstName.EndsWith("vid"));
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.EndsWith("LastName", "ee").OrEndsWith("LastName", "ar"));
var q3b = Persons.AsQueryable().Where(t => t.LastName.EndsWith("ee") || t.LastName.EndsWith("ar"));
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void Contains()
{
var q1 = Persons.AsQueryable().Query(t => t.Contains("LastName", "ee"));
var q1b = Persons.AsQueryable().Where(t => t.LastName.Contains("ee"));
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.Contains("LastName", "ee").AndContains("FirstName", "vid"));
var q2b = Persons.AsQueryable().Where(t => t.LastName.Contains("ee") && t.FirstName.Contains("vid"));
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.Contains("LastName", "ee").OrContains("LastName", "ar"));
var q3b = Persons.AsQueryable().Where(t => t.LastName.Contains("ee") || t.LastName.Contains("ar"));
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void NotContains()
{
var q1 = Persons.AsQueryable().Query(t => t.Contains("LastName", "ee", negate: true));
var q1b = Persons.AsQueryable().Where(t => !t.LastName.Contains("ee"));
QueryableAssert.AreEqual(q1, q1b);
}
[TestMethod]
public void NotContains2()
{
var q1 = Persons.AsQueryable().Query(t => t.NotContains("LastName", "ee"));
var q1b = Persons.AsQueryable().Where(t => !t.LastName.Contains("ee"));
QueryableAssert.AreEqual(q1, q1b);
var q2 = Persons.AsQueryable().Query(t => t.NotContains("LastName", "ee").AndNotContains("FirstName", "vid"));
var q2b = Persons.AsQueryable().Where(t => !t.LastName.Contains("ee") && !t.FirstName.Contains("vid"));
QueryableAssert.AreEqual(q2, q2b);
var q3 = Persons.AsQueryable().Query(t => t.NotContains("LastName", "ee").OrNotContains("LastName", "ar"));
var q3b = Persons.AsQueryable().Where(t => !t.LastName.Contains("ee") || !t.LastName.Contains("ar"));
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void ContainsAndNotContains()
{
var q1 = Persons.AsQueryable().Query(t => t.Contains("LastName", "s").AndNotContains("LastName", "r"));
var q1b = Persons.AsQueryable().Where(t => t.LastName.Contains("s") && !t.LastName.Contains("r"));
QueryableAssert.AreEqual(q1, q1b);
}
}
}