如何用Rhino Mocks模拟IDbSet [英] How to mock IDbSet with Rhino Mocks

查看:102
本文介绍了如何用Rhino Mocks模拟IDbSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根本无法正常工作。我在测试中得到了以下代码:

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

但是它在上轰炸StrictMock 行,出现错误:

But it bombs out on the StrictMock line with the error:


System.TypeLoadException:方法'Create'on type
'来自程序集
'DynamicProxyGenAssembly2,Version = 0.0.0.0,Culture = neutral,
PublicKeyToken = a621a9e7e5c32e69的IDbSet`1Proxy1862178487664986a7bd03ad3b5c6f2c'试图隐式实现具有较弱类型参数约束的
接口方法

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

有什么想法吗?

谢谢!

推荐答案

您遇到了Rhino.Mocks(版本3.6.0.0)在通用方法约束下存在的已知问题。

You have encountered a known issue that Rhino.Mocks (version 3.6.0.0) has with generic method constraints.

'Create'方法:

The 'Create' method:

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

由于约束而无法正确生成,其中TDeriv edEntity:类,TEntity

此处有关于此错误的更多信息:无法让RhinoMocks发出遵循通用类型限制规则的模拟

There is more information regarding the bug here : Can't get RhinoMocks to emit a mock that follows the generic type restriction rules

不幸的是,看来我们将不得不等待下一个Rhino.Mocks版本来解决此问题。

Unfortunately, it looks like we are going to have to wait for the next version of Rhino.Mocks to address the issue.

这篇关于如何用Rhino Mocks模拟IDbSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆