Faking Private Overloaded Methods
You can specify, which overloaded method must be faked by calling WithArgumentTypes() and passing all arguments types into it.
Syntax
C# Isolate.NonPublic.WhenCalled(() => <method>).WithArgumentTypes(<Args_list>).<behavior>;
VB
Isolate.NonPublic.WhenCalled(Function() <method>).WithArgumentTypes(<Args_list>).<behavior>
Samples
Sample 1: Static methods
C# // Use this line to set expectation on PrivateStaticMethod() Isolate.NonPublic.WhenCalled<Dependency>("PrivateStaticMethod").WithArgumentTypes(new Type[0]).WillReturn(10); // Use this line to set expectation on PrivateStaticMethod(int) Isolate.NonPublic.WhenCalled<Dependency>("PrivateStaticMethod").WithArgumentTypes(typeof(int)).WillReturn(10); // Use this line to set expectation on PrivateStaticMethod(string, int) Isolate.NonPublic.WhenCalled<Dependency>("PrivateStaticMethod").WithArgumentTypes(typeof(string), typeof(int)).WillReturn(10);
VB
'Use this line to set expectation on PrivateStaticMethod()
Isolate.NonPublic.WhenCalled(Of Dependency)("PrivateStaticMethod").WithArgumentTypes(new Type(){}).WillReturn(10)
'Use this line to set expectation on PrivateStaticMethod(Integer)
Isolate.NonPublic.WhenCalled(Of Dependency)("PrivateStaticMethod").WithArgumentTypes(GetType(Integer)).WillReturn(10)
'Use this line to set expectation on PrivateStaticMethod(String, Integer)
Isolate.NonPublic.WhenCalled(Of Dependency)("PrivateStaticMethod").WithArgumentTypes(GetType(String), GetType(Integer)).WillReturn(10)
Sample 2: Instance methods
C# // Use these lines to set expectation on PrivateMethod() var fakeDependency = Isolate.Fake.Instance<Dependency>(Members.CallOriginal); Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithArgumentTypes(new Type[0]).WillReturn(10); // Use these lines to set expectation on PrivateMethod(int) var fakeDependency = Isolate.Fake.Instance<Dependency>(Members.CallOriginal); Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithArgumentTypes(typeof(int)).WillReturn(10); // Use these lines to set expectation on PrivateMethod(string, int) var fakeDependency = Isolate.Fake.Instance<Dependency>(Members.CallOriginal); Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithArgumentTypes(typeof(string), typeof(int)).WillReturn(10);
VB
'Use these lines to set expectation on PrivateMethod()
Dim fakeDependency = Isolate.Fake.Instance(Of Dependency)(Members.CallOriginal)
Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithArgumentTypes(new Type(){}).WillReturn(10)
'Use these lines to set expectation on PrivateMethod(Integer)
Dim fakeDependency = Isolate.Fake.Instance(Of Dependency)(Members.CallOriginal)
Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithArgumentTypes(GetType(Integer)).WillReturn(10)
'Use these lines to set expectation on PrivateMethod(String, Integer)
Dim fakeDependency = Isolate.Fake.Instance(Of Dependency)(Members.CallOriginal)
Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithArgumentTypes(GetType(String), GetType(Integer)).WillReturn(10)
Sample 3: Using WithArgumentTypes() and WithGenericTypes() together
C# // Use these lines to set expectation on PrivateMethod()<string> var fakeDependency = Isolate.Fake.Instance<Dependency>(Members.CallOriginal); Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithGenericArguments(typeof(string)).WithArgumentTypes(new Type[0]).WillReturn(10); // Use these lines to set expectation on PrivateMethod(int)<int, string> var fakeDependency = Isolate.Fake.Instance<Dependency>(Members.CallOriginal); Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithGenericArguments(typeof(int), typeof(string)).WithArgumentTypes(typeof(int)).WillReturn(10); // Use these lines to set expectation on PrivateMethod(string, int)<string, int, int> var fakeDependency = Isolate.Fake.Instance<Dependency>(Members.CallOriginal); Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithGenericArguments(typeof(string), typeof(int), typeof(int)).WithArgumentTypes(typeof(string), typeof(int)).WillReturn(10);
VB
'Use these lines to set expectation on PrivateMethod(Of String)()
Dim fakeDependency = Isolate.Fake.Instance(Of Dependency)(Members.CallOriginal)
Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithGenericArguments(GetType(String)).WithArgumentTypes(new Type(){}).WillReturn(10)
'Use these lines to set expectation on PrivateMethod(Of Integer, Of String)(Integer)
Dim fakeDependency = Isolate.Fake.Instance(Of Dependency)(Members.CallOriginal)
Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithGenericArguments(GetType(Integer), GetType(String)).WithArgumentTypes(GetType(Integer)).WillReturn(10)
'Use these lines to set expectation on PrivateMethod(Of String, Of Integer, Of Integer)(String, Integer)
Dim fakeDependency = Isolate.Fake.Instance(Of Dependency)(Members.CallOriginal)
Isolate.NonPublic.WhenCalled(fakeDependency, "PrivateMethod").WithGenericArguments(GetType(String), GetType(Integer), GetType(Integer)).WithArgumentTypes(GetType(String), GetType(Integer)).WillReturn(10)