I have simply question. How can this test fail? In comments are values of variables
[Fact]
public void ToNullableDouble_CorrectInput_ReturnsCorrectValue()
{
double expectedValue = double.MaxValue; //1.7976931348623157E+308
string expectedValueString = expectedValue.ToString(); //"1,79769313486232E+308" - fail, I do not know why
string expectedValueString2 = expectedValue.ToString(CultureInfo.InvariantCulture); //"1.79769313486232E+308" - fail
string expectedValueString3 = 1.75.ToString(); //"1,75" - pass
string expectedValueString4 = 1.75.ToString(CultureInfo.InvariantCulture); //"1.75" - fail because of the culture
double number;
double? convertedValue = double.TryParse(expectedValueString, out number) ? number : (double?)null;
//convertedValue = null, number = 0
Assert.True(convertedValue.HasValue);
}
Float behaves pretty same, decimal is ok. I know what is the difference between decimally types. But I do not understand how can be MaxValue constant unconverted. It is not should be culture settings:
double.TryParse(expectedValueString, out number) ? number : (double?)null;
null
double.TryParse(expectedValueString2, out number) ? number : (double?)null;
null
double.TryParse(expectedValueString3, out number) ? number : (double?)null;
1.75
double.TryParse(expectedValueString4, out number) ? number : (double?)null;
null
For other values works correctly e.g.: 1.75