forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlStatementLoggerFixture.cs
44 lines (41 loc) · 1.37 KB
/
SqlStatementLoggerFixture.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
using NHibernate.AdoNet.Util;
using NUnit.Framework;
namespace NHibernate.Test.UtilityTest
{
[TestFixture]
public class SqlStatementLoggerFixture
{
[Test]
public void SupportsInvalidSql()
{
using (var spy = new SqlLogSpy())
{
var logger = new SqlStatementLogger(false, true);
using (var cmd = new System.Data.SqlClient.SqlCommand(
"UPDATE Table Set Column = @p0; @p0 = 'Some data with an embedded quote in parentheses and signal word (''UPDATE'') like this: (don't update)'"))
{
Assert.DoesNotThrow(() => logger.LogCommand(cmd, FormatStyle.Basic));
}
Assert.That(spy.GetWholeLog(), Contains.Substring("Some data with an embedded quote"));
}
}
[Test]
public void SupportsKeywordInParameter()
{
using (var spy = new SqlLogSpy())
{
var logger = new SqlStatementLogger(false, true);
using (var cmd = new System.Data.SqlClient.SqlCommand("UPDATE Table Set Column = @p0;"))
{
cmd.Parameters.AddWithValue(
"p0",
"Some data with an embedded quote in parentheses and signal word ('UPDATE') like this: (don't update)");
Assert.DoesNotThrow(() => logger.LogCommand(cmd, FormatStyle.Basic));
}
var log = spy.GetWholeLog();
Assert.That(log, Contains.Substring("Some data with an embedded quote"));
Assert.That(log.Split('\n'), Has.Length.GreaterThan(2), "SQL seems not formatted");
}
}
}
}