I have written the following to stub a Singleton for the purpose of unit testing.
public static class LocalisationSetter
{
[ThreadStatic]
private static CultureInfo _cultureInfo;
public static void Set(CultureInfo cultureInfo)
{
_cultureInfo = cultureInfo;
Localisation.Current.Culture = _cultureInfo; // Setting The singleton.
}
}
In my test I do something like below:
LocalisationSetter.Set(new CultureInfo("fr-FR"));
The above method just seems little "dirty"...
Just wondered if there is potentially a better way. I need to make sure the changes to "Localisation" is only visible to the thread.
Localisation.Currentis notThreadStaticalso then yourSetterclass is pointless. Even if it is, the class doesn't do anything that you couldn't do straight from the test.Thread.CurrentCulture = cultureInfo;AlsoThread.CurrentUICulture.