|
16 | 16 | using System; |
17 | 17 | using FluentAssertions; |
18 | 18 | using System.Globalization; |
| 19 | +using System.Threading; |
19 | 20 | using Xunit; |
20 | 21 |
|
21 | 22 | namespace MongoDB.Bson.Tests |
@@ -121,6 +122,46 @@ public void ToDecimal_should_throw_when_value_is_out_of_range(string valueString |
121 | 122 | exception.Should().BeOfType<OverflowException>(); |
122 | 123 | } |
123 | 124 |
|
| 125 | + [Theory] |
| 126 | + [InlineData("123.456", 123.456)] |
| 127 | + public void ToDouble_should_not_depend_on_current_culture(string valueString, double expectedDouble) |
| 128 | + { |
| 129 | + var currentCulture = Thread.CurrentThread.CurrentCulture; |
| 130 | + try |
| 131 | + { |
| 132 | + Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); |
| 133 | + var subject = Decimal128.Parse(valueString); |
| 134 | + |
| 135 | + var result = Decimal128.ToDouble(subject); |
| 136 | + |
| 137 | + result.Should().Be(expectedDouble); |
| 138 | + } |
| 139 | + finally |
| 140 | + { |
| 141 | + Thread.CurrentThread.CurrentCulture = currentCulture; |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + [Theory] |
| 146 | + [InlineData("123.456", 123.456)] |
| 147 | + public void ToSingle_should_not_depend_on_current_culture(string valueString, float expectedFloat) |
| 148 | + { |
| 149 | + var currentCulture = Thread.CurrentThread.CurrentCulture; |
| 150 | + try |
| 151 | + { |
| 152 | + Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); |
| 153 | + var subject = Decimal128.Parse(valueString); |
| 154 | + |
| 155 | + var result = Decimal128.ToSingle(subject); |
| 156 | + |
| 157 | + result.Should().Be(expectedFloat); |
| 158 | + } |
| 159 | + finally |
| 160 | + { |
| 161 | + Thread.CurrentThread.CurrentCulture = currentCulture; |
| 162 | + } |
| 163 | + } |
| 164 | + |
124 | 165 | [Theory] |
125 | 166 | [InlineData((byte)0, "0")] |
126 | 167 | [InlineData((byte)1, "1")] |
|
0 commit comments