简体   繁体   English

如何用Rhino Mocks模拟IDbSet

[英]How to mock IDbSet with Rhino Mocks

I can't get this working at all. 我根本无法正常工作。 I've got this code in my test: 我的测试中有以下代码:

MockRepository repository = new MockRepository();
IDbSet<SystemUser> userSet = repository.StrictMock<IDbSet<SystemUser>>();
Expect.Call(userSet.Any(u => u.Id == "UserName")).Return(true);
// More code follows

But it bombs out on the StrictMock line with the error: 但是它在StrictMock行上炸毁并显示错误:

System.TypeLoadException: Method 'Create' on type 'IDbSet`1Proxy1862178487664986a7bd03ad3b5c6f2c' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a621a9e7e5c32e69' tried to implicitly implement an interface method with weaker type parameter constraints System.TypeLoadException:从程序集'DynamicProxyGenAssembly2,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = a621a9e7e5c32e69'的类型'IDbSet'1Proxy1862178487664986a7bd03ad3b5c6f2c'上的方法'Create'试图隐式实现具有较弱类型参数约束的接口方法

Any ideas what this could be? 有什么想法吗?

Thanks! 谢谢!

You have encountered a known issue that Rhino.Mocks (version 3.6.0.0) has with generic method constraints. 您遇到了Rhino.Mocks(版本3.6.0.0)具有通用方法约束的已知问题。

The 'Create' method: “创建”方法:

TDerivedEntity Create<TDerivedEntity>() where TDerivedEntity : class, TEntity

is failing to be generated correctly because of the constraints where TDerivedEntity : class, TEntity . 由于where TDerivedEntity : class, TEntity的约束where TDerivedEntity : class, TEntity正确生成。

There is more information regarding the bug here : Can't get RhinoMocks to emit a mock that follows the generic type restriction rules 这里有关于该错误的更多信息: 无法使RhinoMocks发出遵循通用类型限制规则的模拟

Unfortunately, it looks like we are going to have to wait for the next version of Rhino.Mocks to address the issue. 不幸的是,看来我们将不得不等待下一个Rhino.Mocks版本才能解决此问题。

For those who are still looking for a solution for this problem. 对于那些仍在寻找解决方案的人。 rhino mocks 3.6.1 and later solves this issue. 犀牛模拟3.6.1和更高版本解决了此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM