MSTest project cannot get localized string?

I got a strange problem. In my unit test, I want to check localized strings. However, I cannot get it to work. For example, I created two resources: Resource1.resx for English and Resource1.zh-CN.resx for the Chinese. The unit test project can only get the English resource string (by default?). 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"));

I created another regular project (not an MSTest project) to make sure localized strings work. Thus, it works in a regular project, but not in an MSTest project.

This did not help, even if I put the following code to make "zh-CN" the current unit test culture:

[TestInitialize()]
public void MyTestInitialize()
{
    Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
} 

Has anyone seen similar problems? Is there a workaround?

+5
1

DeploymentItem, DLL ?

[TestMethod()]
[DeploymentItem(@"bin\Debug\fr\Proj.resources.dll", "fr-CA")]
public void TestDialogLocalization(){
 // blah
}
+10

All Articles