mardi 24 février 2015

FakeItEasy - Having an interface fake inherit from abstract while both share same interface inheritance

I have an interface



public interface IInterface { void DoSomething(); }


Another interface



public interface IOtherInterface : IInterface { }


An abstract class



public abstract class AbstractClass : IInterface
{
public void DoSomething()
{
Console.WriteLine("Got here");
}
}


I'm writing a unit test and fake IOtherInterface. The abstract class already contains helpful methods I'd want to leverage for my unit test. How would I make my A.Fake<IOtherInterface>(); inherit from AbstractClass?


This is what I've tried so far but it doesn't work - AbstractClass.DoSomething does not get hit.



IOtherInterface fake = A.Fake<IOtherInterface>(builder => builder.Implements(typeof (AbstractClass)));

fake.DoSomething();


Of course if I make a proxy like:



var abstractFake = A.Fake<AbstractClass>();
A.CallTo(() => fake.DoSomething()).Invokes(abstractFake.DoSomething);

fake.DoSomething();


... things work as I wanted. Is there a built in mechanism to achieve this so that I don't need that proxy abstractFake object?


Aucun commentaire:

Enregistrer un commentaire