单元测试:在使用RIA服务时,如何抽象M来测试MVVM中的VM

时间:2022-08-24 21:55:40

Ok I'm having a crisis of conscience right now.

好吧,我现在正处于良心危机中。

I am having no luck in trying to abstract out RIA Services from our Silverlight application so we can do proper unit testing.

我没有运气试图从我们的Silverlight应用程序中抽象出RIA服务,因此我们可以进行适当的单元测试。

At this point we have a views and view models, and DomainContext is the Model. No matter how much we tried we cannot find anyway to abstract the DomainContext or the Entities so we can replace them with test data.

此时我们有视图和视图模型,而DomainContext是模型。无论我们尝试多少,我们都无法找到抽象DomainContext或实体,因此我们可以用测试数据替换它们。

What is the recommended strategies to unit test a view model that has a dependency on RIA Services?

对依赖于RIA服务的视图模型进行单元测试的推荐策略是什么?

1 个解决方案

#1


Did you see my blog post that demonstrated exactly this? Specifically it allows you to plug in a mock DomainClient underneath the DomainContext, that then allows you to unit test your view models using a DomainContext without a dependency on any server.

您是否看到我的博客文章正好证明了这一点?具体来说,它允许您在DomainContext下插入一个模拟DomainClient,然后允许您使用DomainContext对您的视图模型进行单元测试,而不依赖于任何服务器。

http://www.nikhilk.net/NET-RIA-Services-ViewModel-Pattern-2.aspx

#1


Did you see my blog post that demonstrated exactly this? Specifically it allows you to plug in a mock DomainClient underneath the DomainContext, that then allows you to unit test your view models using a DomainContext without a dependency on any server.

您是否看到我的博客文章正好证明了这一点?具体来说,它允许您在DomainContext下插入一个模拟DomainClient,然后允许您使用DomainContext对您的视图模型进行单元测试,而不依赖于任何服务器。

http://www.nikhilk.net/NET-RIA-Services-ViewModel-Pattern-2.aspx