开发者

Mocking help?I can't find what's the problem

开发者 https://www.devze.com 2022-12-20 16:16 出处:网络
I have an interface definded like this: public interface IDatabase{ void Get<TTypeToFetch> ();} and when I try to do:

I have an interface definded like this:

public interface IDatabase{ void Get<TTypeToFetch> ();}

and when I try to do: Mockery mocke开发者_开发技巧ry = new Mockery(); IDatabase db = mockery.NewMock<IDatabase>(); I get the following error:

System.TypeLoadException: System.TypeLoadException: Signature of the body and declaration in a method implementation do not match

What is wrong? (I am using Visual Studio 2008 with nmock2) Please could everyone give me an answer, I have to finish this soon. Thanks, Luisa


I think this may be a problem with NMock, possibly even a bug. The type IDatabase is not generic, so when you invoke Get<T>, different Ts could be used at runtime. But when NMock is generating the mock, it doesn't appear to understand that this is the case, and kablammo -- each method signature is different, depending on the type parameter supplied.

Try doing this instead:

public interface IDatabase<T> {
  void Get<T>();
}

Also, shouldn't the type of Get be T, not void?


I had the same exception with my own interface. When i change interface to be public everything runs ok.

0

精彩评论

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

关注公众号