Reputation: 1021
In my unit tests, I want to be able to validate the content message of the exception but since our build servers farm has clients in french and english, the message changes between runs and ends up crashing the tests.
The actual way I do it is that I test if it is one or the other but it is uselessly complicated and ugly. I'm using MsTest v2 and FluentAssertions. I already tried setting
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-CA");
but it looks like it is not the right place to fix the culture for exceptions globalization. What is?
Edit for repro example
Tested code
public class ObjectWithMethodThatThrows
{
public string MethodThatThrows(string arg)
=> arg ?? throw new ArgumentNullException(nameof(arg));
}
Test Method
[TestMethod]
public void TestMethodThatThrows()
{
var sut = new ObjectWithMethodThatThrows();
Action act = () => sut.MethodThatThrows(null);
act.Should().Throw<ArgumentNullException>.WithMessage("*Value cannot be null");
}
This test will crash on a French server because the message will be
La valeur ne peut pas être null.
https://unlocalize.com/33667/The-Value-cannot-be-null/fr
I want to be able, on the build servers, to always get Value cannot be null no matter how the server is configured.
Upvotes: 1
Views: 34