Why are all objects listing Rhino stub methods in

2019-07-15 07:11发布

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.

enter image description here

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

1条回答
Viruses.
2楼-- · 2019-07-15 07:56

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.

查看更多
登录 后发表回答