diff --git a/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs b/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs index 227c50b..cde71c8 100644 --- a/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs +++ b/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs @@ -1,7 +1,11 @@ -namespace World.Net.UnitTests.Countries; +using System.Reflection.Metadata; +using System.Xml.Linq; -public sealed class FaroeIslandsTest +namespace World.Net.UnitTests.Countries; + +public sealed class FaroeIslandsTest : AssertCountryTestBase { + private static CountryIdentifier Id => CountryIdentifier.FaroeIslands; private const string FAROEISLANDS_COUNTRY_NAME = "Faroe Islands"; private const string FAROEISLANDS_NATIVE_NAME = "Føroyar"; private const string FAROEISLANDS_CAPITAL = "Tórshavn"; @@ -10,32 +14,38 @@ public sealed class FaroeIslandsTest private const string FAROEISLANDS_ISO3_CODE = "FRO"; private const int FAROEISLANDS_NUMERIC_CODE = 234; private readonly string[] FAROEISLANDS_CALLING_CODE = ["+298"]; - private const int FAROEISLANDS_STATE_COUNT = 6; // 6 regions - private static readonly string[] VALID_STATE_TYPES = { "Region" }; + private static readonly (string Name, string IsoCode, string Type)[] States = + [ + new("Eysturoy", "FO-01", "Region"), + new("Norðoyar", "FO-02", "Region"), + new("Sandoy", "FO-03", "Region"), + new("Streymoy", "FO-04", "Region"), + new("Suðuroy", "FO-05", "Region"), + new("Vágar", "FO-06", "Region") + ]; [Fact] public void GetCountry_ReturnsCorrectInformation_ForFaroeIslands() { // Arrange - CountryIdentifier existingCountryId = CountryIdentifier.FaroeIslands; - // Act - var country = CountryProvider.GetCountry(existingCountryId); // Assert - Assert.NotNull(country); - Assert.Equal(existingCountryId, country.Id); - Assert.Equal(FAROEISLANDS_COUNTRY_NAME, country.Name); - Assert.Equal(FAROEISLANDS_OFFICIAL_NAME, country.OfficialName); - Assert.Equal(FAROEISLANDS_NATIVE_NAME, country.NativeName); - Assert.Equal(FAROEISLANDS_CAPITAL, country.Capital); - Assert.Equal(FAROEISLANDS_NUMERIC_CODE, country.NumericCode); - Assert.Equal(FAROEISLANDS_ISO2_CODE, country.ISO2Code); - Assert.Equal(FAROEISLANDS_ISO3_CODE, country.ISO3Code); - Assert.Equal(FAROEISLANDS_CALLING_CODE, country.CallingCode); - Assert.NotNull(country.States); - Assert.Equal(FAROEISLANDS_STATE_COUNT, country.States.Count()); - Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); + var country = CountryProvider.GetCountry(Id); + + AssertCorrectInformation( + country, + Id, + FAROEISLANDS_COUNTRY_NAME, + FAROEISLANDS_OFFICIAL_NAME, + FAROEISLANDS_NATIVE_NAME, + FAROEISLANDS_CAPITAL, + FAROEISLANDS_NUMERIC_CODE, + FAROEISLANDS_ISO2_CODE, + FAROEISLANDS_ISO3_CODE, + FAROEISLANDS_CALLING_CODE, + States + ); } } diff --git a/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs b/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs index 49e111e..5652b56 100644 --- a/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs +++ b/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs @@ -1,6 +1,6 @@ namespace World.Net.UnitTests.Countries; -public sealed class FijiIslandsTest +public sealed class FijiIslandsTest : AssertCountryTestBase { private const string FIJI_COUNTRY_NAME = "Fiji"; private const string FIJI_NATIVE_NAME = "Matanitu ko Viti"; @@ -10,32 +10,47 @@ public sealed class FijiIslandsTest private const string FIJI_ISO3_CODE = "FJI"; private const int FIJI_NUMERIC_CODE = 242; private readonly string[] FIJI_CALLING_CODE = ["+679"]; - private const int FIJI_STATE_COUNT = 15; // 14 provinces + 1 dependency - private static readonly string[] VALID_STATE_TYPES = { "Province", "Dependency" }; + private const CountryIdentifier ExpectedId = CountryIdentifier.FijiIslands; + private static readonly (string Name, string IsoCode, string Type)[] States = + [ + new("Ba", "FJ-01", "Province"), + new("Bua", "FJ-02", "Province"), + new("Cakaudrove", "FJ-03", "Province"), + new("Kadavu", "FJ-04", "Province"), + new("Lau", "FJ-05", "Province"), + new("Lomaiviti", "FJ-06", "Province"), + new("Macuata", "FJ-07", "Province"), + new("Nadroga-Navosa", "FJ-08", "Province"), + new("Naitasiri", "FJ-09", "Province"), + new("Namosi", "FJ-10", "Province"), + new("Ra", "FJ-11", "Province"), + new("Rewa", "FJ-12", "Province"), + new("Serua", "FJ-13", "Province"), + new("Tailevu", "FJ-14", "Province"), + new("Rotuma", "FJ-15", "Dependency") + ]; [Fact] public void GetCountry_ReturnsCorrectInformation_ForFiji() { // Arrange - CountryIdentifier existingCountryId = CountryIdentifier.FijiIslands; - // Act - var country = CountryProvider.GetCountry(existingCountryId); - + var country = CountryProvider.GetCountry(ExpectedId); + // Assert - Assert.NotNull(country); - Assert.Equal(existingCountryId, country.Id); - Assert.Equal(FIJI_COUNTRY_NAME, country.Name); - Assert.Equal(FIJI_OFFICIAL_NAME, country.OfficialName); - Assert.Equal(FIJI_NATIVE_NAME, country.NativeName); - Assert.Equal(FIJI_CAPITAL, country.Capital); - Assert.Equal(FIJI_NUMERIC_CODE, country.NumericCode); - Assert.Equal(FIJI_ISO2_CODE, country.ISO2Code); - Assert.Equal(FIJI_ISO3_CODE, country.ISO3Code); - Assert.Equal(FIJI_CALLING_CODE, country.CallingCode); - Assert.NotNull(country.States); - Assert.Equal(FIJI_STATE_COUNT, country.States.Count()); - Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); + AssertCorrectInformation( + country, + ExpectedId, + FIJI_COUNTRY_NAME, + FIJI_OFFICIAL_NAME, + FIJI_NATIVE_NAME, + FIJI_CAPITAL, + FIJI_NUMERIC_CODE, + FIJI_ISO2_CODE, + FIJI_ISO3_CODE, + FIJI_CALLING_CODE, + States + ); } } diff --git a/src/World.Net.UnitTests/Countries/FranceTest.cs b/src/World.Net.UnitTests/Countries/FranceTest.cs index 1fbc3b0..2b0f716 100644 --- a/src/World.Net.UnitTests/Countries/FranceTest.cs +++ b/src/World.Net.UnitTests/Countries/FranceTest.cs @@ -1,39 +1,155 @@ namespace World.Net.UnitTests.Countries; -public sealed class FranceTest +public sealed class FranceTest : AssertCountryTestBase { private const string FRANCE_NAME = "France"; - private const int FRANCE_STATE_COUNT = 116; private const string FRANCE_OFFICIAL_NAME = "French Republic"; private const string FRANCE_NATIVE_NAME = "France"; private const string FRANCE_CAPITAL = "Paris"; private const int FRANCE_NUMERIC_CODE = 250; private const string FRANCE_ISO2_CODE = "FR"; - 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", }; private const string FRANCE_ISO3_CODE = "FRA"; private readonly string[] FRANCE_CALLING_CODE = ["+33"]; - + private const CountryIdentifier ExpectedId = CountryIdentifier.France; + private static readonly (string Name, string IsoCode, string Type)[] ExpectedStates = + [ + new("Ain", "FR-01", "metropolitan department"), + new("Aisne", "FR-02", "metropolitan department"), + new("Allier", "FR-03", "metropolitan department"), + new("Alpes-de-Haute-Provence", "FR-04", "metropolitan department"), + new("Alpes-Maritimes", "FR-06", "metropolitan department"), + new("Alsace", "FR-6AE", "European collectivity"), + new("Ardèche", "FR-07", "metropolitan department"), + new("Ardennes", "FR-08", "metropolitan department"), + new("Ariège", "FR-09", "metropolitan department"), + new("Aube", "FR-10", "metropolitan department"), + new("Aude", "FR-11", "metropolitan department"), + new("Auvergne-Rhône-Alpes", "FR-ARA", "metropolitan region"), + new("Aveyron", "FR-12", "metropolitan department"), + new("Bas-Rhin", "FR-67", "metropolitan department"), + new("Bouches-du-Rhône", "FR-13", "metropolitan department"), + new("Bourgogne-Franche-Comté", "FR-BFC", "metropolitan region"), + new("Bretagne", "FR-BRE", "metropolitan region"), + new("Calvados", "FR-14", "metropolitan department"), + new("Cantal", "FR-15", "metropolitan department"), + new("Centre-Val de Loire", "FR-CVL", "metropolitan region"), + new("Charente", "FR-16", "metropolitan department"), + new("Charente-Maritime", "FR-17", "metropolitan department"), + new("Cher", "FR-18", "metropolitan department"), + new("Clipperton", "FR-CP", "dependency"), + new("Corrèze", "FR-19", "metropolitan department"), + new("Corse", "FR-20R", "metropolitan collectivity with special status"), + new("Corse-du-Sud", "FR-2A", "metropolitan department"), + new("Côte-d'Or", "FR-21", "metropolitan department"), + new("Côtes-d'Armor", "FR-22", "metropolitan department"), + new("Creuse", "FR-23", "metropolitan department"), + new("Deux-Sèvres", "FR-79", "metropolitan department"), + new("Dordogne", "FR-24", "metropolitan department"), + new("Doubs", "FR-25", "metropolitan department"), + new("Drôme", "FR-26", "metropolitan department"), + new("Essonne", "FR-91", "metropolitan department"), + new("Eure", "FR-27", "metropolitan department"), + new("Eure-et-Loir", "FR-28", "metropolitan department"), + new("Finistère", "FR-29", "metropolitan department"), + new("French Guiana", "FR-973", "overseas region"), + new("French Polynesia", "FR-PF", "overseas collectivity"), + new("French Southern and Antarctic Lands", "FR-TF", "overseas territory"), + new("Gard", "FR-30", "metropolitan department"), + new("Gers", "FR-32", "metropolitan department"), + new("Gironde", "FR-33", "metropolitan department"), + new("Grand-Est", "FR-GES", "metropolitan region"), + new("Guadeloupe", "FR-971", "overseas region"), + new("Haut-Rhin", "FR-68", "metropolitan department"), + new("Haute-Corse", "FR-2B", "metropolitan department"), + new("Haute-Garonne", "FR-31", "metropolitan department"), + new("Haute-Loire", "FR-43", "metropolitan department"), + new("Haute-Marne", "FR-52", "metropolitan department"), + new("Haute-Saône", "FR-70", "metropolitan department"), + new("Haute-Savoie", "FR-74", "metropolitan department"), + new("Haute-Vienne", "FR-87", "metropolitan department"), + new("Hautes-Alpes", "FR-05", "metropolitan department"), + new("Hautes-Pyrénées", "FR-65", "metropolitan department"), + new("Hauts-de-France", "FR-HDF", "metropolitan region"), + new("Hauts-de-Seine", "FR-92", "metropolitan department"), + new("Hérault", "FR-34", "metropolitan department"), + new("Île-de-France", "FR-IDF", "metropolitan region"), + new("Ille-et-Vilaine", "FR-35", "metropolitan department"), + new("Indre", "FR-36", "metropolitan department"), + new("Indre-et-Loire", "FR-37", "metropolitan department"), + new("Isère", "FR-38", "metropolitan department"), + new("Jura", "FR-39", "metropolitan department"), + new("La Réunion", "FR-974", "overseas region"), + new("Landes", "FR-40", "metropolitan department"), + new("Loir-et-Cher", "FR-41", "metropolitan department"), + new("Loire", "FR-42", "metropolitan department"), + new("Loire-Atlantique", "FR-44", "metropolitan department"), + new("Loiret", "FR-45", "metropolitan department"), + new("Lot", "FR-46", "metropolitan department"), + new("Lot-et-Garonne", "FR-47", "metropolitan department"), + new("Lozère", "FR-48", "metropolitan department"), + new("Maine-et-Loire", "FR-49", "metropolitan department"), + new("Manche", "FR-50", "metropolitan department"), + new("Marne", "FR-51", "metropolitan department"), + new("Martinique", "FR-972", "overseas region"), + new("Mayenne", "FR-53", "metropolitan department"), + new("Mayotte", "FR-976", "overseas region"), + new("Métropole de Lyon", "FR-69M", "metropolitan department"), + new("Meurthe-et-Moselle", "FR-54", "metropolitan department"), + new("Meuse", "FR-55", "metropolitan department"), + new("Morbihan", "FR-56", "metropolitan department"), + new("Moselle", "FR-57", "metropolitan department"), + new("Nièvre", "FR-58", "metropolitan department"), + new("Nord", "FR-59", "metropolitan department"), + new("Oise", "FR-60", "metropolitan department"), + new("Oléron", "FR-OL", "dependency"), + new("Orne", "FR-61", "metropolitan department"), + new("Paris", "FR-75", "metropolitan department"), + new("Pas-de-Calais", "FR-62", "metropolitan department"), + new("Puy-de-Dôme", "FR-63", "metropolitan department"), + new("Pyrénées-Atlantiques", "FR-64", "metropolitan department"), + new("Pyrénées-Orientales", "FR-66", "metropolitan department"), + new("Réunion", "FR-974", "overseas region"), + new("Rhône", "FR-69", "metropolitan department"), + new("Saône-et-Loire", "FR-71", "metropolitan department"), + new("Sarthe", "FR-72", "metropolitan department"), + new("Savoie", "FR-73", "metropolitan department"), + new("Seine-et-Marne", "FR-77", "metropolitan department"), + new("Seine-Maritime", "FR-76", "metropolitan department"), + new("Yvelines", "FR-78", "metropolitan department"), + new("Somme", "FR-80", "metropolitan department"), + new("Tarn", "FR-81", "metropolitan department"), + new("Tarn-et-Garonne", "FR-82", "metropolitan department"), + new("Territoire de Belfort", "FR-90", "metropolitan department"), + new("Val-de-Marne", "FR-94", "metropolitan department"), + new("Val-d'Oise", "FR-95", "metropolitan department"), + new("Var", "FR-83", "metropolitan department"), + new("Vaucluse", "FR-84", "metropolitan department"), + new("Vendée", "FR-85", "metropolitan department"), + new("Vienne", "FR-86", "metropolitan department"), + new("Vosges", "FR-88", "metropolitan department"), + new("Yonne", "FR-89", "metropolitan department"), + new("Yvelines", "FR-78", "metropolitan department") + ]; [Fact] public void GetCountry_ReturnsCorrectInformation_ForFrance() { // Arrange - CountryIdentifier existingCountryId = CountryIdentifier.France; - // Act - var country = CountryProvider.GetCountry(existingCountryId); + var country = CountryProvider.GetCountry(ExpectedId); //Assert - Assert.Equal(existingCountryId, country.Id); - Assert.Equal(FRANCE_NAME, country.Name); - Assert.NotNull(country.States); - Assert.Equal(FRANCE_STATE_COUNT, country.States.Count()); - Assert.Equal(FRANCE_OFFICIAL_NAME, country.OfficialName); - Assert.Equal(FRANCE_NATIVE_NAME, country.NativeName); - Assert.Equal(FRANCE_CAPITAL, country.Capital); - Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); - Assert.Equal(FRANCE_NUMERIC_CODE, country.NumericCode); - Assert.Equal(FRANCE_ISO2_CODE, country.ISO2Code); - Assert.Equal(FRANCE_ISO3_CODE, country.ISO3Code); - Assert.Equal(FRANCE_CALLING_CODE, country.CallingCode); + AssertCorrectInformation( + country, + ExpectedId, + FRANCE_NAME, + FRANCE_OFFICIAL_NAME, + FRANCE_NATIVE_NAME, + FRANCE_CAPITAL, + FRANCE_NUMERIC_CODE, + FRANCE_ISO2_CODE, + FRANCE_ISO3_CODE, + FRANCE_CALLING_CODE, + ExpectedStates + ); } } diff --git a/src/World.Net.UnitTests/Countries/FrenchGuianaTest.cs b/src/World.Net.UnitTests/Countries/FrenchGuianaTest.cs index 5ac1398..b77a1a4 100644 --- a/src/World.Net.UnitTests/Countries/FrenchGuianaTest.cs +++ b/src/World.Net.UnitTests/Countries/FrenchGuianaTest.cs @@ -1,5 +1,5 @@ namespace World.Net.UnitTests.Countries; -public sealed class FrenchGuianaTest +public sealed class FrenchGuianaTest : AssertCountryTestBase { private const string FRENCH_GUIANA_NAME = "French Guiana"; private const string FRENCH_GUIANA_OFFICIAL_NAME = "Guyane française"; @@ -9,28 +9,31 @@ public sealed class FrenchGuianaTest private const string FRENCH_GUIANA_ISO2_CODE = "GF"; private const string FRENCH_GUIANA_ISO3_CODE = "GUF"; private readonly string[] FRENCH_GUIANA_CALLING_CODE = ["+594"]; - + private const CountryIdentifier ExpectedId = CountryIdentifier.FrenchGuiana; + private static readonly (string Name, string IsoCode, string Type)[] ExpectedStates = + [ + ]; [Fact] public void GetCountry_ReturnsCorrectInformation_ForFrench_Guiana() { // Arrange - CountryIdentifier existingCountryId = CountryIdentifier.FrenchGuiana; - // Act - var country = CountryProvider.GetCountry(existingCountryId); + var country = CountryProvider.GetCountry(ExpectedId); //Assert - Assert.Equal(existingCountryId, country.Id); - Assert.Equal(FRENCH_GUIANA_NAME, country.Name); - Assert.NotNull(country.States); - Assert.Empty(country.States); - Assert.Equal(FRENCH_GUIANA_OFFICIAL_NAME, country.OfficialName); - Assert.Equal(FRENCH_GUIANA_NATIVE_NAME, country.NativeName); - Assert.Equal(FRENCH_GUIANA_CAPITAL, country.Capital); - Assert.Equal(FRENCH_GUIANA_NUMERIC_CODE, country.NumericCode); - Assert.Equal(FRENCH_GUIANA_ISO2_CODE, country.ISO2Code); - Assert.Equal(FRENCH_GUIANA_ISO3_CODE, country.ISO3Code); - Assert.Equal(FRENCH_GUIANA_CALLING_CODE, country.CallingCode); + AssertCorrectInformation( + country, + ExpectedId, + FRENCH_GUIANA_NAME, + FRENCH_GUIANA_OFFICIAL_NAME, + FRENCH_GUIANA_NATIVE_NAME, + FRENCH_GUIANA_CAPITAL, + FRENCH_GUIANA_NUMERIC_CODE, + FRENCH_GUIANA_ISO2_CODE, + FRENCH_GUIANA_ISO3_CODE, + FRENCH_GUIANA_CALLING_CODE, + ExpectedStates + ); } } diff --git a/src/World.Net.UnitTests/Countries/FrenchPolynesiaTest.cs b/src/World.Net.UnitTests/Countries/FrenchPolynesiaTest.cs index ae83044..25dd97b 100644 --- a/src/World.Net.UnitTests/Countries/FrenchPolynesiaTest.cs +++ b/src/World.Net.UnitTests/Countries/FrenchPolynesiaTest.cs @@ -1,39 +1,44 @@ namespace World.Net.UnitTests.Countries; -public sealed class FrenchPolynesiaTest +public sealed class FrenchPolynesiaTest : AssertCountryTestBase { private const string FRENCH_POLYNESIA_NAME = "French Polynesia"; - private const int FRENCH_POLYNESIA_STATE_COUNT = 5; private const string FRENCH_POLYNESIA_OFFICIAL_NAME = "Polynésie française"; private const string FRENCH_POLYNESIA_NATIVE_NAME = "Polynésie française"; private const string FRENCH_POLYNESIA_CAPITAL = "Papeete"; private const int FRENCH_POLYNESIA_NUMERIC_CODE = 258; private const string FRENCH_POLYNESIA_ISO2_CODE = "PF"; private const string FRENCH_POLYNESIA_ISO3_CODE = "PYF"; - private static readonly string[] VALID_STATE_TYPES = { "division" }; private readonly string[] FRENCH_POLYNESIA_CALLING_CODE = ["+689"]; - + private const CountryIdentifier ExpectedId = CountryIdentifier.FrenchPolynesia; + private static readonly (string Name, string IsoCode, string Type)[] ExpectedStates = [ + ("N'Austral Islands", "PF-01", "division"), + ("Leeward Islands", "PF-02", "division"), + ("Marquesas Islands", "PF-03", "division"), + ("Tuamotu-Gambier", "PF-04", "division"), + ("Windward Islands", "PF-05", "division"), + ]; [Fact] public void GetCountry_ReturnsCorrectInformation_ForFrench_Polynesia() { // Arrange - CountryIdentifier existingCountryId = CountryIdentifier.FrenchPolynesia; - // Act - var country = CountryProvider.GetCountry(existingCountryId); + var country = CountryProvider.GetCountry(ExpectedId); //Assert - Assert.Equal(existingCountryId, country.Id); - Assert.Equal(FRENCH_POLYNESIA_NAME, country.Name); - Assert.NotNull(country.States); - Assert.Equal(FRENCH_POLYNESIA_STATE_COUNT, country.States.Count()); - Assert.Equal(FRENCH_POLYNESIA_OFFICIAL_NAME, country.OfficialName); - Assert.Equal(FRENCH_POLYNESIA_NATIVE_NAME, country.NativeName); - Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); - Assert.Equal(FRENCH_POLYNESIA_CAPITAL, country.Capital); - Assert.Equal(FRENCH_POLYNESIA_NUMERIC_CODE, country.NumericCode); - Assert.Equal(FRENCH_POLYNESIA_ISO2_CODE, country.ISO2Code); - Assert.Equal(FRENCH_POLYNESIA_ISO3_CODE, country.ISO3Code); - Assert.Equal(FRENCH_POLYNESIA_CALLING_CODE, country.CallingCode); + + AssertCorrectInformation( + country, + ExpectedId, + FRENCH_POLYNESIA_NAME, + FRENCH_POLYNESIA_OFFICIAL_NAME, + FRENCH_POLYNESIA_NATIVE_NAME, + FRENCH_POLYNESIA_CAPITAL, + FRENCH_POLYNESIA_NUMERIC_CODE, + FRENCH_POLYNESIA_ISO2_CODE, + FRENCH_POLYNESIA_ISO3_CODE, + FRENCH_POLYNESIA_CALLING_CODE, + ExpectedStates + ); } }