diff options
author | Tarek Mahmoud Sayed <tarekms@microsoft.com> | 2017-02-10 04:24:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-10 04:24:42 +0300 |
commit | 3a1b3e25cbdba9c06527b47a71d6bc6a41ea5659 (patch) | |
tree | 0079a8929ac97ec4a9710a21472d8ea9ba128048 /src/System.ComponentModel.TypeConverter | |
parent | a8bcdac9416b498b892941873f608b1ee55eb3e6 (diff) |
Fix ComponentModel tests on Linux (#16019)
* Fix ComponentModel tests on Linux
* Remove extra spaces
Diffstat (limited to 'src/System.ComponentModel.TypeConverter')
-rw-r--r-- | src/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs | 100 | ||||
-rw-r--r-- | src/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj | 2 |
2 files changed, 66 insertions, 36 deletions
diff --git a/src/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs b/src/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs index 24133951d8..30c59d800f 100644 --- a/src/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs +++ b/src/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs @@ -44,7 +44,6 @@ namespace System.ComponentModel.Tests Assert.True(converter.CanConvertTo(typeof(InstanceDescriptor))); } - [ActiveIssue(11611, TestPlatforms.AnyUnix)] [Fact] public void ConvertFrom_String() { @@ -57,9 +56,18 @@ namespace System.ComponentModel.Tests c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "nl-BE"); Assert.Equal(new CultureInfo("nl-BE"), c); - - Assert.Throws<ArgumentException>(() => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "Dutch (Bel")); - Assert.Throws<ArgumentException>(() => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "duTcH (Bel")); + + try + { + // Linux can create such cultures + var cul = new CultureInfo("Dutch (Bel"); + } + catch (CultureNotFoundException) + { + // if we cannot create the cultures we should get exception from the Converter too + Assert.Throws<ArgumentException>(() => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "Dutch (Bel")); + Assert.Throws<ArgumentException>(() => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "duTcH (Bel")); + } c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "(Default)"); Assert.Equal(CultureInfo.InvariantCulture, c); @@ -72,41 +80,65 @@ namespace System.ComponentModel.Tests "nl-B"); } - [ActiveIssue(11611, TestPlatforms.AnyUnix)] [Fact] public void ConvertFrom_String_InvalidCulture() { ArgumentException ex; - ex = Assert.Throws<ArgumentException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "(default)")); - // The (default) culture cannot be converted to - // a CultureInfo object on this computer - Assert.Equal(typeof(ArgumentException), ex.GetType()); - Assert.Null(ex.InnerException); - Assert.NotNull(ex.Message); - Assert.True(ex.Message.IndexOf(typeof(CultureInfo).Name) != -1); - Assert.True(ex.Message.IndexOf("(default)") != -1); - Assert.Null(ex.ParamName); - - ex = Assert.Throws<ArgumentException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, " ")); - // The culture cannot be converted to - // a CultureInfo object on this computer - Assert.Equal(typeof(ArgumentException), ex.GetType()); - Assert.Null(ex.InnerException); - Assert.NotNull(ex.Message); - Assert.True(ex.Message.IndexOf(typeof(CultureInfo).Name) != -1); - Assert.True(ex.Message.IndexOf(" ") != -1); - Assert.Null(ex.ParamName); - - ex = Assert.Throws<ArgumentException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "\r\n")); - // The \r\n culture cannot be converted to - // a CultureInfo object on this computer - Assert.Equal(typeof(ArgumentException), ex.GetType()); - Assert.Null(ex.InnerException); - Assert.NotNull(ex.Message); - Assert.True(ex.Message.IndexOf(typeof(CultureInfo).Name) != -1); - Assert.True(ex.Message.IndexOf("\r\n") != -1); - Assert.Null(ex.ParamName); + try + { + // Linux can create such cultures + var cul = new CultureInfo("(default)"); + } + catch (CultureNotFoundException) + { + // if we cannot create the cultures we should get exception from the Converter too + ex = Assert.Throws<ArgumentException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "(default)")); + // The (default) culture cannot be converted to + // a CultureInfo object on this computer + Assert.Equal(typeof(ArgumentException), ex.GetType()); + Assert.Null(ex.InnerException); + Assert.NotNull(ex.Message); + Assert.True(ex.Message.IndexOf(typeof(CultureInfo).Name) != -1); + Assert.True(ex.Message.IndexOf("(default)") != -1); + Assert.Null(ex.ParamName); + } + + try + { + // Linux can create such cultures + var cul = new CultureInfo(" "); + } + catch (CultureNotFoundException) + { + ex = Assert.Throws<ArgumentException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, " ")); + // The culture cannot be converted to + // a CultureInfo object on this computer + Assert.Equal(typeof(ArgumentException), ex.GetType()); + Assert.Null(ex.InnerException); + Assert.NotNull(ex.Message); + Assert.True(ex.Message.IndexOf(typeof(CultureInfo).Name) != -1); + Assert.True(ex.Message.IndexOf(" ") != -1); + Assert.Null(ex.ParamName); + } + + try + { + // Linux can create such cultures + var cul = new CultureInfo("\r\n"); + } + catch (CultureNotFoundException) + { + ex = Assert.Throws<ArgumentException>(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "\r\n")); + // The \r\n culture cannot be converted to + // a CultureInfo object on this computer + Assert.Equal(typeof(ArgumentException), ex.GetType()); + Assert.Null(ex.InnerException); + Assert.NotNull(ex.Message); + Assert.True(ex.Message.IndexOf(typeof(CultureInfo).Name) != -1); + Assert.True(ex.Message.IndexOf("\r\n") != -1); + Assert.Null(ex.ParamName); + } } [Fact] diff --git a/src/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj b/src/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj index 4edc55d965..3a4616e681 100644 --- a/src/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj +++ b/src/System.ComponentModel.TypeConverter/tests/System.ComponentModel.TypeConverter.Tests.csproj @@ -65,8 +65,6 @@ <Compile Include="UInt32ConverterTests.cs" /> <Compile Include="UInt64ConverterTests.cs" /> <Compile Include="UriTypeConverterTests.cs" /> - </ItemGroup> - <ItemGroup Condition=" '$(TargetGroup)' == 'netstandard'"> <Compile Include="Drawing\StringTypeConverterTestBase.cs" /> <Compile Include="TimerTests.cs" /> <Compile Include="BindingListTests.cs" /> |