@@ -475,6 +475,39 @@ public void SetupResultAllowsProtectedMethodInBaseClass()
475
475
Assert . Equal ( 5 , mock . Object . DoProtectedReturnGeneric < int > ( ) ) ;
476
476
}
477
477
478
+ [ Fact ]
479
+ public void SetupResultAllowsHiddenVirtualMethods ( )
480
+ {
481
+ var mock = new Mock < FooDerived > ( ) ;
482
+ mock . Protected ( )
483
+ . Setup < int > ( "ProtectedHiddenInt" )
484
+ . Returns ( 5 ) ;
485
+
486
+ Assert . Equal ( 5 , mock . Object . DoProtectedHiddenInt ( ) ) ;
487
+ Assert . Equal ( 2 , ( ( FooBase ) mock . Object ) . DoProtectedHiddenInt ( ) ) ;
488
+
489
+ mock . Protected ( )
490
+ . Setup < int > ( "ProtectedHiddenWithGenericParam" , new [ ] { typeof ( int ) } , false )
491
+ . Returns ( 5 ) ;
492
+ Assert . Equal ( 5 , mock . Object . DoProtectedHiddenWithGenericParam < int > ( ) ) ;
493
+
494
+ mock . Protected ( )
495
+ . Setup < int > ( "ProtectedHiddenSum" , genericTypeArguments : Array . Empty < Type > ( ) , exactParameterMatch : true , 1 , 2 )
496
+ . Returns ( 3 ) ;
497
+
498
+ Assert . Equal ( 3 , mock . Object . DoProtectedHiddenSum ( 1 , 2 ) ) ;
499
+
500
+ mock . Protected ( )
501
+ . Setup < int > ( "ProtectedHiddenSum" , genericTypeArguments : Array . Empty < Type > ( ) , exactParameterMatch : true , 1 , 2 , 3 )
502
+ . Returns ( 6 ) ;
503
+ Assert . Equal ( 6 , mock . Object . DoProtectedHiddenSum ( 1 , 2 , 3 ) ) ;
504
+
505
+ mock . Protected ( )
506
+ . Setup < int > ( "ProtectedHiddenSum" , genericTypeArguments : Array . Empty < Type > ( ) , exactParameterMatch : true , 1 , 2 , 3 , 4 )
507
+ . Returns ( 10 ) ;
508
+ Assert . Equal ( 10 , mock . Object . DoProtectedHiddenSum ( 1 , 2 , 3 , 4 ) ) ;
509
+ }
510
+
478
511
[ Fact ]
479
512
public void SetupResultDefaulTwoOverloadsWithDerivedClassThrowsInvalidOperationException ( )
480
513
{
@@ -1041,7 +1074,7 @@ public void SetMatcherExpressionProperty(MethodCallExpression expression)
1041
1074
}
1042
1075
1043
1076
protected virtual LambdaExpression LambdaExpressionProperty { get ; set ; }
1044
-
1077
+
1045
1078
public void SetLambdaExpressionProperty ( LambdaExpression expression )
1046
1079
{
1047
1080
LambdaExpressionProperty = expression ;
@@ -1111,6 +1144,14 @@ public string DoTwoArgs(string arg, int arg1)
1111
1144
return this . TwoArgs ( arg , arg1 ) ;
1112
1145
}
1113
1146
1147
+ public int DoProtectedHiddenInt ( ) => this . ProtectedHiddenInt ( ) ;
1148
+
1149
+ public T DoProtectedHiddenWithGenericParam < T > ( ) => this . ProtectedHiddenWithGenericParam < T > ( ) ;
1150
+
1151
+ public int DoProtectedHiddenSum ( int op1 , int op2 ) => this . ProtectedHiddenSum ( op1 , op2 ) ;
1152
+
1153
+ public int DoProtectedHiddenSum ( int op1 , int op2 , int op3 ) => this . ProtectedHiddenSum ( op1 , op2 , op3 ) ;
1154
+
1114
1155
public string GetProtectedValue ( )
1115
1156
{
1116
1157
return this . ProtectedValue ;
@@ -1194,10 +1235,33 @@ protected virtual string TwoArgs(string arg, int arg1)
1194
1235
{
1195
1236
return arg ;
1196
1237
}
1238
+
1239
+ protected virtual int ProtectedHiddenInt ( ) => 2 ;
1240
+
1241
+ protected virtual T ProtectedHiddenWithGenericParam < T > ( ) => default ( T ) ;
1242
+
1243
+ protected new virtual int ProtectedHiddenSum ( int op1 , int op2 ) => throw new NotImplementedException ( ) ;
1244
+
1245
+ protected new virtual int ProtectedHiddenSum ( int op1 , int op2 , int op3 ) => throw new NotImplementedException ( ) ;
1197
1246
}
1198
1247
1199
1248
public class FooDerived : FooBase
1200
1249
{
1250
+ protected new virtual int ProtectedHiddenInt ( ) => 22 ;
1251
+
1252
+ protected new virtual T ProtectedHiddenWithGenericParam < T > ( ) => default ( T ) ;
1253
+
1254
+ protected new virtual int ProtectedHiddenSum ( int op1 , int op2 ) => throw new NotImplementedException ( ) ;
1255
+
1256
+ protected virtual int ProtectedHiddenSum ( int op1 , int op2 , int op3 , int op4 ) => throw new NotImplementedException ( ) ;
1257
+
1258
+ public new int DoProtectedHiddenInt ( ) => this . ProtectedHiddenInt ( ) ;
1259
+
1260
+ public new T DoProtectedHiddenWithGenericParam < T > ( ) => this . ProtectedHiddenWithGenericParam < T > ( ) ;
1261
+
1262
+ public new int DoProtectedHiddenSum ( int op1 , int op2 ) => this . ProtectedHiddenSum ( op1 , op2 ) ;
1263
+
1264
+ public int DoProtectedHiddenSum ( int op1 , int op2 , int op3 , int op4 ) => this . ProtectedHiddenSum ( op1 , op2 , op3 , op4 ) ;
1201
1265
}
1202
1266
1203
1267
public class MyBase { }
0 commit comments