Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are resx cultures not found in unit tests?

I have embedded string resources in my .NET 4.0 project: Strings.resx and Strings.de.resx.

In production code the correct localised strings are retrieved, dependent on the value of Strings.Culture:

Strings.Culture = new Culture("de");
string deString = Strings.Welcome;  // 'Willkommen'
Strings.Culture = new Culture("en");
string enString = Strings.Welcome;  // 'Welcome'

But in my unit test code (using MSTest) the strings from 'Strings.de.resx' are never returned - I only ever get the strings from Strings.resx, no matter what the values of Strings.Culture or Threads.CurrentThread.CultureUICulture.

Can anybody help?

like image 729
GarethOwen Avatar asked Feb 28 '12 15:02

GarethOwen


1 Answers

Ok, I was able to reproduce this issue. First of all try to disable deployment. Go to "local.testsettings" and uncheck Deployment -> Enable Deployment. When this flag is checked, VS doesn't seem to be deploying satellite assemblies for me. If you do need some deployment item, use DeploymentItemAttribute:

[DeploymentItem(
   @".\YourProject\bin\Debug\de\YourProject.resources.dll", @".\de\")]

or use the same "Deployment" tab to select appropriate satellite assemblies.

like image 192
Primary Key Avatar answered Oct 17 '22 22:10

Primary Key