如何测试使用System.ServiceModel的Windows Phone类库

时间:2013-06-17 11:47:29

标签: unit-testing assemblies windows-phone filenotfoundexception

我有一个Windows Phone 8类库。在该类库中,我使用了System.ServiceModel。从Windows Phone 8应用程序使用时,类库运行正常。

我有一个单元测试项目。如果我尝试使用单元测试项目来测试类库中的方法,我会得到一个FileNotFoundExcaption:

{"Could not load file or assembly 'System.ServiceModel, 
Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 
or one of its dependencies. The system cannot find the file 
specified.":"System.ServiceModel, Version=2.0.5.0, Culture=neutral, 
PublicKeyToken=31bf3856ad364e35"}

我尝试过使用绑定重定向,但是因为两个System.Service模型程序集有不同的publicKeyTokens似乎不起作用。

这可能吗?

完整的融合日志是:

=== Pre-bind state information ===
LOG: User = MACHINENAME\Simon
LOG: DisplayName = System.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : PhoneClassLibraryReferenceTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel.EXE.
LOG: Attempting download of new URL file:///c:/[...]/PhoneClassLibraryReferenceTest/PhoneClassLibraryTest/bin/Debug/System.ServiceModel/System.ServiceModel.EXE.

1 个答案:

答案 0 :(得分:1)

解决方案是安装Visual Studio 2012更新2,并使用Windows Phone 8测试项目。

这样,您的测试将通过模拟器运行,并以System.ServiceModel程序集的正确版本为目标。

This blog post describes how to get going with Windows Phone 8 unit test projects