I've been learning about DynamicObject
in .NET 4.0 and was wondering if this type wou开发者_开发技巧ld be well suited to creating mock objects.
Mocking seems like a great way to use DynamicObject
, but am I missing something?
- Are there any mocking frameworks that use
DynamicObject
(as opposed to dynamic proxies or interception) for mocking? - Are there any disadvantages to using
DyanmicObject
for mocking (besides requiring the .NET 4.0 CLR)?
The biggest drawback that I can think of is that you can call literally any method/property in the world on a dynamic types.
for example, think of the hell it would be to update your tests if your api changed - you tests would still all compile, however they would all die with runtime errors if they tried to exercise the renamed/removed methods.
This, combined with the fact that you lose all Intellisense when operating on dynamic objects leads me to believe that a dynamic-based mocking library would be more difficult to use that something proxy-based like Rhino.
精彩评论