I just started using JustMock but I've searched for a solution to this problem and haven't found it yet so I'll pose the problem here.
As in the distilled example below, I have a class that inherits from another class. The parent class defines multiple protected virtual methods that the child class does not override. I'm interested in testing a specific protected virtual method the child does implement but my attempts to mock the non-overridden parent methods fail with the following exception:
[System.ArgumentException] = {"Could not resolve the target method; make sure that you have provided arguments correctly."}
(In the example, it is thrown on the call to Mock.NonPublic.Arrange(..) )
Am I doing something wrong? Is there a way within JustMock to get around this error? Or must I subclass my child class further and override all the methods I'm interested in mocking in order to get it to work? That last option does work, but it's not exactly ideal.
Any help is greatly appreciated!
Charles
As in the distilled example below, I have a class that inherits from another class. The parent class defines multiple protected virtual methods that the child class does not override. I'm interested in testing a specific protected virtual method the child does implement but my attempts to mock the non-overridden parent methods fail with the following exception:
[System.ArgumentException] = {"Could not resolve the target method; make sure that you have provided arguments correctly."}
(In the example, it is thrown on the call to Mock.NonPublic.Arrange(..) )
Am I doing something wrong? Is there a way within JustMock to get around this error? Or must I subclass my child class further and override all the methods I'm interested in mocking in order to get it to work? That last option does work, but it's not exactly ideal.
Any help is greatly appreciated!
Charles
public
class
Foo
{
public
Foo()
{
}
protected
virtual
void
MethodToMock()
{
}
protected
virtual
void
MethodToTest()
{
}
}
public
class
Bar : Foo
{
public
Bar()
{
}
protected
override
void
MethodToTest()
{
MethodToMock();
}
}
[TestMethod]
public
void
BarTest()
{
var mock = Mock.Create<Bar>(Behavior.CallOriginal);
Mock.NonPublic.Arrange(mock,
"MethodToMock"
).DoNothing();
// Test MethodToTest here
}