2012-02-14 89 views
4

我試圖單元測試一些我的課,並具有在那裏運行測試單獨運作時間的精細100%有問題,但如果我在批量運行它們/使用「所有測試解決方案」選項中我的文件每一個單一測試失敗,出現錯誤:單元測試經過精磨,FileLoadException如果運行「在解決所有測試」

System.IO.FileLoadException was unhandled by user code 
    Message=Could not load file or assembly 'Microsoft.Practices.Prism, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
    Source=ServicesModuleTests 
    FileName=Microsoft.Practices.Prism, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null 

我一直在試圖找出爲什麼長期時間和嘗試在線搜索,但沒有發現任何人有這個相同的問題。

這裏是我的代碼一個簡單的例子:

RegistryService文件:

public class RegistryService 
{ 
    protected ILoggerFacadeExtended _Logger { get; set; } 
    protected IConnectivityService _Connectivity { get; set; } 

    [ImportingConstructor] 
    public RegistryService(ILoggerFacadeExtended logger, IConnectivityService connectivity) 
    { 
     this._Logger = logger; 
     this._Connectivity = connectivity; 
    } 

    public string GetRegistryPath(RegistryHive hive, string path) 
    { 
     string registryPath = string.Format("{0}\\{1}", GetRegistryHiveString(hive), path.Trim('\\')); 
     _Logger.DebugWithFormat("Found registry path: {0}", registryPath); 
     return registryPath; 
    } 

    private string GetRegistryHiveString(RegistryHive hive) 
    { 
     switch (hive) 
     { 
      case RegistryHive.ClassesRoot: 
       return "HKEY_CLASSES_ROOT"; 
      case RegistryHive.CurrentConfig: 
       return "HKEY_CURRENT_CONFIG"; 
      case RegistryHive.CurrentUser: 
       return "HKEY_CURRENT_USER"; 
      case RegistryHive.DynData: 
       return "HKEY_DYN_DATA"; 
      case RegistryHive.LocalMachine: 
       return "HKEY_LOCAL_MACHINE"; 
      case RegistryHive.PerformanceData: 
       return "HKEY_PERFORMANCE_DATA"; 
      case RegistryHive.Users: 
       return "HKEY_USERS"; 
     } 
     throw new ArgumentOutOfRangeException("hive"); 
    } 
} 

測試文件:

private RegistryService CreateMockedRegistryService() 
{ 
    return new RegistryService(MockRepository.GenerateMock<ILoggerFacadeExtended>(), MockRepository.GenerateMock<IConnectivityService>()); 
} 

[TestMethod()] 
public void GetRegistryPathTest_ClassesRoot() 
{ 
    RegistryService target = CreateMockedRegistryService(); 
    RegistryHive hive = RegistryHive.ClassesRoot; 
    string path = @"Something\SomethingElse\"; 
    string expected = @"HKEY_CLASSES_ROOT\Something\SomethingElse"; 
    string actual; 
    actual = target.GetRegistryPath(hive, path); 
    Assert.AreEqual(expected, actual); 
} 

[TestMethod()] 
public void GetRegistryPathTest_CurrentConfig() 
{ 
    RegistryService target = CreateMockedRegistryService(); 
    RegistryHive hive = RegistryHive.CurrentConfig; 
    string path = @"Something\SomethingElse\"; 
    string expected = @"HKEY_CURRENT_CONFIG\Something\SomethingElse"; 
    string actual; 
    actual = target.GetRegistryPath(hive, path); 
    Assert.AreEqual(expected, actual); 
} 

我簡單化的代碼,試圖展示我在這裏沒有佔用太多空間。我可以一個接一個沒有問題地運行,但是在一起運行時會收到異常。

+0

我試圖同時運行測試,他們通過。你有任何信息 – 2012-02-16 07:48:26

回答

1

我想通了通過卸載其他單元測試項目,然後運行試驗,直到它的工作,顯然是其中之一是使用一些舊的棱鏡參考,並正在包括這些文件,而不是更新的人的,這個問題現在已經解決後,我刪除並閱讀了參考文獻。