forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryBooleanExpressionTests.cs
122 lines (100 loc) · 3.71 KB
/
BinaryBooleanExpressionTests.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
using System;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.DomainModel.Northwind.Entities;
using NUnit.Framework;
namespace NHibernate.Test.Linq
{
[TestFixture]
public class BinaryBooleanExpressionTests : LinqTestCase
{
[Test]
public void TimesheetsWithEqualsTrue()
{
var query = (from timesheet in db.Timesheets
where timesheet.Entries.Any()
select timesheet).ToList();
Assert.AreEqual(2, query.Count);
}
[Test]
public void NegativeTimesheetsWithEqualsTrue()
{
var query = (from timesheet in db.Timesheets
where !timesheet.Entries.Any()
select timesheet).ToList();
Assert.AreEqual(1, query.Count);
}
[Test]
public void TimesheetsWithEqualsFalse()
{
var query = (from timesheet in db.Timesheets
where timesheet.Entries.Any() == false
select timesheet).ToList();
Assert.AreEqual(1, query.Count);
}
[Test]
public void NegativeTimesheetsWithEqualsFalse()
{
var query = (from timesheet in db.Timesheets
where !timesheet.Entries.Any() == false
select timesheet).ToList();
Assert.AreEqual(2, query.Count);
}
[Test]
public void TimesheetsWithNotEqualsTrue()
{
var query = (from timesheet in db.Timesheets
where timesheet.Entries.Any() != true
select timesheet).ToList();
Assert.AreEqual(1, query.Count);
}
[Test]
public void NegativeTimesheetsWithNotEqualsTrue()
{
var query = (from timesheet in db.Timesheets
where !timesheet.Entries.Any() != true
select timesheet).ToList();
Assert.AreEqual(2, query.Count);
}
[Test]
public void TimesheetsWithNotEqualsFalse()
{
var query = (from timesheet in db.Timesheets
where timesheet.Entries.Any() != false
select timesheet).ToList();
Assert.AreEqual(2, query.Count);
}
[Test]
public void NegativeTimesheetsWithNotEqualsFalse()
{
var query = (from timesheet in db.Timesheets
where !timesheet.Entries.Any() != false
select timesheet).ToList();
Assert.AreEqual(1, query.Count);
}
[Test]
public void BooleanPropertyComparison()
{
var query = db.Timesheets.Where(t => t.Submitted == true);
Assert.AreEqual(2, query.ToList().Count);
}
[Test]
public void BooleanPropertyAlone()
{
var query = db.Timesheets.Where(t => t.Submitted);
Assert.AreEqual(2, query.ToList().Count);
}
[Test]
public void MammalsViaDynamicInvokedExpression()
{
//simulate dynamically created where clause
Expression<Func<Mammal, bool>> expr1 = mammal => mammal.Pregnant;
Expression<Func<Mammal, bool>> expr2 = mammal => false;
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
var dynamicWhereClause = Expression.Lambda<Func<Mammal, bool>>
(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
var animals = db.Mammals.Where(dynamicWhereClause).ToArray();
Assert.AreEqual(0, animals.Count());
}
}
}