From 14439f13e57d779501a6ae016cdf7832c9cc000e Mon Sep 17 00:00:00 2001 From: deanology Date: Wed, 5 Mar 2025 20:23:42 +0100 Subject: [PATCH 1/3] new details for some countries --- .../Countries/ChristmasIslandTest.cs | 40 +++++++++++ .../Countries/CocosKeelingIslandsTest.cs | 40 +++++++++++ .../Countries/ColombiaTest.cs | 40 +++++++++++ .../Countries/ComorosTest.cs | 40 +++++++++++ src/World.Net/Countries/ChristmasIsland.cs | 37 ++++++++++ .../Countries/CocosKeelingIslands.cs | 38 +++++++++++ src/World.Net/Countries/Colombia.cs | 68 +++++++++++++++++++ src/World.Net/Countries/Comoros.cs | 39 +++++++++++ src/World.Net/Helpers/CountryIdentifier.cs | 2 +- src/World.Net/Helpers/CountryInitializer.cs | 6 +- 10 files changed, 348 insertions(+), 2 deletions(-) create mode 100644 src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs create mode 100644 src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs create mode 100644 src/World.Net.UnitTests/Countries/ColombiaTest.cs create mode 100644 src/World.Net.UnitTests/Countries/ComorosTest.cs create mode 100644 src/World.Net/Countries/ChristmasIsland.cs create mode 100644 src/World.Net/Countries/CocosKeelingIslands.cs create mode 100644 src/World.Net/Countries/Colombia.cs create mode 100644 src/World.Net/Countries/Comoros.cs diff --git a/src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs b/src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs new file mode 100644 index 0000000..5e38097 --- /dev/null +++ b/src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs @@ -0,0 +1,40 @@ +namespace World.Net.UnitTests.Countries; + +public sealed class ChristmasIslandTest +{ + private const string CHRISTMAS_ISLAND_COUNTRY_NAME = "Christmas Island"; + private const string CHRISTMAS_ISLAND_NATIVE_NAME = "Christmas Island"; + private const string CHRISTMAS_ISLAND_CAPITAL = "Flying Fish Cove"; + private const string CHRISTMAS_ISLAND_OFFICIAL_NAME = "Territory of Christmas Island"; + private const string CHRISTMAS_ISLAND_ISO2_CODE = "CX"; + private const string CHRISTMAS_ISLAND_ISO3_CODE = "CXR"; + private const int CHRISTMAS_ISLAND_NUMERIC_CODE = 162; + private const string CHRISTMAS_ISLAND_CALLING_CODE = "+61"; + private const int CHRISTMAS_ISLAND_STATE_COUNT = 0; // No administrative divisions + private static readonly string[] VALID_STATE_TYPES = { }; + + [Fact] + public void GetCountry_ReturnsCorrectInformation_ForChristmasIsland() + { + // Arrange + CountryIdentifier existingCountryId = CountryIdentifier.ChristmasIsland; + + // Act + var country = CountryProvider.GetCountry(existingCountryId); + + // Assert + Assert.NotNull(country); + Assert.Equal(existingCountryId, country.Id); + Assert.Equal(CHRISTMAS_ISLAND_COUNTRY_NAME, country.Name); + Assert.Equal(CHRISTMAS_ISLAND_OFFICIAL_NAME, country.OfficialName); + Assert.Equal(CHRISTMAS_ISLAND_NATIVE_NAME, country.NativeName); + Assert.Equal(CHRISTMAS_ISLAND_CAPITAL, country.Capital); + Assert.Equal(CHRISTMAS_ISLAND_NUMERIC_CODE, country.NumericCode); + Assert.Equal(CHRISTMAS_ISLAND_ISO2_CODE, country.ISO2Code); + Assert.Equal(CHRISTMAS_ISLAND_ISO3_CODE, country.ISO3Code); + Assert.Equal(CHRISTMAS_ISLAND_CALLING_CODE, country.CallingCode); + Assert.NotNull(country.States); + Assert.Equal(CHRISTMAS_ISLAND_STATE_COUNT, country.States.Count()); + Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); + } +} diff --git a/src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs b/src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs new file mode 100644 index 0000000..0b2e1a9 --- /dev/null +++ b/src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs @@ -0,0 +1,40 @@ +namespace World.Net.UnitTests.Countries; + +public sealed class CocosKeelingIslandsTest +{ + private const string COCOS_COUNTRY_NAME = "Cocos (Keeling) Islands"; + private const string COCOS_NATIVE_NAME = "Pulu Kokos (Malay)"; + private const string COCOS_CAPITAL = "West Island"; + private const string COCOS_OFFICIAL_NAME = "Territory of Cocos (Keeling) Islands"; + private const string COCOS_ISO2_CODE = "CC"; + private const string COCOS_ISO3_CODE = "CCK"; + private const int COCOS_NUMERIC_CODE = 166; + private const string COCOS_CALLING_CODE = "+61"; + private const int COCOS_STATE_COUNT = 2; + private static readonly string[] VALID_STATE_TYPES = { "Island" }; + + [Fact] + public void GetCountry_ReturnsCorrectInformation_ForCocosKeelingIslands() + { + // Arrange + CountryIdentifier existingCountryId = CountryIdentifier.CocosKeelingIslands; + + // Act + var country = CountryProvider.GetCountry(existingCountryId); + + // Assert + Assert.NotNull(country); + Assert.Equal(existingCountryId, country.Id); + Assert.Equal(COCOS_COUNTRY_NAME, country.Name); + Assert.Equal(COCOS_OFFICIAL_NAME, country.OfficialName); + Assert.Equal(COCOS_NATIVE_NAME, country.NativeName); + Assert.Equal(COCOS_CAPITAL, country.Capital); + Assert.Equal(COCOS_NUMERIC_CODE, country.NumericCode); + Assert.Equal(COCOS_ISO2_CODE, country.ISO2Code); + Assert.Equal(COCOS_ISO3_CODE, country.ISO3Code); + Assert.Equal(COCOS_CALLING_CODE, country.CallingCode); + Assert.NotNull(country.States); + Assert.Equal(COCOS_STATE_COUNT, country.States.Count()); + Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); + } +} \ No newline at end of file diff --git a/src/World.Net.UnitTests/Countries/ColombiaTest.cs b/src/World.Net.UnitTests/Countries/ColombiaTest.cs new file mode 100644 index 0000000..4a6ac11 --- /dev/null +++ b/src/World.Net.UnitTests/Countries/ColombiaTest.cs @@ -0,0 +1,40 @@ +namespace World.Net.UnitTests.Countries; + +public sealed class ColombiaTest +{ + private const string COLOMBIA_COUNTRY_NAME = "Colombia"; + private const string COLOMBIA_NATIVE_NAME = "Colombia"; + private const string COLOMBIA_CAPITAL = "Bogotá"; + private const string COLOMBIA_OFFICIAL_NAME = "Republic of Colombia"; + private const string COLOMBIA_ISO2_CODE = "CO"; + private const string COLOMBIA_ISO3_CODE = "COL"; + private const int COLOMBIA_NUMERIC_CODE = 170; + private const string COLOMBIA_CALLING_CODE = "+57"; + private const int COLOMBIA_STATE_COUNT = 33; + private static readonly string[] VALID_STATE_TYPES = { "Department", "Capital District" }; + + [Fact] + public void GetCountry_ReturnsCorrectInformation_ForColombia() + { + // Arrange + CountryIdentifier existingCountryId = CountryIdentifier.Colombia; + + // Act + var country = CountryProvider.GetCountry(existingCountryId); + + // Assert + Assert.NotNull(country); + Assert.Equal(existingCountryId, country.Id); + Assert.Equal(COLOMBIA_COUNTRY_NAME, country.Name); + Assert.Equal(COLOMBIA_OFFICIAL_NAME, country.OfficialName); + Assert.Equal(COLOMBIA_NATIVE_NAME, country.NativeName); + Assert.Equal(COLOMBIA_CAPITAL, country.Capital); + Assert.Equal(COLOMBIA_NUMERIC_CODE, country.NumericCode); + Assert.Equal(COLOMBIA_ISO2_CODE, country.ISO2Code); + Assert.Equal(COLOMBIA_ISO3_CODE, country.ISO3Code); + Assert.Equal(COLOMBIA_CALLING_CODE, country.CallingCode); + Assert.NotNull(country.States); + Assert.Equal(COLOMBIA_STATE_COUNT, country.States.Count()); + Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); + } +} diff --git a/src/World.Net.UnitTests/Countries/ComorosTest.cs b/src/World.Net.UnitTests/Countries/ComorosTest.cs new file mode 100644 index 0000000..a1f82e6 --- /dev/null +++ b/src/World.Net.UnitTests/Countries/ComorosTest.cs @@ -0,0 +1,40 @@ +namespace World.Net.UnitTests.Countries; + +public sealed class ComorosTest +{ + private const string COMOROS_COUNTRY_NAME = "Comoros"; + private const string COMOROS_NATIVE_NAME = "Komori"; + private const string COMOROS_CAPITAL = "Moroni"; + private const string COMOROS_OFFICIAL_NAME = "Union of the Comoros"; + private const string COMOROS_ISO2_CODE = "KM"; + private const string COMOROS_ISO3_CODE = "COM"; + private const int COMOROS_NUMERIC_CODE = 174; + private const string COMOROS_CALLING_CODE = "+269"; + private const int COMOROS_STATE_COUNT = 3; + private static readonly string[] VALID_STATE_TYPES = { "Autonomous Island" }; + + [Fact] + public void GetCountry_ReturnsCorrectInformation_ForComoros() + { + // Arrange + CountryIdentifier existingCountryId = CountryIdentifier.Comoros; + + // Act + var country = CountryProvider.GetCountry(existingCountryId); + + // Assert + Assert.NotNull(country); + Assert.Equal(existingCountryId, country.Id); + Assert.Equal(COMOROS_COUNTRY_NAME, country.Name); + Assert.Equal(COMOROS_OFFICIAL_NAME, country.OfficialName); + Assert.Equal(COMOROS_NATIVE_NAME, country.NativeName); + Assert.Equal(COMOROS_CAPITAL, country.Capital); + Assert.Equal(COMOROS_NUMERIC_CODE, country.NumericCode); + Assert.Equal(COMOROS_ISO2_CODE, country.ISO2Code); + Assert.Equal(COMOROS_ISO3_CODE, country.ISO3Code); + Assert.Equal(COMOROS_CALLING_CODE, country.CallingCode); + Assert.NotNull(country.States); + Assert.Equal(COMOROS_STATE_COUNT, country.States.Count()); + Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); + } +} diff --git a/src/World.Net/Countries/ChristmasIsland.cs b/src/World.Net/Countries/ChristmasIsland.cs new file mode 100644 index 0000000..7f3d412 --- /dev/null +++ b/src/World.Net/Countries/ChristmasIsland.cs @@ -0,0 +1,37 @@ +namespace World.Net.Countries; + +internal sealed class ChristmasIsland : ICountry +{ + // + public CountryIdentifier Id => CountryIdentifier.ChristmasIsland; + + // + public string Name { get; } = "Christmas Island"; + + // + public string OfficialName { get; } = "Territory of Christmas Island"; + + // + public string NativeName => "Christmas Island"; + + // + public string Capital { get; } = "Flying Fish Cove"; + + // + public int NumericCode { get; } = 162; + + // + public string ISO2Code { get; } = "CX"; + + // + public string ISO3Code { get; } = "CXR"; + + // + public string CallingCode { get; } = "+61"; + + // + public IEnumerable States => + [ + + ]; +} diff --git a/src/World.Net/Countries/CocosKeelingIslands.cs b/src/World.Net/Countries/CocosKeelingIslands.cs new file mode 100644 index 0000000..4690f91 --- /dev/null +++ b/src/World.Net/Countries/CocosKeelingIslands.cs @@ -0,0 +1,38 @@ +namespace World.Net.Countries; + +internal sealed class CocosKeelingIslands : ICountry +{ + // + public CountryIdentifier Id => CountryIdentifier.CocosKeelingIslands; + + // + public string Name { get; } = "Cocos (Keeling) Islands"; + + // + public string OfficialName { get; } = "Territory of Cocos (Keeling) Islands"; + + // + public string NativeName => "Pulu Kokos (Malay)"; + + // + public string Capital { get; } = "West Island"; + + // + public int NumericCode { get; } = 166; + + // + public string ISO2Code { get; } = "CC"; + + // + public string ISO3Code { get; } = "CCK"; + + // + public string CallingCode { get; } = "+61"; + + // + public IEnumerable States => + [ + new("West Island", "CC-WI", "Island"), + new("Home Island", "CC-HI", "Island") + ]; +} diff --git a/src/World.Net/Countries/Colombia.cs b/src/World.Net/Countries/Colombia.cs new file mode 100644 index 0000000..9467f0d --- /dev/null +++ b/src/World.Net/Countries/Colombia.cs @@ -0,0 +1,68 @@ +namespace World.Net.Countries; + +internal sealed class Colombia : ICountry +{ + // + public CountryIdentifier Id => CountryIdentifier.Colombia; + + // + public string Name { get; } = "Colombia"; + + // + public string OfficialName { get; } = "Republic of Colombia"; + + // + public string NativeName => "Colombia"; + + // + public string Capital { get; } = "Bogotá"; + + // + public int NumericCode { get; } = 170; + + // + public string ISO2Code { get; } = "CO"; + + // + public string ISO3Code { get; } = "COL"; + + // + public string CallingCode { get; } = "+57"; + + // + public IEnumerable States => + [ + new("Amazonas", "CO-AMA", "Department"), + new("Antioquia", "CO-ANT", "Department"), + new("Arauca", "CO-ARA", "Department"), + new("Atlántico", "CO-ATL", "Department"), + new("Bolívar", "CO-BOL", "Department"), + new("Boyacá", "CO-BOY", "Department"), + new("Caldas", "CO-CAL", "Department"), + new("Caquetá", "CO-CAQ", "Department"), + new("Casanare", "CO-CAS", "Department"), + new("Cauca", "CO-CAU", "Department"), + new("Cesar", "CO-CES", "Department"), + new("Chocó", "CO-CHO", "Department"), + new("Córdoba", "CO-COR", "Department"), + new("Cundinamarca", "CO-CUN", "Department"), + new("Guainía", "CO-GUA", "Department"), + new("Guaviare", "CO-GUV", "Department"), + new("Huila", "CO-HUI", "Department"), + new("La Guajira", "CO-LAG", "Department"), + new("Magdalena", "CO-MAG", "Department"), + new("Meta", "CO-MET", "Department"), + new("Nariño", "CO-NAR", "Department"), + new("Norte de Santander", "CO-NSA", "Department"), + new("Putumayo", "CO-PUT", "Department"), + new("Quindío", "CO-QUI", "Department"), + new("Risaralda", "CO-RIS", "Department"), + new("San Andrés, Providencia and Santa Catalina", "CO-SAP", "Department"), + new("Santander", "CO-SAN", "Department"), + new("Sucre", "CO-SUC", "Department"), + new("Tolima", "CO-TOL", "Department"), + new("Valle del Cauca", "CO-VAC", "Department"), + new("Vaupés", "CO-VAU", "Department"), + new("Vichada", "CO-VIC", "Department") + ]; +} diff --git a/src/World.Net/Countries/Comoros.cs b/src/World.Net/Countries/Comoros.cs new file mode 100644 index 0000000..2a1d83e --- /dev/null +++ b/src/World.Net/Countries/Comoros.cs @@ -0,0 +1,39 @@ +namespace World.Net.Countries; + +internal sealed class Comoros : ICountry +{ + // + public CountryIdentifier Id => CountryIdentifier.Comoros; + + // + public string Name { get; } = "Comoros"; + + // + public string OfficialName { get; } = "Union of the Comoros"; + + // + public string NativeName => "Komori"; + + // + public string Capital { get; } = "Moroni"; + + // + public int NumericCode { get; } = 174; + + // + public string ISO2Code { get; } = "KM"; + + // + public string ISO3Code { get; } = "COM"; + + // + public string CallingCode { get; } = "+269"; + + // + public IEnumerable States => + [ + new("Anjouan", "KM-A", "Autonomous Island"), + new("Grande Comore", "KM-G", "Autonomous Island"), + new("Mohéli", "KM-M", "Autonomous Island") + ]; +} diff --git a/src/World.Net/Helpers/CountryIdentifier.cs b/src/World.Net/Helpers/CountryIdentifier.cs index 446d70b..3ba73e2 100644 --- a/src/World.Net/Helpers/CountryIdentifier.cs +++ b/src/World.Net/Helpers/CountryIdentifier.cs @@ -17,7 +17,7 @@ public enum CountryIdentifier /// /// Use this identifier to reference Afghanistan in operations that require a country ID. /// - Afghanistan = 1, + Afghanistan, /// /// The unique identifier for Aland Islands. diff --git a/src/World.Net/Helpers/CountryInitializer.cs b/src/World.Net/Helpers/CountryInitializer.cs index cc6cb53..893be47 100644 --- a/src/World.Net/Helpers/CountryInitializer.cs +++ b/src/World.Net/Helpers/CountryInitializer.cs @@ -45,7 +45,11 @@ public static Dictionary Initialize() { CountryIdentifier.Cambodia, new Cambodia() }, { CountryIdentifier.Cameroon, new Cameroon() }, { CountryIdentifier.Canada, new Canada() }, - { CountryIdentifier.CapeVerde, new CapeVerde() }, + { CountryIdentifier.CapeVerde, new CapeVerde() }, + { CountryIdentifier.ChristmasIsland, new ChristmasIsland() }, + { CountryIdentifier.CocosKeelingIslands, new CocosKeelingIslands() }, + { CountryIdentifier.Colombia, new Colombia() }, + { CountryIdentifier.Comoros, new Comoros() }, // Future countries can be added here in the same format. }; From c296ab7905d4d0777908fe892a1d15a5dfc65406 Mon Sep 17 00:00:00 2001 From: deanology Date: Wed, 5 Mar 2025 23:23:18 +0100 Subject: [PATCH 2/3] fixed test bug --- src/World.Net.UnitTests/Countries/ColombiaTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/World.Net.UnitTests/Countries/ColombiaTest.cs b/src/World.Net.UnitTests/Countries/ColombiaTest.cs index 4a6ac11..5ef0f12 100644 --- a/src/World.Net.UnitTests/Countries/ColombiaTest.cs +++ b/src/World.Net.UnitTests/Countries/ColombiaTest.cs @@ -10,7 +10,7 @@ public sealed class ColombiaTest private const string COLOMBIA_ISO3_CODE = "COL"; private const int COLOMBIA_NUMERIC_CODE = 170; private const string COLOMBIA_CALLING_CODE = "+57"; - private const int COLOMBIA_STATE_COUNT = 33; + private const int COLOMBIA_STATE_COUNT = 32; private static readonly string[] VALID_STATE_TYPES = { "Department", "Capital District" }; [Fact] From 7666506c7d2435ebba2cf23b40a8639177dfe839 Mon Sep 17 00:00:00 2001 From: deanology Date: Mon, 10 Mar 2025 23:53:44 +0100 Subject: [PATCH 3/3] Resolve PR comments --- src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs | 3 +-- src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs | 2 +- src/World.Net/Helpers/CountryIdentifier.cs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs b/src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs index 5e38097..804615d 100644 --- a/src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs +++ b/src/World.Net.UnitTests/Countries/ChristmasIslandTest.cs @@ -10,7 +10,6 @@ public sealed class ChristmasIslandTest private const string CHRISTMAS_ISLAND_ISO3_CODE = "CXR"; private const int CHRISTMAS_ISLAND_NUMERIC_CODE = 162; private const string CHRISTMAS_ISLAND_CALLING_CODE = "+61"; - private const int CHRISTMAS_ISLAND_STATE_COUNT = 0; // No administrative divisions private static readonly string[] VALID_STATE_TYPES = { }; [Fact] @@ -34,7 +33,7 @@ public void GetCountry_ReturnsCorrectInformation_ForChristmasIsland() Assert.Equal(CHRISTMAS_ISLAND_ISO3_CODE, country.ISO3Code); Assert.Equal(CHRISTMAS_ISLAND_CALLING_CODE, country.CallingCode); Assert.NotNull(country.States); - Assert.Equal(CHRISTMAS_ISLAND_STATE_COUNT, country.States.Count()); + Assert.Empty(country.States); Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); } } diff --git a/src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs b/src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs index 0b2e1a9..adc1c97 100644 --- a/src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs +++ b/src/World.Net.UnitTests/Countries/CocosKeelingIslandsTest.cs @@ -37,4 +37,4 @@ public void GetCountry_ReturnsCorrectInformation_ForCocosKeelingIslands() Assert.Equal(COCOS_STATE_COUNT, country.States.Count()); Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); } -} \ No newline at end of file +} diff --git a/src/World.Net/Helpers/CountryIdentifier.cs b/src/World.Net/Helpers/CountryIdentifier.cs index 3ba73e2..446d70b 100644 --- a/src/World.Net/Helpers/CountryIdentifier.cs +++ b/src/World.Net/Helpers/CountryIdentifier.cs @@ -17,7 +17,7 @@ public enum CountryIdentifier /// /// Use this identifier to reference Afghanistan in operations that require a country ID. /// - Afghanistan, + Afghanistan = 1, /// /// The unique identifier for Aland Islands.