Skip to content

Commit a9bf284

Browse files
authored
introduce base class for unit tests to avoid code duplication (#79)
* add lebanon state details * add lesotho * add liberia * initialize lebanon, lesotho and liberia * add Liechtenstein * add Libya * initialize Liechtenstein and Libya * add Lesotho test * add lebanon test * add lithuania * add luxembourg * add Macausar * add Madagascar * initalize counties * add Liberia test case * update faroe islands test * update fiji test * update france tests * french guiana tests * add french polynesia test
1 parent 132e4be commit a9bf284

5 files changed

Lines changed: 243 additions & 94 deletions

File tree

src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
namespace World.Net.UnitTests.Countries;
1+
using System.Reflection.Metadata;
2+
using System.Xml.Linq;
23

3-
public sealed class FaroeIslandsTest
4+
namespace World.Net.UnitTests.Countries;
5+
6+
public sealed class FaroeIslandsTest : AssertCountryTestBase
47
{
8+
private static CountryIdentifier Id => CountryIdentifier.FaroeIslands;
59
private const string FAROEISLANDS_COUNTRY_NAME = "Faroe Islands";
610
private const string FAROEISLANDS_NATIVE_NAME = "Føroyar";
711
private const string FAROEISLANDS_CAPITAL = "Tórshavn";
@@ -10,32 +14,38 @@ public sealed class FaroeIslandsTest
1014
private const string FAROEISLANDS_ISO3_CODE = "FRO";
1115
private const int FAROEISLANDS_NUMERIC_CODE = 234;
1216
private readonly string[] FAROEISLANDS_CALLING_CODE = ["+298"];
13-
private const int FAROEISLANDS_STATE_COUNT = 6; // 6 regions
14-
private static readonly string[] VALID_STATE_TYPES = { "Region" };
17+
private static readonly (string Name, string IsoCode, string Type)[] States =
18+
[
19+
new("Eysturoy", "FO-01", "Region"),
20+
new("Norðoyar", "FO-02", "Region"),
21+
new("Sandoy", "FO-03", "Region"),
22+
new("Streymoy", "FO-04", "Region"),
23+
new("Suðuroy", "FO-05", "Region"),
24+
new("Vágar", "FO-06", "Region")
25+
];
1526

1627
[Fact]
1728
public void GetCountry_ReturnsCorrectInformation_ForFaroeIslands()
1829
{
1930
// Arrange
20-
CountryIdentifier existingCountryId = CountryIdentifier.FaroeIslands;
21-
2231
// Act
23-
var country = CountryProvider.GetCountry(existingCountryId);
2432

2533
// Assert
26-
Assert.NotNull(country);
27-
Assert.Equal(existingCountryId, country.Id);
28-
Assert.Equal(FAROEISLANDS_COUNTRY_NAME, country.Name);
29-
Assert.Equal(FAROEISLANDS_OFFICIAL_NAME, country.OfficialName);
30-
Assert.Equal(FAROEISLANDS_NATIVE_NAME, country.NativeName);
31-
Assert.Equal(FAROEISLANDS_CAPITAL, country.Capital);
32-
Assert.Equal(FAROEISLANDS_NUMERIC_CODE, country.NumericCode);
33-
Assert.Equal(FAROEISLANDS_ISO2_CODE, country.ISO2Code);
34-
Assert.Equal(FAROEISLANDS_ISO3_CODE, country.ISO3Code);
35-
Assert.Equal(FAROEISLANDS_CALLING_CODE, country.CallingCode);
36-
Assert.NotNull(country.States);
37-
Assert.Equal(FAROEISLANDS_STATE_COUNT, country.States.Count());
38-
Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES));
34+
var country = CountryProvider.GetCountry(Id);
35+
36+
AssertCorrectInformation(
37+
country,
38+
Id,
39+
FAROEISLANDS_COUNTRY_NAME,
40+
FAROEISLANDS_OFFICIAL_NAME,
41+
FAROEISLANDS_NATIVE_NAME,
42+
FAROEISLANDS_CAPITAL,
43+
FAROEISLANDS_NUMERIC_CODE,
44+
FAROEISLANDS_ISO2_CODE,
45+
FAROEISLANDS_ISO3_CODE,
46+
FAROEISLANDS_CALLING_CODE,
47+
States
48+
);
3949
}
4050
}
4151

src/World.Net.UnitTests/Countries/FijiIslandsTest.cs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace World.Net.UnitTests.Countries;
22

3-
public sealed class FijiIslandsTest
3+
public sealed class FijiIslandsTest : AssertCountryTestBase
44
{
55
private const string FIJI_COUNTRY_NAME = "Fiji";
66
private const string FIJI_NATIVE_NAME = "Matanitu ko Viti";
@@ -10,32 +10,47 @@ public sealed class FijiIslandsTest
1010
private const string FIJI_ISO3_CODE = "FJI";
1111
private const int FIJI_NUMERIC_CODE = 242;
1212
private readonly string[] FIJI_CALLING_CODE = ["+679"];
13-
private const int FIJI_STATE_COUNT = 15; // 14 provinces + 1 dependency
14-
private static readonly string[] VALID_STATE_TYPES = { "Province", "Dependency" };
13+
private const CountryIdentifier ExpectedId = CountryIdentifier.FijiIslands;
14+
private static readonly (string Name, string IsoCode, string Type)[] States =
15+
[
16+
new("Ba", "FJ-01", "Province"),
17+
new("Bua", "FJ-02", "Province"),
18+
new("Cakaudrove", "FJ-03", "Province"),
19+
new("Kadavu", "FJ-04", "Province"),
20+
new("Lau", "FJ-05", "Province"),
21+
new("Lomaiviti", "FJ-06", "Province"),
22+
new("Macuata", "FJ-07", "Province"),
23+
new("Nadroga-Navosa", "FJ-08", "Province"),
24+
new("Naitasiri", "FJ-09", "Province"),
25+
new("Namosi", "FJ-10", "Province"),
26+
new("Ra", "FJ-11", "Province"),
27+
new("Rewa", "FJ-12", "Province"),
28+
new("Serua", "FJ-13", "Province"),
29+
new("Tailevu", "FJ-14", "Province"),
30+
new("Rotuma", "FJ-15", "Dependency")
31+
];
1532

1633
[Fact]
1734
public void GetCountry_ReturnsCorrectInformation_ForFiji()
1835
{
1936
// Arrange
20-
CountryIdentifier existingCountryId = CountryIdentifier.FijiIslands;
21-
2237
// Act
23-
var country = CountryProvider.GetCountry(existingCountryId);
24-
38+
var country = CountryProvider.GetCountry(ExpectedId);
39+
2540
// Assert
26-
Assert.NotNull(country);
27-
Assert.Equal(existingCountryId, country.Id);
28-
Assert.Equal(FIJI_COUNTRY_NAME, country.Name);
29-
Assert.Equal(FIJI_OFFICIAL_NAME, country.OfficialName);
30-
Assert.Equal(FIJI_NATIVE_NAME, country.NativeName);
31-
Assert.Equal(FIJI_CAPITAL, country.Capital);
32-
Assert.Equal(FIJI_NUMERIC_CODE, country.NumericCode);
33-
Assert.Equal(FIJI_ISO2_CODE, country.ISO2Code);
34-
Assert.Equal(FIJI_ISO3_CODE, country.ISO3Code);
35-
Assert.Equal(FIJI_CALLING_CODE, country.CallingCode);
36-
Assert.NotNull(country.States);
37-
Assert.Equal(FIJI_STATE_COUNT, country.States.Count());
38-
Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES));
41+
AssertCorrectInformation(
42+
country,
43+
ExpectedId,
44+
FIJI_COUNTRY_NAME,
45+
FIJI_OFFICIAL_NAME,
46+
FIJI_NATIVE_NAME,
47+
FIJI_CAPITAL,
48+
FIJI_NUMERIC_CODE,
49+
FIJI_ISO2_CODE,
50+
FIJI_ISO3_CODE,
51+
FIJI_CALLING_CODE,
52+
States
53+
);
3954
}
4055
}
4156

Lines changed: 135 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,155 @@
11
namespace World.Net.UnitTests.Countries;
2-
public sealed class FranceTest
2+
public sealed class FranceTest : AssertCountryTestBase
33
{
44
private const string FRANCE_NAME = "France";
5-
private const int FRANCE_STATE_COUNT = 116;
65
private const string FRANCE_OFFICIAL_NAME = "French Republic";
76
private const string FRANCE_NATIVE_NAME = "France";
87
private const string FRANCE_CAPITAL = "Paris";
98
private const int FRANCE_NUMERIC_CODE = 250;
109
private const string FRANCE_ISO2_CODE = "FR";
11-
private static readonly string[] VALID_STATE_TYPES = { "metropolitan department", "European collectivity", "metropolitan region", "dependency", "metropolitan collectivity with special status", "overseas region", "overseas collectivity", "overseas territory", "overseas region", "metropolitan department", "metropolitan department", };
1210
private const string FRANCE_ISO3_CODE = "FRA";
1311
private readonly string[] FRANCE_CALLING_CODE = ["+33"];
14-
12+
private const CountryIdentifier ExpectedId = CountryIdentifier.France;
13+
private static readonly (string Name, string IsoCode, string Type)[] ExpectedStates =
14+
[
15+
new("Ain", "FR-01", "metropolitan department"),
16+
new("Aisne", "FR-02", "metropolitan department"),
17+
new("Allier", "FR-03", "metropolitan department"),
18+
new("Alpes-de-Haute-Provence", "FR-04", "metropolitan department"),
19+
new("Alpes-Maritimes", "FR-06", "metropolitan department"),
20+
new("Alsace", "FR-6AE", "European collectivity"),
21+
new("Ardèche", "FR-07", "metropolitan department"),
22+
new("Ardennes", "FR-08", "metropolitan department"),
23+
new("Ariège", "FR-09", "metropolitan department"),
24+
new("Aube", "FR-10", "metropolitan department"),
25+
new("Aude", "FR-11", "metropolitan department"),
26+
new("Auvergne-Rhône-Alpes", "FR-ARA", "metropolitan region"),
27+
new("Aveyron", "FR-12", "metropolitan department"),
28+
new("Bas-Rhin", "FR-67", "metropolitan department"),
29+
new("Bouches-du-Rhône", "FR-13", "metropolitan department"),
30+
new("Bourgogne-Franche-Comté", "FR-BFC", "metropolitan region"),
31+
new("Bretagne", "FR-BRE", "metropolitan region"),
32+
new("Calvados", "FR-14", "metropolitan department"),
33+
new("Cantal", "FR-15", "metropolitan department"),
34+
new("Centre-Val de Loire", "FR-CVL", "metropolitan region"),
35+
new("Charente", "FR-16", "metropolitan department"),
36+
new("Charente-Maritime", "FR-17", "metropolitan department"),
37+
new("Cher", "FR-18", "metropolitan department"),
38+
new("Clipperton", "FR-CP", "dependency"),
39+
new("Corrèze", "FR-19", "metropolitan department"),
40+
new("Corse", "FR-20R", "metropolitan collectivity with special status"),
41+
new("Corse-du-Sud", "FR-2A", "metropolitan department"),
42+
new("Côte-d'Or", "FR-21", "metropolitan department"),
43+
new("Côtes-d'Armor", "FR-22", "metropolitan department"),
44+
new("Creuse", "FR-23", "metropolitan department"),
45+
new("Deux-Sèvres", "FR-79", "metropolitan department"),
46+
new("Dordogne", "FR-24", "metropolitan department"),
47+
new("Doubs", "FR-25", "metropolitan department"),
48+
new("Drôme", "FR-26", "metropolitan department"),
49+
new("Essonne", "FR-91", "metropolitan department"),
50+
new("Eure", "FR-27", "metropolitan department"),
51+
new("Eure-et-Loir", "FR-28", "metropolitan department"),
52+
new("Finistère", "FR-29", "metropolitan department"),
53+
new("French Guiana", "FR-973", "overseas region"),
54+
new("French Polynesia", "FR-PF", "overseas collectivity"),
55+
new("French Southern and Antarctic Lands", "FR-TF", "overseas territory"),
56+
new("Gard", "FR-30", "metropolitan department"),
57+
new("Gers", "FR-32", "metropolitan department"),
58+
new("Gironde", "FR-33", "metropolitan department"),
59+
new("Grand-Est", "FR-GES", "metropolitan region"),
60+
new("Guadeloupe", "FR-971", "overseas region"),
61+
new("Haut-Rhin", "FR-68", "metropolitan department"),
62+
new("Haute-Corse", "FR-2B", "metropolitan department"),
63+
new("Haute-Garonne", "FR-31", "metropolitan department"),
64+
new("Haute-Loire", "FR-43", "metropolitan department"),
65+
new("Haute-Marne", "FR-52", "metropolitan department"),
66+
new("Haute-Saône", "FR-70", "metropolitan department"),
67+
new("Haute-Savoie", "FR-74", "metropolitan department"),
68+
new("Haute-Vienne", "FR-87", "metropolitan department"),
69+
new("Hautes-Alpes", "FR-05", "metropolitan department"),
70+
new("Hautes-Pyrénées", "FR-65", "metropolitan department"),
71+
new("Hauts-de-France", "FR-HDF", "metropolitan region"),
72+
new("Hauts-de-Seine", "FR-92", "metropolitan department"),
73+
new("Hérault", "FR-34", "metropolitan department"),
74+
new("Île-de-France", "FR-IDF", "metropolitan region"),
75+
new("Ille-et-Vilaine", "FR-35", "metropolitan department"),
76+
new("Indre", "FR-36", "metropolitan department"),
77+
new("Indre-et-Loire", "FR-37", "metropolitan department"),
78+
new("Isère", "FR-38", "metropolitan department"),
79+
new("Jura", "FR-39", "metropolitan department"),
80+
new("La Réunion", "FR-974", "overseas region"),
81+
new("Landes", "FR-40", "metropolitan department"),
82+
new("Loir-et-Cher", "FR-41", "metropolitan department"),
83+
new("Loire", "FR-42", "metropolitan department"),
84+
new("Loire-Atlantique", "FR-44", "metropolitan department"),
85+
new("Loiret", "FR-45", "metropolitan department"),
86+
new("Lot", "FR-46", "metropolitan department"),
87+
new("Lot-et-Garonne", "FR-47", "metropolitan department"),
88+
new("Lozère", "FR-48", "metropolitan department"),
89+
new("Maine-et-Loire", "FR-49", "metropolitan department"),
90+
new("Manche", "FR-50", "metropolitan department"),
91+
new("Marne", "FR-51", "metropolitan department"),
92+
new("Martinique", "FR-972", "overseas region"),
93+
new("Mayenne", "FR-53", "metropolitan department"),
94+
new("Mayotte", "FR-976", "overseas region"),
95+
new("Métropole de Lyon", "FR-69M", "metropolitan department"),
96+
new("Meurthe-et-Moselle", "FR-54", "metropolitan department"),
97+
new("Meuse", "FR-55", "metropolitan department"),
98+
new("Morbihan", "FR-56", "metropolitan department"),
99+
new("Moselle", "FR-57", "metropolitan department"),
100+
new("Nièvre", "FR-58", "metropolitan department"),
101+
new("Nord", "FR-59", "metropolitan department"),
102+
new("Oise", "FR-60", "metropolitan department"),
103+
new("Oléron", "FR-OL", "dependency"),
104+
new("Orne", "FR-61", "metropolitan department"),
105+
new("Paris", "FR-75", "metropolitan department"),
106+
new("Pas-de-Calais", "FR-62", "metropolitan department"),
107+
new("Puy-de-Dôme", "FR-63", "metropolitan department"),
108+
new("Pyrénées-Atlantiques", "FR-64", "metropolitan department"),
109+
new("Pyrénées-Orientales", "FR-66", "metropolitan department"),
110+
new("Réunion", "FR-974", "overseas region"),
111+
new("Rhône", "FR-69", "metropolitan department"),
112+
new("Saône-et-Loire", "FR-71", "metropolitan department"),
113+
new("Sarthe", "FR-72", "metropolitan department"),
114+
new("Savoie", "FR-73", "metropolitan department"),
115+
new("Seine-et-Marne", "FR-77", "metropolitan department"),
116+
new("Seine-Maritime", "FR-76", "metropolitan department"),
117+
new("Yvelines", "FR-78", "metropolitan department"),
118+
new("Somme", "FR-80", "metropolitan department"),
119+
new("Tarn", "FR-81", "metropolitan department"),
120+
new("Tarn-et-Garonne", "FR-82", "metropolitan department"),
121+
new("Territoire de Belfort", "FR-90", "metropolitan department"),
122+
new("Val-de-Marne", "FR-94", "metropolitan department"),
123+
new("Val-d'Oise", "FR-95", "metropolitan department"),
124+
new("Var", "FR-83", "metropolitan department"),
125+
new("Vaucluse", "FR-84", "metropolitan department"),
126+
new("Vendée", "FR-85", "metropolitan department"),
127+
new("Vienne", "FR-86", "metropolitan department"),
128+
new("Vosges", "FR-88", "metropolitan department"),
129+
new("Yonne", "FR-89", "metropolitan department"),
130+
new("Yvelines", "FR-78", "metropolitan department")
131+
];
15132

16133
[Fact]
17134
public void GetCountry_ReturnsCorrectInformation_ForFrance()
18135
{
19136
// Arrange
20-
CountryIdentifier existingCountryId = CountryIdentifier.France;
21-
22137
// Act
23-
var country = CountryProvider.GetCountry(existingCountryId);
138+
var country = CountryProvider.GetCountry(ExpectedId);
24139

25140
//Assert
26-
Assert.Equal(existingCountryId, country.Id);
27-
Assert.Equal(FRANCE_NAME, country.Name);
28-
Assert.NotNull(country.States);
29-
Assert.Equal(FRANCE_STATE_COUNT, country.States.Count());
30-
Assert.Equal(FRANCE_OFFICIAL_NAME, country.OfficialName);
31-
Assert.Equal(FRANCE_NATIVE_NAME, country.NativeName);
32-
Assert.Equal(FRANCE_CAPITAL, country.Capital);
33-
Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES));
34-
Assert.Equal(FRANCE_NUMERIC_CODE, country.NumericCode);
35-
Assert.Equal(FRANCE_ISO2_CODE, country.ISO2Code);
36-
Assert.Equal(FRANCE_ISO3_CODE, country.ISO3Code);
37-
Assert.Equal(FRANCE_CALLING_CODE, country.CallingCode);
141+
AssertCorrectInformation(
142+
country,
143+
ExpectedId,
144+
FRANCE_NAME,
145+
FRANCE_OFFICIAL_NAME,
146+
FRANCE_NATIVE_NAME,
147+
FRANCE_CAPITAL,
148+
FRANCE_NUMERIC_CODE,
149+
FRANCE_ISO2_CODE,
150+
FRANCE_ISO3_CODE,
151+
FRANCE_CALLING_CODE,
152+
ExpectedStates
153+
);
38154
}
39155
}
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace World.Net.UnitTests.Countries;
2-
public sealed class FrenchGuianaTest
2+
public sealed class FrenchGuianaTest : AssertCountryTestBase
33
{
44
private const string FRENCH_GUIANA_NAME = "French Guiana";
55
private const string FRENCH_GUIANA_OFFICIAL_NAME = "Guyane française";
@@ -9,28 +9,31 @@ public sealed class FrenchGuianaTest
99
private const string FRENCH_GUIANA_ISO2_CODE = "GF";
1010
private const string FRENCH_GUIANA_ISO3_CODE = "GUF";
1111
private readonly string[] FRENCH_GUIANA_CALLING_CODE = ["+594"];
12-
12+
private const CountryIdentifier ExpectedId = CountryIdentifier.FrenchGuiana;
13+
private static readonly (string Name, string IsoCode, string Type)[] ExpectedStates =
14+
[
15+
];
1316

1417
[Fact]
1518
public void GetCountry_ReturnsCorrectInformation_ForFrench_Guiana()
1619
{
1720
// Arrange
18-
CountryIdentifier existingCountryId = CountryIdentifier.FrenchGuiana;
19-
2021
// Act
21-
var country = CountryProvider.GetCountry(existingCountryId);
22+
var country = CountryProvider.GetCountry(ExpectedId);
2223

2324
//Assert
24-
Assert.Equal(existingCountryId, country.Id);
25-
Assert.Equal(FRENCH_GUIANA_NAME, country.Name);
26-
Assert.NotNull(country.States);
27-
Assert.Empty(country.States);
28-
Assert.Equal(FRENCH_GUIANA_OFFICIAL_NAME, country.OfficialName);
29-
Assert.Equal(FRENCH_GUIANA_NATIVE_NAME, country.NativeName);
30-
Assert.Equal(FRENCH_GUIANA_CAPITAL, country.Capital);
31-
Assert.Equal(FRENCH_GUIANA_NUMERIC_CODE, country.NumericCode);
32-
Assert.Equal(FRENCH_GUIANA_ISO2_CODE, country.ISO2Code);
33-
Assert.Equal(FRENCH_GUIANA_ISO3_CODE, country.ISO3Code);
34-
Assert.Equal(FRENCH_GUIANA_CALLING_CODE, country.CallingCode);
25+
AssertCorrectInformation(
26+
country,
27+
ExpectedId,
28+
FRENCH_GUIANA_NAME,
29+
FRENCH_GUIANA_OFFICIAL_NAME,
30+
FRENCH_GUIANA_NATIVE_NAME,
31+
FRENCH_GUIANA_CAPITAL,
32+
FRENCH_GUIANA_NUMERIC_CODE,
33+
FRENCH_GUIANA_ISO2_CODE,
34+
FRENCH_GUIANA_ISO3_CODE,
35+
FRENCH_GUIANA_CALLING_CODE,
36+
ExpectedStates
37+
);
3538
}
3639
}

0 commit comments

Comments
 (0)