Skip to content

Commit 89fba3e

Browse files
authored
Merge pull request #44 from kaleem213/feature/add-kosovo-country-info
Add support for Kosovo (XK) in country info provider
2 parents b3d52da + 04172d3 commit 89fba3e

File tree

8 files changed

+250
-178
lines changed

8 files changed

+250
-178
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Nager.Country.Translation.CountryTranslations
2+
{
3+
/// <summary>
4+
/// Kosovo (partially recognized; not a UN member state)
5+
/// </summary>
6+
public class KosovoCountryTranslation : ICountryTranslation
7+
{
8+
/// <inheritdoc/>
9+
public TranslationInfo[] Translations => new []
10+
{
11+
new TranslationInfo(LanguageCode.DE, "Kosovo"),
12+
new TranslationInfo(LanguageCode.EN, "Kosovo"),
13+
new TranslationInfo(LanguageCode.ES, "Kosovo"),
14+
new TranslationInfo(LanguageCode.FR, "Kosovo"),
15+
new TranslationInfo(LanguageCode.IT, "Kosovo"),
16+
new TranslationInfo(LanguageCode.PT, "Kosovo"),
17+
};
18+
}
19+
}

src/Nager.Country.Translation/TranslationProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public TranslationProvider()
157157
this._alpha2Code2CountryTranslation.Add(Alpha2Code.KZ, new KazakhstanCountryTranslation());
158158
this._alpha2Code2CountryTranslation.Add(Alpha2Code.KE, new KenyaCountryTranslation());
159159
this._alpha2Code2CountryTranslation.Add(Alpha2Code.KI, new KiribatiCountryTranslation());
160+
this._alpha2Code2CountryTranslation.Add(Alpha2Code.XK, new KosovoCountryTranslation());
160161
this._alpha2Code2CountryTranslation.Add(Alpha2Code.KW, new KuwaitCountryTranslation());
161162
this._alpha2Code2CountryTranslation.Add(Alpha2Code.KG, new KyrgyzstanCountryTranslation());
162163
this._alpha2Code2CountryTranslation.Add(Alpha2Code.LA, new LaosCountryTranslation());

src/Nager.Country.UnitTest/CountryDataValidationTest.cs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,45 @@ public class CountryDataValidationTest
1717
[TestMethod]
1818
public async Task CompareWithMledozeCountryProject()
1919
{
20-
using (var httpClient = new HttpClient())
20+
var ignoreCountryCodes = new Alpha2Code[] { Alpha2Code.XK };
21+
22+
using var httpClient = new HttpClient();
23+
var json = await httpClient.GetStringAsync("https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json");
24+
var items = JsonConvert.DeserializeObject<MledozeCountry[]>(json);
25+
26+
ICountryProvider countryProvider = new CountryProvider();
27+
foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
2128
{
22-
var json = await httpClient.GetStringAsync("https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json");
23-
var items = JsonConvert.DeserializeObject<MledozeCountry[]>(json);
29+
if (ignoreCountryCodes.Contains(countryCode))
30+
{
31+
continue;
32+
}
2433

25-
ICountryProvider countryProvider = new CountryProvider();
26-
foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
34+
var countryInfo = countryProvider.GetCountry(countryCode);
35+
Trace.WriteLine($"check {countryInfo.CommonName}");
36+
if (countryInfo is null)
2737
{
28-
var countryInfo = countryProvider.GetCountry(countryCode);
29-
Trace.WriteLine($"check {countryInfo.CommonName}");
30-
if (countryInfo is null)
31-
{
32-
Assert.Fail($"countryInfo is null for {countryCode}");
33-
}
38+
Assert.Fail($"countryInfo is null for {countryCode}");
39+
}
3440

35-
var compareCountry = items.FirstOrDefault(o => o.Cca2.Equals(countryInfo.Alpha2Code.ToString()));
36-
if (compareCountry is null)
37-
{
38-
Assert.Inconclusive(countryCode.ToString());
39-
continue;
40-
}
41+
var compareCountry = items.FirstOrDefault(o => o.Cca2.Equals(countryInfo.Alpha2Code.ToString()));
42+
if (compareCountry is null)
43+
{
44+
Assert.Inconclusive(countryCode.ToString());
45+
continue;
46+
}
4147

42-
//TODO: Check how can check after change structure
43-
//countryInfo.Currencies
44-
// .Should()
45-
// .BeEquivalentTo(compareCountry.Currencies.ChildrenToke.Name.ToArray(),
46-
// because: $"{countryCode} {string.Join(",", compareCountry.Currencies.Keys)} {string.Join(",", countryInfo.Currencies)}");
48+
//TODO: Check how can check after change structure
49+
//countryInfo.Currencies
50+
// .Should()
51+
// .BeEquivalentTo(compareCountry.Currencies.ChildrenToke.Name.ToArray(),
52+
// because: $"{countryCode} {string.Join(",", compareCountry.Currencies.Keys)} {string.Join(",", countryInfo.Currencies)}");
4753

48-
Assert.AreEqual(compareCountry.Ccn3, countryInfo.NumericCode, $"wrong numeric code by {countryCode} {countryInfo.CommonName}");
49-
Assert.AreEqual(compareCountry.Region, countryInfo.Region.ToString(), $"wrong region by {countryCode} {countryInfo.CommonName}");
50-
//Assert.AreEqual(this.AdaptMledozeSubRegion(compareCountry.Subregion), this.GetSubRegion(countryInfo.SubRegion), $"wrong subregion by {countryCode} {countryInfo.CommonName}");
51-
Assert.AreEqual(compareCountry.Cca3, countryInfo.Alpha3Code.ToString(), $"wrong alpha 3 code by {countryCode} {countryInfo.CommonName}");
52-
Assert.AreEqual(compareCountry.Name.Common, countryInfo.CommonName.ToString(), $"wrong common name by {countryCode} {countryInfo.CommonName}");
53-
}
54+
Assert.AreEqual(compareCountry.Ccn3, countryInfo.NumericCode, $"wrong numeric code by {countryCode} {countryInfo.CommonName}");
55+
Assert.AreEqual(compareCountry.Region, countryInfo.Region.ToString(), $"wrong region by {countryCode} {countryInfo.CommonName}");
56+
//Assert.AreEqual(this.AdaptMledozeSubRegion(compareCountry.Subregion), this.GetSubRegion(countryInfo.SubRegion), $"wrong subregion by {countryCode} {countryInfo.CommonName}");
57+
Assert.AreEqual(compareCountry.Cca3, countryInfo.Alpha3Code.ToString(), $"wrong alpha 3 code by {countryCode} {countryInfo.CommonName}");
58+
Assert.AreEqual(compareCountry.Name.Common, countryInfo.CommonName.ToString(), $"wrong common name by {countryCode} {countryInfo.CommonName}");
5459
}
5560
}
5661

src/Nager.Country.UnitTest/TranslationTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public void DuplicateTranslationTest()
1616
foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
1717
{
1818
var countryTranslation = translationProvider.GetCountryTranslation(countryCode);
19+
if (countryTranslation is null)
20+
{
21+
Assert.Fail($"Missing country translation for {countryCode}");
22+
}
1923

2024
var duplicateTranslation = countryTranslation.Translations.GroupBy(o => o.LanguageCode).Any(o => o.Count() > 1);
2125
Assert.IsFalse(duplicateTranslation);

src/Nager.Country/Alpha2Code.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,10 @@ public enum Alpha2Code
477477
/// Korea, South
478478
/// </summary>
479479
KR,
480-
/*
481480
/// <summary>
482-
/// Kosovo
481+
/// Kosovo (partially recognized; not a UN member state)
483482
/// </summary>
484483
XK,
485-
*/
486484
/// <summary>
487485
/// Kuwait
488486
/// </summary>

src/Nager.Country/Alpha3Code.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,10 @@ public enum Alpha3Code
477477
/// Korea, South
478478
/// </summary>
479479
KOR,
480-
/*
481480
/// <summary>
482-
/// Kosovo
481+
/// Kosovo (partially recognized; not a UN member state)
483482
/// </summary>
484483
XKX,
485-
*/
486484
/// <summary>
487485
/// Kuwait
488486
/// </summary>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Nager.Country.Currencies;
2+
3+
namespace Nager.Country.CountryInfos
4+
{
5+
/// <summary>
6+
/// Kosovo (partially recognized; not a UN member state)
7+
/// </summary>
8+
public sealed class KosovoCountryInfo : ICountryInfo
9+
{
10+
/// <inheritdoc/>
11+
public string CommonName => "Kosovo";
12+
/// <inheritdoc/>
13+
public string OfficialName => "Republic of Kosovo";
14+
/// <inheritdoc/>
15+
public string NativeName => "Republika e Kosovës";
16+
/// <inheritdoc/>
17+
/// <remarks>User-assigned placeholder</remarks>
18+
public Alpha2Code Alpha2Code => Alpha2Code.XK;
19+
/// <inheritdoc/>
20+
/// <remarks>Common unofficial convention</remarks>
21+
public Alpha3Code Alpha3Code => Alpha3Code.XKX;
22+
/// <inheritdoc/>
23+
/// <remarks>No ISO numeric code yet</remarks>
24+
public int NumericCode => 0;
25+
/// <inheritdoc/>
26+
/// <remarks>Reserved, unofficial</remarks>
27+
public string[] TLD => new[] { ".xk" };
28+
/// <inheritdoc/>
29+
public Region Region => Region.Europe;
30+
/// <inheritdoc/>
31+
public SubRegion SubRegion => SubRegion.SouthernEurope;
32+
/// <inheritdoc/>
33+
public Alpha2Code[] BorderCountries => new[]
34+
{
35+
Alpha2Code.AL,
36+
Alpha2Code.ME,
37+
Alpha2Code.MK,
38+
Alpha2Code.RS
39+
};
40+
/// <inheritdoc/>
41+
/// <remarks>Euro used unilaterally</remarks>
42+
public ICurrency[] Currencies => new[] { new EurCurrency() };
43+
/// <inheritdoc/>
44+
public string[] CallingCodes => new[] { "383" };
45+
}
46+
}

0 commit comments

Comments
 (0)