From b039537aa9a77535a7e90b520aec199a81afb712 Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Tue, 13 Jun 2017 15:16:59 -0700 Subject: [PATCH] Force invariant culture for some ColorTranslator tests. --- .../tests/ColorTranslatorTests.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/System.Drawing.Common/tests/ColorTranslatorTests.cs b/src/System.Drawing.Common/tests/ColorTranslatorTests.cs index 574a88e22650..c0c602f9a86b 100644 --- a/src/System.Drawing.Common/tests/ColorTranslatorTests.cs +++ b/src/System.Drawing.Common/tests/ColorTranslatorTests.cs @@ -3,7 +3,9 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Globalization; using System.Reflection; +using System.Threading; using Xunit; namespace System.Drawing.Tests @@ -188,7 +190,16 @@ public static IEnumerable FromHtml_TestData() [MemberData(nameof(FromHtml_TestData))] public void FromHtml_String_ReturnsExpected(string htmlColor, Color expected) { - Assert.Equal(expected, ColorTranslator.FromHtml(htmlColor)); + CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture; + try + { + Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal(expected, ColorTranslator.FromHtml(htmlColor)); + } + finally + { + Thread.CurrentThread.CurrentCulture = originalCulture; + } } [Theory] @@ -216,7 +227,16 @@ public void FromHtml_String_ReturnsExpected(string htmlColor, Color expected) [InlineData("1,2,256", typeof(ArgumentException))] public void FromHtml_Invalid_Throws(string htmlColor, Type exception) { - Assert.Throws(exception, () => ColorTranslator.FromHtml(htmlColor)); + CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture; + try + { + Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Throws(exception, () => ColorTranslator.FromHtml(htmlColor)); + } + finally + { + Thread.CurrentThread.CurrentCulture = originalCulture; + } } public static IEnumerable ToHtml_TestData()