我正在尝试编写一个单元测试来访问我与项目关联的资源。这是一般结构。该资源具有打算由 MyLibClass 使用的字符串,并且该类设置为en-US
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位于单独的项目文件夹中。
有没有更好的方法来解决这个问题?