我正在嘗試編寫一個單元測試,以訪問與項目關聯的資源。這是一般結構。資源具有旨在由MyLibClass使用字符串和類設置爲en-US
如何從另一個(測試).Net dll訪問.Net DLL中的嵌入式資源?
Solution1
--MyLibrary
--Properties
--AssemblyInfo.cs
--Resources.resx
--Resource.Designer.cs
--References
--MyLibClass.cs
--MyLibrary.Tests
--Properties
--AssemblyInfo.cs
--References
--MyLibClassTests.cs
--MainProject
的測試需要設置類,並通過它的ResourceManager因爲我試圖使用依賴注入。當我嘗試在測試中使用下面的代碼進行加載時,出現以下錯誤。
由於資源被嵌入到MyLibrary.dll中,MyLibraryTest.dll如何訪問它?
resmgr = new ResourceManager("MyLibrary",
Assembly.GetExecutingAssembly());
誤差在NUnit的
MyLibrary.Tests. MyLibClassTests.IsInValidMyProperty_Blank:
An unexpected exception type was thrown
Expected: System.ArgumentException
but was: System.Resources.MissingManifestResourceException : Could not find any
resources appropriate for the specified culture or the neutral culture. Make sure
"MyLibrary.resources" was correctly embedded or linked into assembly "MyLibrary.Tests"
at compile time, or that all the satellite assemblies required are loadable and
fully signed.
所以經過考慮之後,DLL的是在不同的項目文件夾。
有沒有更好的方法來解決這個問題?
executingassembly是測試的DLL,你想,你正在測試 –