开发者

Moq with constructor argument

I have a factory that looks like below:

public IFoo GetFoo(IFile file开发者_Go百科)
{
  return _kernel.Get<IFoo>(new ConstructorArgument("file", file));
}

It works fine until I use Moq to mock IFoo. In the mock there is no constructor argument named file, and I get a Ninject.ActivationException.

How should I solve this?


You should be mocking your factory during testing. Hopefully, the "GetFoo" method is part of your factory interface. Mock the factory and then you can set up the factory to return whatever IFoo you want (a test IFoo or perhaps a mock IFoo).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜