问题描述
我遇到一个奇怪的问题.在我的单元测试中,我想检查本地化的字符串.但是,我似乎无法正常工作.例如,我创建了两个资源:用于英语的Resource1.resx和用于中文的Resource1.zh-CN.resx.单元测试项目只能获取(默认值?)英语资源字符串.这是我正在使用的代码:
I ran into a strange problem. In my unit test, I want to check the localized strings. However, I can't seem to get it work. For example, I created two resources: Resource1.resx for English and Resource1.zh-CN.resx for Chinese. The unit test project can only get the (default?) English resource string. This is the code I'm using:
ResourceManager actual = new ResourceManager(typeof(LocaleTest.Properties.Resource1));
string name0 = actual.GetString("Name", new CultureInfo("en-US"));
string name1 = actual.GetString("Name", new CultureInfo("zh-CN"));
我创建了另一个常规项目(不是MSTest项目),以确保本地化的字符串正常工作.因此,它可以在常规项目中工作,而不能在MSTest项目中工作.
I created another regular project (means not a MSTest project) to make sure the localized strings are working. So, it works in a regular project, but not in a MSTest project.
即使我将以下代码设置为"zh-CN"作为单元测试的当前区域性,也无济于事:
It didn't help even if I put the following code to make 'zh-CN' as the current culture of the unit test:
[TestInitialize()]
public void MyTestInitialize()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
}
有人看到过类似的问题吗?有什么解决方法吗?
Anybody has seen similar problems? Is there any workaround?
推荐答案
您不需要使用 DeploymentItem 以确保本地化DLL在测试文件夹中?
Don't you need to use DeploymentItem to ensure that the localisation DLL is in the test folder?
[TestMethod()]
[DeploymentItem(@"bin\Debug\fr\Proj.resources.dll", "fr-CA")]
public void TestDialogLocalization(){
// blah
}
这篇关于MSTest项目无法获取本地化的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!