8
8
//------------------------------------------------------------------------------
9
9
10
10
11
+ using System ;
11
12
using System . Collections . Generic ;
12
13
using System . Linq ;
14
+ using System . Linq . Expressions ;
13
15
using System . Text . RegularExpressions ;
16
+ using NHibernate . DomainModel . Northwind . Entities ;
14
17
using NUnit . Framework ;
15
18
using NHibernate . Linq ;
16
19
@@ -22,7 +25,7 @@ namespace NHibernate.Test.Linq
22
25
public class ParameterTestsAsync : LinqTestCase
23
26
{
24
27
[ Test ]
25
- public async Task UsingSameArrayParameterTwiceAsync ( )
28
+ public async Task UsingArrayParameterTwiceAsync ( )
26
29
{
27
30
var ids = new [ ] { 11008 , 11019 , 11039 } ;
28
31
await ( AssertTotalParametersAsync (
@@ -31,36 +34,36 @@ public async Task UsingSameArrayParameterTwiceAsync()
31
34
}
32
35
33
36
[ Test ]
34
- public async Task UsingDifferentArrayParametersAsync ( )
37
+ public async Task UsingTwoArrayParametersAsync ( )
35
38
{
36
- var ids = new [ ] { 11008 , 11019 , 11039 } ;
37
- var ids2 = new [ ] { 11008 , 11019 , 11039 } ;
39
+ var ids = new [ ] { 11008 , 11019 , 11039 } ;
40
+ var ids2 = new [ ] { 11008 , 11019 , 11039 } ;
38
41
await ( AssertTotalParametersAsync (
39
42
db . Orders . Where ( o => ids . Contains ( o . OrderId ) && ids2 . Contains ( o . OrderId ) ) ,
40
43
ids . Length + ids2 . Length ) ) ;
41
44
}
42
45
43
46
[ Test ]
44
- public async Task UsingSameListParameterTwiceAsync ( )
47
+ public async Task UsingListParameterTwiceAsync ( )
45
48
{
46
- var ids = new List < int > { 11008 , 11019 , 11039 } ;
49
+ var ids = new List < int > { 11008 , 11019 , 11039 } ;
47
50
await ( AssertTotalParametersAsync (
48
51
db . Orders . Where ( o => ids . Contains ( o . OrderId ) && ids . Contains ( o . OrderId ) ) ,
49
52
ids . Count ) ) ;
50
53
}
51
54
52
55
[ Test ]
53
- public async Task UsingDifferentListParametersAsync ( )
56
+ public async Task UsingTwoListParametersAsync ( )
54
57
{
55
- var ids = new List < int > { 11008 , 11019 , 11039 } ;
56
- var ids2 = new List < int > { 11008 , 11019 , 11039 } ;
58
+ var ids = new List < int > { 11008 , 11019 , 11039 } ;
59
+ var ids2 = new List < int > { 11008 , 11019 , 11039 } ;
57
60
await ( AssertTotalParametersAsync (
58
61
db . Orders . Where ( o => ids . Contains ( o . OrderId ) && ids2 . Contains ( o . OrderId ) ) ,
59
62
ids . Count + ids2 . Count ) ) ;
60
63
}
61
64
62
65
[ Test ]
63
- public async Task UsingSameEntityParameterTwiceAsync ( )
66
+ public async Task UsingEntityParameterTwiceAsync ( )
64
67
{
65
68
var order = await ( db . Orders . FirstAsync ( ) ) ;
66
69
await ( AssertTotalParametersAsync (
@@ -69,17 +72,17 @@ public async Task UsingSameEntityParameterTwiceAsync()
69
72
}
70
73
71
74
[ Test ]
72
- public async Task UsingDifferentEntityParametersAsync ( )
75
+ public async Task UsingTwoEntityParametersAsync ( )
73
76
{
74
77
var order = await ( db . Orders . FirstAsync ( ) ) ;
75
- var order2 = await ( db . Orders . Skip ( 1 ) . FirstAsync ( ) ) ;
78
+ var order2 = await ( db . Orders . FirstAsync ( ) ) ;
76
79
await ( AssertTotalParametersAsync (
77
80
db . Orders . Where ( o => o == order && o != order2 ) ,
78
81
2 ) ) ;
79
82
}
80
83
81
84
[ Test ]
82
- public async Task UsingSameValueTypeParameterTwiceAsync ( )
85
+ public async Task UsingValueTypeParameterTwiceAsync ( )
83
86
{
84
87
var value = 1 ;
85
88
await ( AssertTotalParametersAsync (
@@ -88,17 +91,35 @@ public async Task UsingSameValueTypeParameterTwiceAsync()
88
91
}
89
92
90
93
[ Test ]
91
- public async Task UsingDifferentValueTypeParametersAsync ( )
94
+ public async Task UsingNegateValueTypeParameterTwiceAsync ( )
95
+ {
96
+ var value = 1 ;
97
+ await ( AssertTotalParametersAsync (
98
+ db . Orders . Where ( o => o . OrderId == - value && o . OrderId != - value ) ,
99
+ 1 ) ) ;
100
+ }
101
+
102
+ [ Test ]
103
+ public async Task UsingNegateValueTypeParameterAsync ( )
92
104
{
93
105
var value = 1 ;
94
- var value2 = 2 ;
106
+ await ( AssertTotalParametersAsync (
107
+ db . Orders . Where ( o => o . OrderId == value && o . OrderId != - value ) ,
108
+ 2 ) ) ;
109
+ }
110
+
111
+ [ Test ]
112
+ public async Task UsingTwoValueTypeParametersAsync ( )
113
+ {
114
+ var value = 1 ;
115
+ var value2 = 1 ;
95
116
await ( AssertTotalParametersAsync (
96
117
db . Orders . Where ( o => o . OrderId == value && o . OrderId != value2 ) ,
97
118
2 ) ) ;
98
119
}
99
120
100
121
[ Test ]
101
- public async Task UsingSameStringParameterTwiceAsync ( )
122
+ public async Task UsingStringParameterTwiceAsync ( )
102
123
{
103
124
var value = "test" ;
104
125
await ( AssertTotalParametersAsync (
@@ -107,15 +128,91 @@ public async Task UsingSameStringParameterTwiceAsync()
107
128
}
108
129
109
130
[ Test ]
110
- public async Task UsingDifferentStringParametersAsync ( )
131
+ public async Task UsingTwoStringParametersAsync ( )
111
132
{
112
133
var value = "test" ;
113
- var value2 = "test2 " ;
134
+ var value2 = "test " ;
114
135
await ( AssertTotalParametersAsync (
115
136
db . Products . Where ( o => o . Name == value && o . Name != value2 ) ,
116
137
2 ) ) ;
117
138
}
118
139
140
+ [ Test ]
141
+ public async Task UsingObjectPropertyParameterTwiceAsync ( )
142
+ {
143
+ var value = new Product { Name = "test" } ;
144
+ await ( AssertTotalParametersAsync (
145
+ db . Products . Where ( o => o . Name == value . Name && o . Name != value . Name ) ,
146
+ 1 ) ) ;
147
+ }
148
+
149
+ [ Test ]
150
+ public async Task UsingTwoObjectPropertyParametersAsync ( )
151
+ {
152
+ var value = new Product { Name = "test" } ;
153
+ var value2 = new Product { Name = "test" } ;
154
+ await ( AssertTotalParametersAsync (
155
+ db . Products . Where ( o => o . Name == value . Name && o . Name != value2 . Name ) ,
156
+ 2 ) ) ;
157
+ }
158
+
159
+ [ Test ]
160
+ public async Task UsingObjectNestedPropertyParameterTwiceAsync ( )
161
+ {
162
+ var value = new Employee { Superior = new Employee { Superior = new Employee { FirstName = "test" } } } ;
163
+ await ( AssertTotalParametersAsync (
164
+ db . Employees . Where ( o => o . FirstName == value . Superior . Superior . FirstName && o . FirstName != value . Superior . Superior . FirstName ) ,
165
+ 1 ) ) ;
166
+ }
167
+
168
+ [ Test ]
169
+ public async Task UsingDifferentObjectNestedPropertyParameterAsync ( )
170
+ {
171
+ var value = new Employee { Superior = new Employee { FirstName = "test" , Superior = new Employee { FirstName = "test" } } } ;
172
+ await ( AssertTotalParametersAsync (
173
+ db . Employees . Where ( o => o . FirstName == value . Superior . FirstName && o . FirstName != value . Superior . Superior . FirstName ) ,
174
+ 2 ) ) ;
175
+ }
176
+
177
+ [ Test ]
178
+ public async Task UsingMethodObjectPropertyParameterTwiceAsync ( )
179
+ {
180
+ var value = new Product { Name = "test" } ;
181
+ await ( AssertTotalParametersAsync (
182
+ db . Products . Where ( o => o . Name == value . Name . Trim ( ) && o . Name != value . Name . Trim ( ) ) ,
183
+ 2 ) ) ;
184
+ }
185
+
186
+ [ Test ]
187
+ public async Task UsingStaticMethodObjectPropertyParameterTwiceAsync ( )
188
+ {
189
+ var value = new Product { Name = "test" } ;
190
+ await ( AssertTotalParametersAsync (
191
+ db . Products . Where ( o => o . Name == string . Copy ( value . Name ) && o . Name != string . Copy ( value . Name ) ) ,
192
+ 2 ) ) ;
193
+ }
194
+
195
+ [ Test ]
196
+ public async Task UsingObjectPropertyParameterWithSecondLevelClosureAsync ( )
197
+ {
198
+ var value = new Product { Name = "test" } ;
199
+ Expression < Func < Product , bool > > predicate = o => o . Name == value . Name && o . Name != value . Name ;
200
+ await ( AssertTotalParametersAsync (
201
+ db . Products . Where ( predicate ) ,
202
+ 1 ) ) ;
203
+ }
204
+
205
+ [ Test ]
206
+ public async Task UsingObjectPropertyParameterWithThirdLevelClosureAsync ( )
207
+ {
208
+ var value = new Product { Name = "test" } ;
209
+ Expression < Func < OrderLine , bool > > orderLinePredicate = o => o . Order . ShippedTo == value . Name && o . Order . ShippedTo != value . Name ;
210
+ Expression < Func < Product , bool > > predicate = o => o . Name == value . Name && o . OrderLines . AsQueryable ( ) . Any ( orderLinePredicate ) ;
211
+ await ( AssertTotalParametersAsync (
212
+ db . Products . Where ( predicate ) ,
213
+ 1 ) ) ;
214
+ }
215
+
119
216
private static async Task AssertTotalParametersAsync < T > ( IQueryable < T > query , int parameterNumber , CancellationToken cancellationToken = default ( CancellationToken ) )
120
217
{
121
218
using ( var sqlSpy = new SqlLogSpy ( ) )
0 commit comments