@@ -475,6 +475,39 @@ public void SetupResultAllowsProtectedMethodInBaseClass()
475475 Assert . Equal ( 5 , mock . Object . DoProtectedReturnGeneric < int > ( ) ) ;
476476 }
477477
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+
478511 [ Fact ]
479512 public void SetupResultDefaulTwoOverloadsWithDerivedClassThrowsInvalidOperationException ( )
480513 {
@@ -1041,7 +1074,7 @@ public void SetMatcherExpressionProperty(MethodCallExpression expression)
10411074 }
10421075
10431076 protected virtual LambdaExpression LambdaExpressionProperty { get ; set ; }
1044-
1077+
10451078 public void SetLambdaExpressionProperty ( LambdaExpression expression )
10461079 {
10471080 LambdaExpressionProperty = expression ;
@@ -1111,6 +1144,14 @@ public string DoTwoArgs(string arg, int arg1)
11111144 return this . TwoArgs ( arg , arg1 ) ;
11121145 }
11131146
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+
11141155 public string GetProtectedValue ( )
11151156 {
11161157 return this . ProtectedValue ;
@@ -1194,10 +1235,33 @@ protected virtual string TwoArgs(string arg, int arg1)
11941235 {
11951236 return arg ;
11961237 }
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 ( ) ;
11971246 }
11981247
11991248 public class FooDerived : FooBase
12001249 {
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 ) ;
12011265 }
12021266
12031267 public class MyBase { }
0 commit comments