1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Linq;
using Xunit;
namespace System.Globalization.Tests
{
public class RegionInfoPropertyTests
{
[Fact]
public void CurrentRegion()
{
CultureInfo oldThreadCulture = CultureInfo.CurrentCulture;
try
{
CultureInfo.CurrentCulture = new CultureInfo("en-US");
RegionInfo ri = new RegionInfo(new RegionInfo(CultureInfo.CurrentCulture.Name).TwoLetterISORegionName);
Assert.True(RegionInfo.CurrentRegion.Equals(ri) || RegionInfo.CurrentRegion.Equals(new RegionInfo(CultureInfo.CurrentCulture.Name)));
Assert.Same(RegionInfo.CurrentRegion, RegionInfo.CurrentRegion);
}
finally
{
CultureInfo.CurrentCulture = oldThreadCulture;
}
}
[Theory]
[InlineData("en-US", "United States")]
public void DisplayName(string name, string expected)
{
Assert.Equal(expected, new RegionInfo(name).DisplayName);
}
[Theory]
[InlineData("GB", "United Kingdom")]
[InlineData("SE", "Sverige")]
[InlineData("FR", "France")]
public void NativeName(string name, string expected)
{
Assert.Equal(expected, new RegionInfo(name).NativeName);
}
[Theory]
[InlineData("en-US", new string[] { "United States" })]
[InlineData("US", new string[] { "United States" })]
[InlineData("zh-CN", new string[] { "China", "People's Republic of China" })]
[InlineData("CN", new string[] { "China", "People's Republic of China" })]
public void EnglishName(string name, string[] expected)
{
string result = new RegionInfo(name).EnglishName;
Assert.True(expected.Contains(result));
}
[Theory]
[InlineData("en-US", false)]
[InlineData("zh-CN", true)]
public void IsMetric(string name, bool expected)
{
Assert.Equal(expected, new RegionInfo(name).IsMetric);
}
[Theory]
[InlineData("en-US", "USD")]
[InlineData("zh-CN", "CNY")]
[InlineData("de-DE", "EUR")]
[InlineData("it-IT", "EUR")]
public void ISOCurrencySymbol(string name, string expected)
{
Assert.Equal(expected, new RegionInfo(name).ISOCurrencySymbol);
}
[Theory]
[InlineData("en-US", new string[] { "$" })]
[InlineData("zh-CN", new string[] { "\u00A5", "\uffe5" })] // \u00A5 is Latin-1 Supplement(Windows), \uffe5 is Halfwidth and Fullwidth Forms(ICU)
public void CurrencySymbol(string name, string[] expected)
{
string result = new RegionInfo(name).CurrencySymbol;
Assert.True(expected.Contains(result));
}
[Theory]
[InlineData("en-US", "US")]
[InlineData("zh-CN", "CN")]
[InlineData("de-DE", "DE")]
[InlineData("it-IT", "IT")]
public void TwoLetterISORegionName(string name, string expected)
{
Assert.Equal(expected, new RegionInfo(name).TwoLetterISORegionName);
}
}
}
|