views:

134

answers:

1

Is there 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.

+2  A: 

A few relatively unrelated (to each other) thoughts...

  1. If the auto-generated files are partial classes, you could simply add another partial class to define that it implements an interface.
  2. You could use StructureMap to inject dependencies to Moq objects to do what you want.
  3. Use generics in an interesting way to allow you to use either the generated class or the mocked object. (probably not a good solution)
  4. Use reflection to work with the two different object types. (probably not a good option)
  5. 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!

Jaxidian
Some additional links that might help: http://www.nikhilk.net/NET-RIA-Services-ViewModel-Pattern-2.aspx http://forums.silverlight.net/forums/p/110292/249721.aspx
Jaxidian