Trying to follow this: http://msdn.microsoft.com/en-us/library/21a15yht.aspx The problem with the example is it's a mixture of instructions for visual studio users and command line users, but I have done my best to follow only the VS instructions.
So I have: Created a new Unit Test Project in visual studio called Example
.
I added a resource called Greeting.en-US.resx
and put a string in called HelloString
.
Edit I have now added another default resource file called Greeting.resx
string is "Hello (Default)"
My unit test:
using System.Globalization;
using System.Resources;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Example
{
[TestClass]
public class GreetingTests
{
[TestMethod]
public void Hello()
{
var newCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = newCulture;
Thread.CurrentThread.CurrentUICulture = newCulture;
var rm = new ResourceManager("Example.Greeting",
typeof (GreetingTests).Assembly);
Assert.AreEqual("Hello (US)", rm.GetString("HelloString"));
}
}
}
Now it only ever loads the default
Assert.AreEqual failed. Expected:<Hello (US)>. Actual:<Hello (Default)>.
The same code works in a Console App just fine.