chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi,
I tried to invoke a private method with parameter having value null using Arrange-Act-Assert style, but Typemock throws an expection; so I couldn't achieve my aim.
Here is my sample class:
public Class1
{
private int value;

private void MyPrivateMethod(bool? boolValue)
{
if(boolValue.HasValue)
{
if(boolValue.Value)
{
value = 1;
}
else
{
value = -1;
}
}
else
{
value = 0;
}
}
}

----------------------------------------------------------------------
Test code:

Class1 c1= new Class1();
Isolate.Invoke.Method(c1, "MyPrivateMethod", null);

-----------------------------------------------------------------------
I tried to make a mock instance of Class1 and invoke method on it, but I again received an exception. Please lead me in a way to achieve this.
Thanks.
asked by mkg (4.3k points)

1 Answer

0 votes
Hi,

This is actually a bug :(
It happens when you pass null as a value to the invoked method.
We will fixed it and I'll update you as soon as it is fixed.
Please note that even after the fix there might be some restrictions on invoking private methods with overloads.
Consider the example:
public class SomeArgType1
{}

public class SomeArgType2
{}

public class Foo
{
    private void Bar(SomeArgType1 arg)
    {}

    private void Bar(SomeArgType2 arg)
    {}
}

// test code
Foo foo = new Foo();
Isolate.Invoke.Method(foo, "Bar", null)


In the example above Isolator will not be able to decide which overload of Bar you want to call unless you'll send a non null instance as an argument.
answered by ohad (35.4k points)
...