forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggingTests.cs
60 lines (49 loc) · 1.99 KB
/
LoggingTests.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
using System.Linq;
using NHibernate.Cfg;
using NHibernate.DomainModel.Northwind.Entities;
using NUnit.Framework;
namespace NHibernate.Test.Linq
{
[TestFixture]
public class LoggingTests : LinqTestCase
{
[Test]
public void PageBetweenProjections()
{
using (var spy = new LogSpy("NHibernate.Linq"))
{
var subquery = db.Products.Where(p => p.ProductId > 5);
var list = db.Products.Where(p => subquery.Contains(p))
.Skip(5).Take(10)
.ToList();
var logtext = spy.GetWholeLog();
const string expected =
"Expression (partially evaluated): value(NHibernate.Linq.NhQueryable`1[NHibernate.DomainModel.Northwind.Entities.Product]).Where(p => value(NHibernate.Linq.NhQueryable`1[NHibernate.DomainModel.Northwind.Entities.Product]).Where(p => (p.ProductId > 5)).Contains(p)).Skip(5).Take(10)";
Assert.That(logtext, Does.Contain(expected));
}
}
[Test]
public void CanLogLinqExpressionWithoutInitializingContainedProxy()
{
var productId = db.Products.Select(p => p.ProductId).First();
using (var logspy = new LogSpy("NHibernate.Linq"))
{
var productProxy = session.Load<Product>(productId);
Assert.That(NHibernateUtil.IsInitialized(productProxy), Is.False);
var result = from product in db.Products
where product == productProxy
select product;
Assert.That(result.Count(), Is.EqualTo(1));
// Verify that the expected logging did happen.
var actualLog = logspy.GetWholeLog();
string expectedLog =
"Expression (partially evaluated): value(NHibernate.Linq.NhQueryable`1[NHibernate.DomainModel.Northwind.Entities.Product])" +
".Where(product => (product == Product#" + productId + ")).Count()";
Assert.That(actualLog, Does.Contain(expectedLog));
// And verify that the proxy in the expression wasn't initialized.
Assert.That(NHibernateUtil.IsInitialized(productProxy), Is.False,
"ERROR: We expected the proxy to NOT be initialized.");
}
}
}
}