开发者

Moq with constructor argument

开发者 https://www.devze.com 2023-04-10 17:22 出处:网络
I have a factory that looks like below: public IFoo GetFoo(IFile file开发者_Go百科) { return _kernel.Get<IFoo>(new ConstructorArgument(\"file\", file));

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

精彩评论

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

关注公众号