为什么所有对象都在智能感知中列出了Rhino存根方法? [英] Why are all objects listing Rhino stub methods in intellisense?
问题描述
我注意到,有点烦人的是,每个对象(不是桩对象)都列出了所有常见的Rhino方法,例如Visual Studio中的AssertNeverCalled.这使得浏览属性/方法变得更加困难.
I noticed that slightly annoyingly, every object (not just stub objects) is listing all the common Rhino methods like AssertNeverCalled in Visual Studio. It makes browsing the properties/methods much harder.
这是Visual Studio(例如损坏的Intellisense DB)的错误还是Rhino Mocks的功能"?
Is this a bug with Visual Studio (corrupted Intellisense DB for instance) or a 'feature' of Rhino Mocks?
推荐答案
要回答您的问题,我需要将我的答案分配在split方法和asserts方法之间.
To answer your question I need to split my answer between the arrange and the asserts methods.
您在引用类型实例上遇到这些扩展方法的原因是因为VS IntelliSense仍然不支持过滤这些方法:
The reason you face those extension methods on reference types instances is because the VS IntelliSense doesn't support anyway to filter those methods:
public static IMethodOptions<object> Stub<T>(this T mock, Action<T> action) where T : class
如您在上面的stub
方法签名中所看到的,T
类型的唯一约束是; T
必须是引用类型.
As you can see in the above stub
method signeture, the only constrain on T
type is; T
must be a reference type.
这就是为什么IntelliSense在示例中不向您提供stub
方法的原因(DateTime
是struct ...)
This is the reason why the IntelliSense doesn't offer you the stub
methods in your example(DateTime
is struct...)
因此IntelliSense为您提供了对引用类型的安排方法的原因是:IntelliSense限制+ Rhinomocks设计(Moq通过.Object
属性解决了此问题).
So the reason the IntelliSense offers you the arrange methods on reference types is: IntelliSense limitation + Rhinomocks design(Moq solved this problem with the .Object
property).
为什么IntelliSense会针对非引用类型(您的示例...)提供asserts方法?
这是Rhinomocks的错误;基本上Rhinomocks不允许您生成非引用类型的对象,并且这些方法没有约束;
This is a Rhinomocks bug; Basiclly Rhinomocks doesn't allowed you to generate a non-reference type object and there is no constrain on those methods;
public static void AssertWasCalled<T>(this T mock, Action<T> action)
如上面的签名所示,T
没有任何约束,这是您遇到的不一致行为(错误...)的根源
As you can see in the above signeture there is no constrain on T
, this is the source of the inconsistency behavior(bug...) you've faced
asserts方法的引用类型应与ranging方法的约束完全相同.
The asserts methods should have the reference types constrain exactly as the arrange methods have.
这篇关于为什么所有对象都在智能感知中列出了Rhino存根方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!