Skip to content

Commit f3a601b

Browse files
authored
Merge pull request #2118 from dldl-cmd/fix_test_not_independent_of_machine_culture
Remove dependency on CurrentCulture in tests
2 parents 4821b92 + a946952 commit f3a601b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public async Task WriteOpenApiFloatAsJsonWorksAsync(float input, bool produceTer
113113
var json = await WriteAsJsonAsync(floatValue, produceTerseOutput);
114114

115115
// Assert
116-
Assert.Equal(input.ToString(), json);
116+
Assert.Equal(input.ToString(CultureInfo.InvariantCulture), json);
117117
}
118118

119119
public static IEnumerable<object[]> DoubleInputs
@@ -141,15 +141,15 @@ public async Task WriteOpenApiDoubleAsJsonWorksAsync(double input, bool produceT
141141
var json = await WriteAsJsonAsync(doubleValue, produceTerseOutput);
142142

143143
// Assert
144-
Assert.Equal(input.ToString(), json);
144+
Assert.Equal(input.ToString(CultureInfo.InvariantCulture), json);
145145
}
146146

147147
public static IEnumerable<object[]> StringifiedDateTimes
148148
{
149149
get
150150
{
151151
return
152-
from input in new [] {
152+
from input in new[] {
153153
"2017-1-2",
154154
"1999-01-02T12:10:22",
155155
"1999-01-03",
@@ -178,7 +178,7 @@ public async Task WriteOpenApiDateTimeAsJsonWorksAsync(string inputString, bool
178178
public static IEnumerable<object[]> BooleanInputs
179179
{
180180
get =>
181-
from input in new [] { true, false }
181+
from input in new[] { true, false }
182182
from shouldBeTerse in shouldProduceTerseOutputValues
183183
select new object[] { input, shouldBeTerse };
184184
}
@@ -258,7 +258,7 @@ private static async Task<string> WriteAsJsonAsync(JsonNode any, bool produceTer
258258
// Arrange (continued)
259259
using var stream = new MemoryStream();
260260
var writer = new OpenApiJsonWriter(
261-
new StreamWriter(stream),
261+
new CultureInvariantStreamWriter(stream),
262262
new() { Terse = produceTerseOutput });
263263

264264
writer.WriteAny(any);
@@ -279,5 +279,15 @@ private static async Task<string> WriteAsJsonAsync(JsonNode any, bool produceTer
279279
_ => value.MakeLineBreaksEnvironmentNeutral(),
280280
};
281281
}
282+
283+
private class CultureInvariantStreamWriter : StreamWriter
284+
{
285+
public CultureInvariantStreamWriter(Stream stream) : base(stream)
286+
{
287+
}
288+
289+
public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture;
290+
}
291+
282292
}
283293
}

0 commit comments

Comments
 (0)