简体   繁体   English

silverlight5 nUnit测试类INotifyDataErrorInfo定义的程序集未找到

[英]silverlight5 nUnit test class INotifyDataErrorInfo defined assembly not found

Our application using silverlight 5 with MVVM design pattern and Telerik UI for silverlight. 我们的应用程序使用具有MVVM设计模式的silverlight 5和用于Silverlight的Telerik UI。
We try to right unit test for our View Models that are using INotifyDataErrorInfo interface. 我们尝试对使用INotifyDataErrorInfo接口的视图模型进行正确的单元测试。 But it raise Error, 但这会引发错误,

The type 'System.ComponentModel.INotifyDataErrorInfo' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

I implemented the INotify interface in our test class, 我在测试类中实现了INotify接口,

[TestFixture]
public class ViewModelTest : LabOra.Applications.View.ViewModelBase, INotifyPropertyChanged
{


    [Test]
    public void ContactVmTest()
    {
        var vm = new ContactsVM();
        // Console.WriteLine(vm.NumberOfRecords);
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

But still the same Error. 但是还是一样的错误。 What is the wrong ? 怎么了

You can't use normal class library project to test silverlight ViewModels their runtime are different. 您不能使用普通的类库项目来测试silverlight ViewModel,它们的运行时间是不同的。 Sometime you can succede but if you have any custom silverlight project reference it wont work. 有时您可以成功,但是如果您有任何自定义的Silverlight项目引用,它将无法正常工作。 You need silverlight application or class library project to test silverlight viewmodels. 您需要silverlight应用程序或类库项目来测试silverlight视图模型。

  1. Check your Test Project Template, Because you want to test Silverlight class library as your view models are in Silverlight library project, You need Silverlight class library application as your test project. 检查您的测试项目模板,因为您要测试Silverlight类库,因为视图模型位于Silverlight库项目中,因此需要Silverlight类库应用程序作为测试项目。
  2. Download Latest version of Silverlight toolkit. 下载最新版本的Silverlight工具包。 Within that toolkit you should have below dlls under path. 在该工具包中,路径下应位于dll下。

    C:\\Program Files (x86)\\Microsoft SDKs\\Silverlight\\v5.0\\Toolkit\\dec11\\Testing C:\\ Program Files(x86)\\ Microsoft SDKs \\ Silverlight \\ v5.0 \\ Toolkit \\ dec11 \\ Testing

  3. Microsoft.Silverlight.Testing.dll Microsoft.Silverlight.Testing.dll
  4. Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll

Add these two references to your silverlight project. 将这两个引用添加到您的silverlight项目。

Modify App.xaml.cs of the silverlight project (You are going to use for the test) as below 修改Silverlight项目的App.xaml.cs(将用于测试),如下所示

private void Application_Startup(object sender, StartupEventArgs e)
    {
        this.RootVisual = UnitTestSystem.CreateTestPage();

    }

Set the project as start up project and run. 将项目设置为启动项目并运行。

after googling plenty of times/days without any proper solution to my scenario. 在无数次/每天都谷歌搜索之后,没有针对我的情况的适当解决方案。 i found this site , he explains it in different different ways. 我找到了这个网站 ,他用不同的方式解释了它。 MS Unit, NUnit all the stuff with silverlight 5 unit testing. MS Unit,NUnit所有东西都与silverlight 5进行了单元测试。

To do unit testing on silverlight 5, MVVM app I used Silverlight Toolkit for silverlight 5 . 为了在Silverlight 5上进行单元测试,我使用MVVM应用程序将Silverlight Toolkit用于Silverlight 5 After installing it, in Visual studio 2012 you will not have silverlight test template as some examples on internet as describe even after installing silverlight toolkit. 安装后,在Visual Studio 2012中,即使安装了Silverlight工具包,也不会像Internet上的某些示例那样具有Silverlight测试模板。 I just create another silverlight 5 project into my existing project solution and create class and put Annotations. 我只是在现有的项目解决方案中创建另一个Silverlight 5项目,并创建类并放入注释。 To do this you need to add unit testing reference to your newly created project. 为此,您需要向新创建的项目添加单元测试参考。

[TestClass]
public class UnitTest
{
    [TestMethod]
    public void load()
    {
         Assert.IsTrue(true);
    }

}

Those are in, C:\\Program Files (x86)\\Microsoft SDKs\\Silverlight\\v5.0\\Toolkit\\dec11\\Testing folder,browse and add. 这些位于C:\\Program Files (x86)\\Microsoft SDKs\\Silverlight\\v5.0\\Toolkit\\dec11\\Testing文件夹中,浏览并添加。

change your test project App.xaml.cs startup event, 更改您的测试项目App.xaml.cs启动事件,

private void Application_Startup(object sender, StartupEventArgs e)
    {
        this.RootVisual = UnitTestSystem.CreateTestPage();
    }

Finally, in your original project (ProjectName.web), set it as start up project, if you didn't and set start page as your testing project page.( This link will help you ) 最后,在原始项目(ProjectName.web)中,将其设置为启动项目(如果没有),并将开始页面设置为测试项目页面。( 此链接将为您提供帮助

Also Thank you RAJ, for your guidance. 也感谢RAJ的指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM