我有一个接口FakeItEasy - 具有界面假从抽象继承虽然二者有相同的接口继承
public interface IInterface { void DoSomething(); }
另一个接口
public interface IOtherInterface : IInterface { }
一个抽象类
public abstract class AbstractClass : IInterface
{
public void DoSomething()
{
Console.WriteLine("Got here");
}
}
我m写单元测试并假冒IOtherInterface。抽象类已经包含了我想用于单元测试的有用方法。我将如何让我的A.Fake<IOtherInterface>();
继承AbstractClass
?
这是我到目前为止尝试的,但它不起作用 - AbstractClass.DoSomething没有受到打击。
IOtherInterface fake = A.Fake<IOtherInterface>(builder => builder.Implements(typeof (AbstractClass)));
fake.DoSomething();
当然,如果我做出这样的代理:
var abstractFake = A.Fake<AbstractClass>();
A.CallTo(() => fake.DoSomething()).Invokes(abstractFake.DoSomething);
fake.DoSomething();
...事情的工作,因为我想要的。是否有内置的机制来实现这一目标,以便我不需要代理abstractFake
对象?
UPDATE
我需要IOtherInterface
,因为我需要的是IOtherInterface作为依赖客户端类:
class Consumer
{
public Consumer(IOtherInterface otherInterface)
{
otherInterface.DoSomething();
}
}
它的确如此,但'abstractFake'变量的类型是'AbstractClass'而不是'IOtherInterface'。我需要'IOtherInterface'。查看更新:) – 2015-02-24 14:40:15
感谢您提出这个问题。正如你从布莱尔康拉德的回答中看到的那样,结果提出了两个项目问题,这很好! – 2015-02-26 06:52:57
@AdamRalph我会诚实地说,它让我大开眼界,去看看布莱尔的职业活动,去创造那些你通常看不到的项目问题。通常,即使项目的合作者也会说“提交错误”。无论如何,我很高兴我有间接的贡献:) – 2015-02-26 14:27:42