Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1d2c96e

Browse files
AlexRadchstephentoub
authored andcommitted
Fixed netfx System.ComponentModel.TypeConverter.Tests-InvariantCulture on non English Windows (#28168)
* Fixed netfx System.ComponentModel.TypeConverter.Tests-InvariantCulture on non English Windows. * Used RemoteInvoke * Removed return SuccessExitCode;
1 parent ee528ac commit 1d2c96e

File tree

7 files changed

+81
-42
lines changed

7 files changed

+81
-42
lines changed

src/System.ComponentModel.TypeConverter/tests/ArrayConverterTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Globalization;
56
using Xunit;
67

78
namespace System.ComponentModel.Tests
@@ -11,11 +12,16 @@ public class ArrayConverterTests : ConverterTestBase
1112
[Fact]
1213
public static void ConvertTo_WithContext()
1314
{
14-
ConvertTo_WithContext(new object[1, 3]
15-
{
16-
{ new int[2] { 1, 2 }, "Int32[] Array", null }
17-
},
18-
new ArrayConverter());
15+
RemoteInvoke(() =>
16+
{
17+
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
18+
19+
ConvertTo_WithContext(new object[1, 3]
20+
{
21+
{ new int[2] { 1, 2 }, "Int32[] Array", null }
22+
},
23+
new ArrayConverter());
24+
}).Dispose();
1925
}
2026
}
2127
}

src/System.ComponentModel.TypeConverter/tests/CollectionConverterTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Globalization;
56
using Xunit;
67

78
namespace System.ComponentModel.Tests
@@ -13,11 +14,16 @@ public class CollectionConverterTests : ConverterTestBase
1314
[Fact]
1415
public static void ConvertTo_WithContext()
1516
{
16-
ConvertTo_WithContext(new object[1, 3]
17-
{
18-
{ new Collection1(), "(Collection)", null }
19-
},
20-
CollectionConverterTests.s_converter);
17+
RemoteInvoke(() =>
18+
{
19+
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
20+
21+
ConvertTo_WithContext(new object[1, 3]
22+
{
23+
{ new Collection1(), "(Collection)", null }
24+
},
25+
CollectionConverterTests.s_converter);
26+
}).Dispose();
2127
}
2228
}
2329
}

src/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@
1111
//
1212

1313
using System.ComponentModel.Design.Serialization;
14+
using System.Diagnostics;
1415
using System.Globalization;
16+
using System.Runtime.InteropServices;
1517
using Xunit;
1618

1719
namespace System.ComponentModel.Tests
1820
{
19-
public class CultureInfoConverterTest
21+
public class CultureInfoConverterTest : RemoteExecutorTestBase
2022
{
21-
private CultureInfoConverter converter;
22-
23-
public CultureInfoConverterTest()
24-
{
25-
converter = new CultureInfoConverter();
26-
}
23+
private CultureInfoConverter converter => new CultureInfoConverter();
2724

2825
[Fact]
2926
public void CanConvertFrom()
@@ -153,13 +150,18 @@ public void ConvertFrom_String_InvalidCulture()
153150
[Fact]
154151
public void ConvertFrom_Value_Null()
155152
{
156-
NotSupportedException ex = Assert.Throws<NotSupportedException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, (string)null));
157-
// CultureInfoConverter cannot convert from (null)
158-
Assert.Equal(typeof(NotSupportedException), ex.GetType());
159-
Assert.Null(ex.InnerException);
160-
Assert.NotNull(ex.Message);
161-
Assert.True(ex.Message.IndexOf(typeof(CultureInfoConverter).Name) != -1);
162-
Assert.True(ex.Message.IndexOf("(null)") != -1);
153+
RemoteInvoke(() =>
154+
{
155+
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
156+
157+
NotSupportedException ex = Assert.Throws<NotSupportedException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, (string)null));
158+
// CultureInfoConverter cannot convert from (null)
159+
Assert.Equal(typeof(NotSupportedException), ex.GetType());
160+
Assert.Null(ex.InnerException);
161+
Assert.NotNull(ex.Message);
162+
Assert.True(ex.Message.IndexOf(typeof(CultureInfoConverter).Name) != -1);
163+
Assert.True(ex.Message.IndexOf("(null)") != -1);
164+
}).Dispose();
163165
}
164166

165167
[Fact]

src/System.ComponentModel.TypeConverter/tests/Design/DesignerOptionServiceTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
using System.Collections;
66
using System.ComponentModel.DataAnnotations;
7+
using System.Diagnostics;
8+
using System.Globalization;
79
using System.Linq;
810
using Xunit;
911

1012
namespace System.ComponentModel.Design.Tests
1113
{
12-
public class DesignerOptionServiceTests
14+
public class DesignerOptionServiceTests : RemoteExecutorTestBase
1315
{
1416
[Fact]
1517
public void CreateOptionCollection_CreateMultipleTimes_ReturnsExpected()
@@ -266,8 +268,13 @@ public void DesignerOptionConverterGetProperties_InvalidValue_ReturnsEmpty(objec
266268
[Fact]
267269
public void DesignerOptionConverter_ConvertToString_ReturnsExpected()
268270
{
269-
TypeConverter converter = TypeDescriptor.GetConverter(typeof(DesignerOptionService.DesignerOptionCollection));
270-
Assert.Equal("(Collection)", converter.ConvertToString(null));
271+
RemoteInvoke(() =>
272+
{
273+
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
274+
275+
TypeConverter converter = TypeDescriptor.GetConverter(typeof(DesignerOptionService.DesignerOptionCollection));
276+
Assert.Equal("(Collection)", converter.ConvertToString(null));
277+
}).Dispose();
271278
}
272279

273280
[Fact]

src/System.ComponentModel.TypeConverter/tests/MultilineStringConverterTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Globalization;
56
using Xunit;
67

78
namespace System.ComponentModel.Tests
@@ -11,11 +12,16 @@ public class MultilineStringConverterTests : ConverterTestBase
1112
[Fact]
1213
public static void ConvertTo_WithContext()
1314
{
14-
ConvertTo_WithContext(new object[1, 3]
15-
{
16-
{ "any string", "(Text)", null }
17-
},
18-
new MultilineStringConverter());
15+
RemoteInvoke(() =>
16+
{
17+
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
18+
19+
ConvertTo_WithContext(new object[1, 3]
20+
{
21+
{ "any string", "(Text)", null }
22+
},
23+
new MultilineStringConverter());
24+
}).Dispose();
1925
}
2026
}
2127
}

src/System.ComponentModel.TypeConverter/tests/ReferenceConverterTests.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333

3434
using System.Collections.Generic;
3535
using System.ComponentModel.Design;
36+
using System.Diagnostics;
37+
using System.Globalization;
3638
using Xunit;
3739

3840
namespace System.ComponentModel.Tests
3941
{
40-
public class ReferenceConverterTest
42+
public class ReferenceConverterTest : RemoteExecutorTestBase
4143
{
4244

4345
class TestReferenceService : IReferenceService
@@ -197,11 +199,16 @@ public void ConvertFrom()
197199
[Fact]
198200
public void ConvertTo()
199201
{
200-
ReferenceConverter converter = new ReferenceConverter(typeof(ITestInterface));
201-
string referenceName = "reference name";
202+
RemoteInvoke(() =>
203+
{
204+
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
202205

203-
Assert.Equal("(none)", (string)converter.ConvertTo(null, null, null, typeof(string)));
206+
ReferenceConverter remoteConverter = new ReferenceConverter(typeof(ITestInterface));
207+
Assert.Equal("(none)", (string)remoteConverter.ConvertTo(null, null, null, typeof(string)));
208+
}).Dispose();
204209

210+
ReferenceConverter converter = new ReferenceConverter(typeof(ITestInterface));
211+
string referenceName = "reference name";
205212
TestComponent component = new TestComponent();
206213

207214
// no context

src/System.ComponentModel.TypeConverter/tests/TypeListConverterTests.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ public static void ConvertFrom_WithContext()
3636
[Fact]
3737
public static void ConvertTo_WithContext()
3838
{
39-
ConvertTo_WithContext(new object[2, 3]
40-
{
41-
{ typeof(char), "System.Char", null }, // the base class is not verifying if this type is not in the list
42-
{ null, "(none)", CultureInfo.InvariantCulture }
43-
},
44-
TypeListConverterTests.s_converter);
39+
RemoteInvoke(() =>
40+
{
41+
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
42+
43+
ConvertTo_WithContext(new object[2, 3]
44+
{
45+
{ typeof(char), "System.Char", null }, // the base class is not verifying if this type is not in the list
46+
{ null, "(none)", CultureInfo.InvariantCulture }
47+
},
48+
TypeListConverterTests.s_converter);
49+
}).Dispose();
4550
}
4651

4752
[Fact]

0 commit comments

Comments
 (0)