-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathParameterParserFixture.cs
95 lines (84 loc) · 2.59 KB
/
ParameterParserFixture.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using NHibernate.Engine.Query;
using NSubstitute;
using NUnit.Framework;
namespace NHibernate.Test.EngineTest
{
[TestFixture]
public class ParameterParserFixture
{
[Test]
public void CanFindParameterAfterComment()
{
string query =
@"
SELECT id
FROM tablea
/* Comment with ' number 2 */
WHERE Name = :name
ORDER BY Name";
var recognizer = new ParamLocationRecognizer();
ParameterParser.Parse(query, recognizer);
Assert.That(recognizer.NamedParameterDescriptionMap, Has.Count.EqualTo(1));
Assert.That(recognizer.NamedParameterDescriptionMap, Contains.Key("name"));
}
[Test]
public void CanFindParameterAfterInlineComment()
{
string query =
@"
SELECT id
FROM tablea
-- Comment with ' :number 1
WHERE Name = :name
ORDER BY Name";
var recognizer = new ParamLocationRecognizer();
ParameterParser.Parse(query, recognizer);
Assert.That(recognizer.NamedParameterDescriptionMap, Has.Count.EqualTo(1));
Assert.That(recognizer.NamedParameterDescriptionMap, Contains.Key("name"));
}
[Test]
public void CanFindParameterAfterAnyComment()
{
string query =
@"
SELECT id
FROM tablea
-- Comment with ' number 1
WHERE Name = :name
/* Comment with ' number 2 */
ORDER BY Name + :pizza";
var recognizer = new ParamLocationRecognizer();
ParameterParser.Parse(query, recognizer);
Assert.That(recognizer.NamedParameterDescriptionMap, Has.Count.EqualTo(2));
Assert.That(recognizer.NamedParameterDescriptionMap, Contains.Key("name"));
Assert.That(recognizer.NamedParameterDescriptionMap, Contains.Key("pizza"));
}
[Test]
public void IgnoresCommentsWithinQuotes()
{
string query =
@"
SELECT id
FROM tablea WHERE Name = '
-- :comment1
' OR Name = '
/* :comment2 */
'
-- :comment3
/* :comment4 */
ORDER BY Name + :pizza -- :comment5";
var recognizer = Substitute.For<ParameterParser.IRecognizer>();
ParameterParser.Parse(query, recognizer);
//Only one parameter in the query
recognizer.ReceivedWithAnyArgs(1).NamedParameter(default, default);
recognizer.Received(1).NamedParameter("pizza", Arg.Any<int>());
//comment1 and comment2 are not really comments and therefore not parsed as blocks
recognizer.DidNotReceive().Other(Arg.Is<string>(x => x.Contains("comment1")));
recognizer.DidNotReceive().Other(Arg.Is<string>(x => x.Contains("comment2")));
//comment 3-5 are actual comments and therefore parsed as blocks
recognizer.Received(1).Other(Arg.Is<string>(x => x.StartsWith("-- :comment3")));
recognizer.Received(1).Other("/* :comment4 */");
recognizer.Received(1).Other(Arg.Is<string>(x => x.StartsWith("-- :comment5")));
}
}
}