11using System . Reflection ;
22using NSubstitute . Core ;
33using NSubstitute . Core . Arguments ;
4+ using NSubstitute . Exceptions ;
45
56// Disable nullability for client API, so it does not affect clients.
67#nullable disable annotations
@@ -17,11 +18,11 @@ public static class ProtectedExtensions
1718 /// <param name="methodName">Name of the method.</param>
1819 /// <param name="args">The method arguments.</param>
1920 /// <returns>Result object from the method invocation.</returns>
20- /// <exception cref="System.ArgumentNullException ">Substitute - Cannot mock null object</exception>
21+ /// <exception cref="NSubstitute.Exceptions.NullSubstituteReferenceException ">Substitute - Cannot mock null object</exception>
2122 /// <exception cref="System.ArgumentException">Must provide valid protected method name to mock - methodName</exception>
2223 public static object Protected < T > ( this T obj , string methodName , params object [ ] args ) where T : class
2324 {
24- if ( obj == null ) { throw new ArgumentNullException ( nameof ( obj ) , "Cannot mock null object" ) ; }
25+ if ( obj == null ) { throw new NullSubstituteReferenceException ( ) ; }
2526 if ( string . IsNullOrWhiteSpace ( methodName ) ) { throw new ArgumentException ( "Must provide valid protected method name to mock" , nameof ( methodName ) ) ; }
2627
2728 IList < IArgumentSpecification > argTypes = SubstitutionContext . Current . ThreadContext . PeekAllArgumentSpecifications ( ) ;
@@ -41,11 +42,11 @@ public static object Protected<T>(this T obj, string methodName, params object[]
4142 /// <param name="methodName">Name of the method.</param>
4243 /// <param name="args">The method arguments.</param>
4344 /// <returns>WhenCalled<T>.</returns>
44- /// <exception cref="System.ArgumentNullException ">Substitute - Cannot mock null object</exception>
45+ /// <exception cref="NSubstitute.Exceptions.NullSubstituteReferenceException ">Substitute - Cannot mock null object</exception>
4546 /// <exception cref="System.ArgumentException">Must provide valid protected method name to mock - methodName</exception>
4647 public static WhenCalled < T > When < T > ( this T obj , string methodName , params object [ ] args ) where T : class
4748 {
48- if ( obj == null ) { throw new ArgumentNullException ( nameof ( obj ) , "Cannot mock null object" ) ; }
49+ if ( obj == null ) { throw new NullSubstituteReferenceException ( ) ; }
4950 if ( string . IsNullOrWhiteSpace ( methodName ) ) { throw new ArgumentException ( "Must provide valid protected method name to mock" , nameof ( methodName ) ) ; }
5051
5152 IList < IArgumentSpecification > argTypes = SubstitutionContext . Current . ThreadContext . PeekAllArgumentSpecifications ( ) ;
0 commit comments