NUnit 和 NMock- ExpectAndReturn - 如何告诉 NMock 期望 CreateObjectSet
我有以下
var objSet = new DynamicMock(typeof(IObjectSet<Nationality>));
objSet.ExpectAndReturn("GetAll", new List<Nationality>
{
new Nationality
{
//obj init here
},
new Nationality
{
//obj init here
}
}.AsQueryable());
工作得很好(我可以调用 blah.GetAll() 并得到预期的列表)。
我想做的(如果可能的话?)是告诉另一个 DynamicMock 期望具有以下签名的方法
obj.CreateObjectSet<RandomCustomType>()
,但我不确定如何包含/配置调用以期望 '
'。
I have the following
var objSet = new DynamicMock(typeof(IObjectSet<Nationality>));
objSet.ExpectAndReturn("GetAll", new List<Nationality>
{
new Nationality
{
//obj init here
},
new Nationality
{
//obj init here
}
}.AsQueryable());
which works just fine (I can call blah.GetAll() and I get the expected list back).
What I'd like to do (if possible?) is tell another DynamicMock to expect a method with the following signature
obj.CreateObjectSet<RandomCustomType>()
But I am unsure of how to include/configure the call to expect the '<Type>
'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定 NMock 1.x 不支持通用方法,它是不再支持。迁移到 NMock 以外的另一个模拟框架怎么样?NMock 具有类型化接口,并且不基于硬编码字符串?
在Rhino Mocks(例如)中,您可以按如下方式执行此操作(示例取自又一个 StackObverflow 问题):
I'm pretty sure NMock 1.x doesn't support Generic methods, and it's no longer supported. What about moving to another mocking framework other than NMock, which has typed interface, and not based on hardcoded strings?
In Rhino Mocks (for example) you could do this as follows (example taken from yet another StackObverflow question):