2014-09-25 94 views
1

我試圖爲我的MVC5應用程序創建單元測試,我正在使用資源。我的問題是,當我執行測試時,會拋出這個異常。資源大會沒有找到

System.Resources.MissingManifestResourceException:無法爲指定的文化或中性文化找到適當的資源。確保「Resources.Ressources.resources」正確嵌入或在編譯時鏈接到裝配「GestionSaisieExternaliséeV2」,或者確保所有需要的附屬程序集都可加載並已進行了完全簽名

我的行動使用的資源的控制器。

[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 
internal static global::System.Resources.ResourceManager ResourceManager 
{ 
    get 
    { 
      if (object.ReferenceEquals(resourceMan, null)) 
      { 
       global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Resources.Ressources", typeof(Ressources).Assembly); 
       resourceMan = temp; 
      } 
      return resourceMan; 
    } 
} 

的VS解決方案項目:

  • MVC 5項目。
  • 單元測試項目。
+1

您是否驗證了錯誤消息中提到的所有內容?如果是的話 - 請確保用您的發現更新您的文章。 – 2014-09-25 14:04:31

+0

我不知道要驗證什麼,我的資源文件「.resx」是bin文件夾和MVC應用程序的DLL也。 – HLS 2014-09-25 14:10:45

+0

您是否缺少測試項目中的參考? – 2014-09-25 14:18:12

回答

1

已解決。 資源文件應該在文件的屬性中設置爲「Embedded Resource」。

感謝大家。

0

我認爲你需要讓你的資源類公開;見下圖:

Make resources public.

另一件事將是InternalVisibleTo屬性添加到AssemblyInfo.cs文件你的MVC項目。這將使內部類型(默認訪問修飾符)對測試程序集可見,因此您可以從那裏訪問Resources.Something