forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSumTests.cs
59 lines (53 loc) · 1.17 KB
/
SumTests.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
using System;
using System.Linq;
using NUnit.Framework;
namespace NHibernate.Test.Linq.ByMethod
{
[TestFixture]
public class SumTests : LinqTestCase
{
[Test]
public void EmptySumDecimal()
{
Assert.That(
() =>
{
db.OrderLines.Where(ol => false).Sum(ol => ol.Discount);
},
// Before NH-3850
Throws.InstanceOf<HibernateException>()
// After NH-3850
.Or.InstanceOf<InvalidOperationException>());
}
[Test]
public void EmptySumCastNullableDecimal()
{
decimal total = db.OrderLines.Where(ol => false).Sum(ol => (decimal?)ol.Discount) ?? 0;
Assert.AreEqual(0, total);
}
[Test]
public void SumDecimal()
{
decimal total = db.OrderLines.Sum(ol => ol.Discount);
Assert.Greater(total, 0);
}
[Test]
public void EmptySumNullableDecimal()
{
decimal total = db.Orders.Where(ol => false).Sum(ol => ol.Freight) ?? 0;
Assert.AreEqual(0, total);
}
[Test]
public void SumNullableDecimal()
{
decimal? total = db.Orders.Sum(ol => ol.Freight);
Assert.Greater(total, 0);
}
[Test]
public void SumSingle()
{
float total = db.Products.Sum(p => p.ShippingWeight);
Assert.Greater(total, 0);
}
}
}