Why are all objects listing Rhino stub methods in intellisense?

假如想象 提交于 2019-12-13 16:24:56

问题


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.

Is this a bug with Visual Studio (corrupted Intellisense DB for instance) or a 'feature' of Rhino Mocks?


回答1:


To answer your question I need to split my answer between the arrange and the asserts methods.

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

As you can see in the above stub method signeture, the only constrain on T type is; T must be a reference type.

This is the reason why the IntelliSense doesn't offer you the stub methods in your example(DateTime is struct...)

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).

Why does the IntelliSense offer the asserts methods on non reference types(Your exemple...)?

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)

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

The asserts methods should have the reference types constrain exactly as the arrange methods have.



来源:https://stackoverflow.com/questions/37348531/why-are-all-objects-listing-rhino-stub-methods-in-intellisense

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!