Hi,
I have a class which implements two different interfaces.
There is a second class which receives an object of the previous class and performs a cast to one
of the interfaces implemented by the class.
In my tests I've mocked an object of TypeA and called the method on TestB using my mocked object as parameter.
Inside the method there is a cast to ITypeB but this cast returns an object with all its members set to null, so the TestB.Methdod() throws an exception.
Maybe this simple code will clarify the case:
public interface ITypeA
{
public int attributeA{get;}
}
public interface ITypeB;
{
public int attributeB{get;}
}
public class TestA: ITypeA,ITypeB
{
.... methods & attributes
}
public class TestB
{
public void Method(TestA objA)
{
ITypeB b = objA as ITypeB);
int value = b.attributeB; // This throws an exception.
}
}
And the code used to test:
TestA fakeTestA = Isolate.Fake.Instance<TestA>();
Isolate.WhenCalled(() => fakeTestA.attributeA).WillReturn(1);
Isolate.WhenCalled(() => fakeTestA.attributeB).WillReturn(2);
TestB realTestB = new TestB();
realTestB.Method(fakeTestA);
Thanks in advance,