How to mock a RIA service
Is t开发者_JAVA百科here any ability to mock methods that are provided with RIA Services?
I would like to test my Silverlight App without communication to the server side...
I see a following approach:
- create a separate interface;
- add it to "base classes" for my RiaService;
- define each autogenerated RIA-method in this interface;
- insert dependency so that my "functionality" will depend not from the RiaService, but from the interface that is implemented with RiaService.
But for this case I see a problem: how to keep my interface in the auto-generated files?
ANy thoughts are welcome.
A few relatively unrelated (to each other) thoughts...
- If the auto-generated files are partial classes, you could simply add another partial class to define that it implements an interface.
- You could use StructureMap to inject dependencies to Moq objects to do what you want.
- Use generics in an interesting way to allow you to use either the generated class or the mocked object. (probably not a good solution)
- Use reflection to work with the two different object types. (probably not a good option)
- Compile directives (#if DEBUG) to use the two different object types. (definitely not a good option)
Hope this either helps or inspires some good/better ideas!
精彩评论