I want to set invariant culture for my test cases, at a test class level. What I did first is to create a base class for test classes, but it is instantiated for every test case, so culture is set/rollbacked for every test, what I do not need.
So I replaced the base class by a class fixture (xUnit 2.4.1), which is instantiated once for the test class (good, as expected) but... the culture set is not taken into account. From the very first test case, even in the ctor of the test class (which is called after fixture's one), the culture is my system's one and not the one I have set to tests.
I have checked that both fixture and test case are running in the same thread.
Fixture is very basic and looks like this:
public class UnitTestsFixture : IDisposable
{
private bool disposedValue;
protected readonly CultureInfo originalCulture;
public UnitTestsFixture()
{
originalCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
Thread.CurrentThread.CurrentCulture = originalCulture;
// TODO: dispose managed state (managed objects)
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
disposedValue = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}