如何嘲弄与犀牛模拟扩展方法? [英] How to mock extension methods with Rhino Mock?

查看:186
本文介绍了如何嘲弄与犀牛模拟扩展方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与我需要一些扩展方法扩展类型的IDataReader的对象。问题是现在,当我尝试嘲笑IDataReader的,不包括在模拟扩展的方法,这样当行 Expect.Call(reader.ExtensionMethod()),收益(someValue中)是达到 ExtensionMethod 执行这不是我想要的!我希望这一呼吁是创纪录的,当扩展方法是从别的地方调用我想它返回 someValue中

I have extended objects of type IDataReader with some extension methods that I needed. The problem is now when I try to mock the IDataReader, the extended method is not included in the mock so when the row Expect.Call(reader.ExtensionMethod()).Return(someValue) is reach the ExtensionMethod is executed which is not what I want! I want that call to be record and when the extension method is call from somewhere else I want it to return someValue.

有谁知道如何解决这个问题?

Does anyone know how to get around this?

推荐答案

答案似乎是没有的时刻。为了虽然不好,但我解决我的问题写一个模拟类为我的界面我想,而不是嘲笑。由于我没有需要的接口方法很多它去非常快。

The answer seems to be no at the moment. To bad though, but I solved my problem with writing a mock class for my interface I wanted to mock instead. Since I didn't needed that many methods of the interface it went pretty fast.

这篇关于如何嘲弄与犀牛模拟扩展方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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