Intellitest mocking issue

580 Views Asked by At

I have a situation like this right now. On the below code I am running visual studio Intellitest, However I am able to mock the classes A and B using fake assembly and able to run the explorations. But when it comes to the constructor of B class where PEX is trying to instantiate a Concrete class on the constructor level class B and subsequently trying to invoke a function(ie _c.CMethod()). In this scenario Pex is throwing run time warning "unable to instrument the methods" and aborting the code exploration by leaving code coverage to minimum. I am following this article for mocking complex objects.

Sample code

public class A
{
    private readonly IB _IB;
    public A(IB IntfB)
    {
        _IB = IntfB;
    }

    public void Amethod()
    {
        _IB.CallingBMethod();
    }
}

public class B
{
    public B()
    {
        C _c = new C();
        _c.CMethod();
    }

    public string CallingBMethod()
    {
        return "Return from BMethod";
    }
}

public interface IB
{
    string CallingBMethod();
}

    enter code here

public class C
{
    public string CMethod()
    {
        return "Return from CMethod";
    }
}
0

There are 0 best solutions below