我正在尝试编写一个单元测试,以访问与项目关联的资源。这是一般结构。资源具有旨在由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,你想,你正在测试 –