开发者

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

  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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜