1
1
using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Diagnostics ;
2
4
using System . Data ;
3
5
using System . Linq ;
6
+ using System . Reflection ;
4
7
using System . Text ;
5
8
using NHibernate . Dialect ;
6
9
using NHibernate . Driver ;
@@ -370,14 +373,14 @@ public void AnyObject()
370
373
}
371
374
372
375
// Failing case till NH-3850 is fixed
373
- [ Test ]
376
+ [ Test , Ignore ( "Won't fix: requires reshaping the query" ) ]
374
377
public void AverageBBase ( )
375
378
{
376
379
Average < DomainClassBExtendedByA > ( 1.5m ) ;
377
380
}
378
381
379
382
// Non-reg case
380
- [ Test ]
383
+ [ Test , Ignore ( "Accidentally works: requires reshaping the query for being reliable" ) ]
381
384
public void AverageCBase ( )
382
385
{
383
386
Average < DomainClassCExtendedByD > ( 1.5m ) ;
@@ -398,7 +401,7 @@ public void AverageF()
398
401
}
399
402
400
403
// Failing case till NH-3850 is fixed
401
- [ Test ]
404
+ [ Test , Ignore ( "Won't fix: requires reshaping the query" ) ]
402
405
public void AverageGBase ( )
403
406
{
404
407
Average < DomainClassGExtendedByH > ( 2.5m ) ;
@@ -421,7 +424,7 @@ private void Average<DC>(decimal? expectedResult) where DC : DomainClassBase
421
424
}
422
425
423
426
// Failing case till NH-3850 is fixed
424
- [ Test ]
427
+ [ Test , Ignore ( "Won't fix: requires reshaping the query" ) ]
425
428
public void AverageObject ( )
426
429
{
427
430
using ( var session = OpenSession ( ) )
@@ -1133,7 +1136,7 @@ public void SumE()
1133
1136
}
1134
1137
1135
1138
// Non-reg case
1136
- [ Test ]
1139
+ [ Test , Ignore ( "Candidate potential breaking changes: Sum would now yield 0 instead of null on empty result sets." ) ]
1137
1140
public void SumF ( )
1138
1141
{
1139
1142
Sum < DomainClassF > ( null ) ;
@@ -1181,5 +1184,69 @@ private void Sum<DC>(int? expectedResult) where DC : DomainClassBase
1181
1184
Assert . AreEqual ( expectedResult . Value , dbl . Value , 0.001d ) ;
1182
1185
}
1183
1186
}
1187
+
1188
+ [ Test ]
1189
+ public void BadOverload ( )
1190
+ {
1191
+ var sumMethodTemplate = ReflectionHelper . GetMethod ( ( ) => Queryable . Sum ( ( IQueryable < int > ) null ) ) ;
1192
+ Assert . Throws < InvalidOperationException > ( ( ) =>
1193
+ {
1194
+ ReflectionHelper . GetMethodOverload ( sumMethodTemplate , new [ ] { typeof ( object ) } ) ;
1195
+ } ) ;
1196
+ }
1197
+
1198
+ [ Test , Explicit ( "Just a blunt perf comparison among some candidate overload reflection patterns, one being required for NH-3850" ) ]
1199
+ public void OverloadReflectionBluntPerfCompare ( )
1200
+ {
1201
+ var sumMethodTemplate = ReflectionHelper . GetMethod ( ( ) => Queryable . Sum ( ( IQueryable < int > ) null ) ) ;
1202
+
1203
+ var swNoSameParamsCheck = new Stopwatch ( ) ;
1204
+ swNoSameParamsCheck . Start ( ) ;
1205
+ for ( var i = 0 ; i < 1000 ; i ++ )
1206
+ {
1207
+ var sumMethod = sumMethodTemplate . DeclaringType . GetMethod ( sumMethodTemplate . Name ,
1208
+ ( sumMethodTemplate . IsStatic ? BindingFlags . Static : BindingFlags . Instance ) | BindingFlags . Public ,
1209
+ null , new [ ] { typeof ( IQueryable < decimal > ) } , null ) ;
1210
+ Trace . TraceInformation ( sumMethod . ToString ( ) ) ;
1211
+ }
1212
+ swNoSameParamsCheck . Stop ( ) ;
1213
+
1214
+ var swCurrentChoiceSameType = new Stopwatch ( ) ;
1215
+ swCurrentChoiceSameType . Start ( ) ;
1216
+ for ( var i = 0 ; i < 1000 ; i ++ )
1217
+ {
1218
+ var sumMethod = ReflectionHelper . GetMethodOverload ( sumMethodTemplate , new [ ] { typeof ( IQueryable < int > ) } ) ;
1219
+ Trace . TraceInformation ( sumMethod . ToString ( ) ) ;
1220
+ }
1221
+ swCurrentChoiceSameType . Stop ( ) ;
1222
+
1223
+ var swCurrentChoice = new Stopwatch ( ) ;
1224
+ swCurrentChoice . Start ( ) ;
1225
+ for ( var i = 0 ; i < 1000 ; i ++ )
1226
+ {
1227
+ var sumMethod = ReflectionHelper . GetMethodOverload ( sumMethodTemplate , new [ ] { typeof ( IQueryable < long > ) } ) ;
1228
+ Trace . TraceInformation ( sumMethod . ToString ( ) ) ;
1229
+ }
1230
+ swCurrentChoice . Stop ( ) ;
1231
+
1232
+ var swEnHlp = new Stopwatch ( ) ;
1233
+ swEnHlp . Start ( ) ;
1234
+ for ( var i = 0 ; i < 1000 ; i ++ )
1235
+ {
1236
+ // Testing the obsolete helper perf. Disable obsolete warning. Remove this swEnHlp part of the test if this helper is to be removed.
1237
+ #pragma warning disable 0618
1238
+ var sumMethod = EnumerableHelper . GetMethod ( "Sum" , new [ ] { typeof ( IEnumerable < int > ) } ) ;
1239
+ #pragma warning restore 0618
1240
+ Trace . TraceInformation ( sumMethod . ToString ( ) ) ;
1241
+ }
1242
+ swEnHlp . Stop ( ) ;
1243
+
1244
+ Assert . Pass ( @"Blunt perf timings:
1245
+ Direct reflection: {0}
1246
+ Current impl, same overload: {1}
1247
+ Current impl, other overload: {2}
1248
+ EnumerableHelper.GetMethod(non generic overload): {3}" ,
1249
+ swNoSameParamsCheck . Elapsed , swCurrentChoiceSameType . Elapsed , swCurrentChoice . Elapsed , swEnHlp . Elapsed ) ;
1250
+ }
1184
1251
}
1185
1252
}
0 commit comments