-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestOperators.cs
165 lines (131 loc) · 5.06 KB
/
TestOperators.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
using NUnit.Framework;
using Amigo.ORM.Utils;
namespace AmigoTests
{
[TestFixture]
public class TestOperators
{
[Test]
public void TestQueryEqual()
{
var value = new Eq(new {Author__FirstName = "Foo's"}).ToString();
var expected = "author.firstname = 'Foo''s'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryEqualMulti()
{
var value = new Eq(new {Author__FirstName = "Foo", Author__LastName = 6}).ToString();
var expected = "author.firstname = 'Foo' AND author.lastname = 6";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryNotEqual()
{
var value = new Neq(new {Author__FirstName = "Foo"}).ToString();
var expected = "author.firstname != 'Foo'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryNotEqualMulti()
{
var value = new Neq(new {Author__FirstName = "Foo", Author__LastName = 6}).ToString();
var expected = "author.firstname != 'Foo' AND author.lastname != 6";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryAnd()
{
var value = new And(
new Eq(new {Name = "foo"}),
new Neq(new {Label = "bar"})
).ToString();
var expected = "name = 'foo' AND label != 'bar'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryOr()
{
var value = new Or(
new Eq(new {Name = "foo"}),
new Neq(new {Label = "bar"})
).ToString();
var expected = "name = 'foo' OR label != 'bar'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryOrWithNestedAnd()
{
var value = new Or(
new Eq(new {Name = "foo"}),
new And(
new Eq(new {Label = "bar"}),
new Neq(new {Description = "baz"})
),
new Eq(new {Zap = "qux"})
).ToString();
var expected = "name = 'foo' OR (label = 'bar' AND description != 'baz') OR zap = 'qux'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryAndWithNestedOr()
{
var value = new And(
new Eq(new {Name = "foo"}),
new Or(
new Eq(new {Label = "bar"}),
new Neq(new {Description = "baz"})
),
new Eq(new {Zap = "qux"})
).ToString();
var expected = "name = 'foo' AND (label = 'bar' OR description != 'baz') AND zap = 'qux'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryAndWithNestedAnd()
{
var value = new And(
new Eq(new {Name = "foo"}),
new And(
new Eq(new {Label = "bar"}),
new Neq(new {Description = "baz"})
),
new Eq(new {Zap = "qux"})
).ToString();
var expected = "name = 'foo' AND (label = 'bar' AND description != 'baz') AND zap = 'qux'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryOrWithNestedOr()
{
var value = new Or(
new Eq(new {Name = "foo"}),
new Or(
new Eq(new {Label = "bar"}),
new Neq(new {Description = "baz"})
),
new Eq(new {Zap = "qux"})
).ToString();
var expected = "name = 'foo' OR (label = 'bar' OR description != 'baz') OR zap = 'qux'";
Assert.AreEqual(expected, value);
}
[Test]
public void TestQueryWithDefaultTable()
{
var op = new Or(
new Eq(new {Name = "foo"}),
new Or(
new Eq(new {Label = "bar"}),
new Neq(new {Description = "baz"})
),
new Eq(new {Zap = "qux"})
);
op.DefaultTable = "Post";
var value = op.ToString();
var expected = "post.name = 'foo' OR (post.label = 'bar' OR post.description != 'baz') OR post.zap = 'qux'";
Assert.AreEqual(expected, value);
}
}
}
//# create a configured "Session" class
//Session = sessionmaker(bind=some_engine)