forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperatorTests.cs
51 lines (46 loc) · 1.45 KB
/
OperatorTests.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using NHibernate.DomainModel.Northwind.Entities;
using NHibernate.Linq;
using NUnit.Framework;
namespace NHibernate.Test.Linq
{
[TestFixture]
public class OperatorTests : LinqTestCase
{
[Test]
public void Mod()
{
Assert.AreEqual(2, session.Query<TimesheetEntry>().Where(a => a.NumberOfHours % 7 == 0).Count());
}
[Test]
public void UnaryMinus()
{
Assert.AreEqual(1, session.Query<TimesheetEntry>().Count(a => -a.NumberOfHours == -7));
}
[Test]
public void DecimalAdd()
{
decimal offset = 5.5m;
decimal test = 10248 + offset;
var result = session.Query<Order>().Where(e => offset + e.OrderId == test).ToList();
Assert.That(result, Has.Count.EqualTo(1));
offset = 5.5m;
test = 32.38m + offset;
result = session.Query<Order>().Where(e => offset + e.Freight == test).ToList();
Assert.That(result, Has.Count.EqualTo(1));
}
[Test]
public void UnaryPlus()
{
// Ensure expression tree contains UnaryPlus
var param = Expression.Parameter(typeof(TimesheetEntry), "e");
var expr = Expression.Equal(Expression.UnaryPlus(Expression.PropertyOrField(param, "NumberOfHours")), Expression.Constant(7));
var predicate = Expression.Lambda<Func<TimesheetEntry, bool>>(expr, param);
Assert.AreEqual(1, session.Query<TimesheetEntry>().Count(predicate));
}
}
}