/
Countries_generation.cs
254 lines (219 loc) · 8.55 KB
/
Countries_generation.cs
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
using Qowaiv.TestTools.Generation;
using Qowaiv.TestTools.Resx;
using Qowaiv.TestTools.Wikipedia;
namespace Globalization.Countries_specs;
public class Constants
{
[Test]
public void Generates()
{
Action generate = CountryConstants.Generate;
generate.Should().NotThrow();
}
}
/// <remarks>
/// As fetching data from Wikipedia is time consuming (no benefits from caching)
/// and therefor not executed on a RELEASE build.
/// </remarks>
public class Resource_files
{
internal static readonly IReadOnlyCollection<Iso3166_1> Iso3166_1s = new WikiLemma("ISO 3166-1", TestCultures.en).TransformRange(Iso3166_1.Parse).Result;
internal static readonly IReadOnlyCollection<Iso3166_3> Iso3166_3s = new WikiLemma("ISO_3166-3", TestCultures.en).TransformRange(Iso3166_3.Parse).Result;
[TestCaseSource(nameof(Iso3166_1s))]
public void existing_reflect_info_of_Wikipedia(Iso3166_1 info)
{
var country = Country.Parse(info.Iso2);
var summary = new Iso3166_1(country.EnglishName, country.IsoAlpha2Code, country.IsoAlpha3Code, country.IsoNumericCode);
summary.Should().Be(info);
}
[TestCaseSource(nameof(Iso3166_3s))]
public void former_reflect_info_of_Wikipedia(Iso3166_3 info)
{
var country = Country.Parse(info.Name);
var summary = new Iso3166_3(
country.EnglishName,
country.IsoAlpha2Code,
country.IsoAlpha3Code,
country.IsoNumericCode,
0,
0,
country.Name);
summary.Should().BeEquivalentTo(info, c => c.Excluding(m => m.Start).Excluding(m => m.End));
}
public class Display_names
{
private static readonly IReadOnlyCollection<Country> Existing = Country.GetExisting().ToArray();
[TestCaseSource(nameof(Existing))]
public async Task ar(Country country)
{
var display = country.GetDisplayName(TestCultures.ar);
display.Should().MatchWikipedia(await CountryDisplayName.ar(country))
.And.BeArabic()
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task de(Country country)
{
var display = country.GetDisplayName(TestCultures.de);
display.Should().MatchWikipedia(await CountryDisplayName.de(country))
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task es(Country country)
{
var display = country.GetDisplayName(TestCultures.es);
display.Should().MatchWikipedia(await CountryDisplayName.es(country))
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task fr(Country country)
{
var display = country.GetDisplayName(TestCultures.fr);
display.Should().MatchWikipedia(await CountryDisplayName.fr(country))
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task it(Country country)
{
var display = country.GetDisplayName(TestCultures.it);
display.Should().MatchWikipedia(await CountryDisplayName.it(country))
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task ja(Country country)
{
var display = country.GetDisplayName(TestCultures.ja);
display.Should().MatchWikipedia(await CountryDisplayName.ja(country))
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task nl(Country country)
{
var display = country.GetDisplayName(TestCultures.nl);
display.Should().MatchWikipedia(await CountryDisplayName.nl(country))
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task pt(Country country)
{
var display = country.GetDisplayName(TestCultures.pt);
display.Should().MatchWikipedia(await CountryDisplayName.pt(country))
.And.BeTrimmed();
}
[TestCaseSource(nameof(Existing))]
public async Task ru(Country country)
{
var display = country.GetDisplayName(TestCultures.ru);
display.Should().MatchWikipedia(await CountryDisplayName.ru(country))
.And.BeTrimmed();
}
}
public class Generates
{
[Test]
public void neutral_culture()
{
var unknown = new CountryData("ZZ")
{
DisplayName = "Unknown",
ISO = 999,
ISO2 = "ZZ",
ISO3 = "ZZZ",
StartDate = Date.MinValue,
};
// Including Kosovo, that is still disputed: https://en.wikipedia.org/wiki/XK_(user_assigned_code)
var data = new Dictionary<string, CountryData>()
{
["XK"] = new CountryData("XK")
{
DisplayName = "Kosovo",
ISO2 = "XK",
ISO3 = "XKK",
StartDate = new(2008, 02, 01),
}
};
foreach (var former in Iso3166_3s)
{
data[former.Name] = new(former.Name)
{
DisplayName = former.DisplayName,
ISO = former.Iso,
ISO2 = former.Iso2,
ISO3 = former.Iso3,
StartDate = new(former.Start, 01, 01),
EndDate = new(former.End - 1, 12, 31),
};
}
foreach(var c in Iso3166_1s)
{
data[c.Iso2] = new(c.Iso2)
{
DisplayName = c.DisplayName,
ISO = c.Iso,
ISO2 = c.Iso2,
ISO3 = c.Iso3,
};
}
foreach (var c in Country.All)
{
var dat = data[c.Name];
var updated = dat with
{
StartDate = c.StartDate,
EndDate = c.EndDate,
CallingCode = c.CallingCode,
};
data[c.Name] = updated;
}
var resource = new XResourceFile();
resource.Add("All", string.Join(';', data.Keys.OrderBy(c => c.Length).ThenBy(c => c)));
resource.AddRange(unknown.Data());
foreach (var info in data.Values.OrderBy(c => c.Name.Length).ThenBy(c => c.Name))
{
resource.AddRange(info.Data());
}
resource.Invoking(r => r.Save(Solution.Root.File("src/Qowaiv/Globalization/CountryLabels.resx")))
.Should().NotThrow();
}
[Test]
public async Task ar()
=> (await CountryDisplayName.Update("مجهولة", TestCultures.ar, CountryDisplayName.ar))
.Should().NotThrow();
[Test]
public async Task de()
=> (await CountryDisplayName.Update("Unbekannt", TestCultures.de, CountryDisplayName.de))
.Should().NotThrow();
[Test]
public async Task es()
=> (await CountryDisplayName.Update("Desconocido", TestCultures.es, CountryDisplayName.es))
.Should().NotThrow();
[Test]
public async Task fr()
=> (await CountryDisplayName.Update("Inconnu", TestCultures.fr, CountryDisplayName.fr))
.Should().NotThrow();
[Test]
public async Task it()
=> (await CountryDisplayName.Update("Sconosciuto", TestCultures.it, CountryDisplayName.it))
.Should().NotThrow();
[Test]
public async Task ja()
=> (await CountryDisplayName.Update("不明", TestCultures.ja, CountryDisplayName.ja))
.Should().NotThrow();
[Test]
public async Task nl()
=> (await CountryDisplayName.Update("Onbekend",TestCultures.nl,CountryDisplayName.nl))
.Should().NotThrow();
[Test]
public async Task pt()
=> (await CountryDisplayName.Update("Não sabe", TestCultures.pt, CountryDisplayName.pt))
.Should().NotThrow();
[Test]
public async Task ru()
=> (await CountryDisplayName.Update("неизвестно", TestCultures.ru, CountryDisplayName.ru))
.Should().NotThrow();
[Test]
public async Task zh()
=> (await CountryDisplayName.Update("未知項", TestCultures.zh, CountryDisplayName.zh))
.Should().NotThrow();
}
}