forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryCommentTests.cs
60 lines (53 loc) · 1.6 KB
/
QueryCommentTests.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.Linq;
using NUnit.Framework;
namespace NHibernate.Test.Linq
{
[TestFixture]
public class QueryCommentTests : LinqTestCase
{
protected override void Configure(Configuration configuration)
{
configuration.SetProperty(Environment.UseSqlComments, "true");
}
[Test]
public void CanSetCommentOnLinqQueries()
{
using (var sl = new SqlLogSpy())
{
var comment = "This is my comment";
var result = (from e in db.Customers
where e.CompanyName == "Bon app'"
select e).WithOptions(o => o.SetComment(comment)).ToList();
var sql = sl.Appender.GetEvents()[0].RenderedMessage;
Assert.That(sql.IndexOf(comment), Is.GreaterThan(0));
}
}
[Test]
public void CanSetCommentOnLinqPagingQuery()
{
using (var sl = new SqlLogSpy())
{
var comment = "This is my comment";
var result = (from e in db.Customers
select e).Skip(1).Take(1).WithOptions(o => o.SetComment(comment)).ToList();
var sql = sl.Appender.GetEvents()[0].RenderedMessage;
Assert.That(sql.IndexOf(comment), Is.GreaterThan(0));
}
}
[Test]
public void CanSetCommentBeforeSkipOnLinqOrderedPageQuery()
{
using (var sl = new SqlLogSpy())
{
var comment = "This is my comment";
var result = (from e in db.Customers
orderby e.CompanyName
select e).WithOptions(o => o.SetComment(comment)).Skip(5).Take(5).ToList();
var sql = sl.Appender.GetEvents()[0].RenderedMessage;
Assert.That(sql.IndexOf(comment), Is.GreaterThan(0));
}
}
}
}