From d770008448da4480b8200604509e5063856ce225 Mon Sep 17 00:00:00 2001 From: deanology Date: Sat, 29 Mar 2025 11:27:01 +0100 Subject: [PATCH 1/3] Add support for Faroe Islands, Fiji Islands, and Finland with corresponding unit tests --- .../Countries/FaroeIslandsTest.cs | 42 ++++++++++++++ .../Countries/FijiIslandsTest.cs | 42 ++++++++++++++ .../Countries/FinlandTest.cs | 41 +++++++++++++ src/World.Net/Countries/FaroeIslands.cs | 42 ++++++++++++++ src/World.Net/Countries/FijiIslands.cs | 51 +++++++++++++++++ src/World.Net/Countries/Finland.cs | 57 +++++++++++++++++++ src/World.Net/Helpers/CountryInitializer.cs | 3 + 7 files changed, 278 insertions(+) create mode 100644 src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs create mode 100644 src/World.Net.UnitTests/Countries/FijiIslandsTest.cs create mode 100644 src/World.Net.UnitTests/Countries/FinlandTest.cs create mode 100644 src/World.Net/Countries/FaroeIslands.cs create mode 100644 src/World.Net/Countries/FijiIslands.cs create mode 100644 src/World.Net/Countries/Finland.cs diff --git a/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs b/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs new file mode 100644 index 0000000..11a98b2 --- /dev/null +++ b/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs @@ -0,0 +1,42 @@ +namespace World.Net.UnitTests.Countries; + +public sealed class FaroeIslandsTest +{ + private const string FAROEISLANDS_COUNTRY_NAME = "Faroe Islands"; + private const string FAROEISLANDS_NATIVE_NAME = "Føroyar"; + private const string FAROEISLANDS_CAPITAL = "Tórshavn"; + private const string FAROEISLANDS_OFFICIAL_NAME = "Faroe Islands"; + private const string FAROEISLANDS_ISO2_CODE = "FO"; + private const string FAROEISLANDS_ISO3_CODE = "FRO"; + private const int FAROEISLANDS_NUMERIC_CODE = 234; + private const string FAROEISLANDS_CALLING_CODE = "+298"; + private const int FAROEISLANDS_STATE_COUNT = 6; // 6 regions + private static readonly string[] VALID_STATE_TYPES = { "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)); + } +} + + diff --git a/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs b/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs new file mode 100644 index 0000000..7cfc9be --- /dev/null +++ b/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs @@ -0,0 +1,42 @@ +namespace World.Net.UnitTests.Countries; + +public sealed class FijiIslandsTest +{ + private const string FIJI_COUNTRY_NAME = "Fiji"; + private const string FIJI_NATIVE_NAME = "Matanitu ko Viti"; + private const string FIJI_CAPITAL = "Suva"; + private const string FIJI_OFFICIAL_NAME = "Republic of Fiji"; + private const string FIJI_ISO2_CODE = "FJ"; + private const string FIJI_ISO3_CODE = "FJI"; + private const int FIJI_NUMERIC_CODE = 242; + private const 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" }; + + [Fact] + public void GetCountry_ReturnsCorrectInformation_ForFiji() + { + // Arrange + CountryIdentifier existingCountryId = CountryIdentifier.FijiIslands; + + // Act + var country = CountryProvider.GetCountry(existingCountryId); + + // 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)); + } +} + + diff --git a/src/World.Net.UnitTests/Countries/FinlandTest.cs b/src/World.Net.UnitTests/Countries/FinlandTest.cs new file mode 100644 index 0000000..d7b9a65 --- /dev/null +++ b/src/World.Net.UnitTests/Countries/FinlandTest.cs @@ -0,0 +1,41 @@ +namespace World.Net.UnitTests.Countries; + +public sealed class FinlandTest +{ + private const string FINLAND_COUNTRY_NAME = "Finland"; + private const string FINLAND_NATIVE_NAME = "Suomen tasavalta / Republiken Finland"; + private const string FINLAND_CAPITAL = "Helsinki"; + private const string FINLAND_OFFICIAL_NAME = "Republic of Finland"; + private const string FINLAND_ISO2_CODE = "FI"; + private const string FINLAND_ISO3_CODE = "FIN"; + private const int FINLAND_NUMERIC_CODE = 246; + private const string FINLAND_CALLING_CODE = "+358"; + private const int FINLAND_STATE_COUNT = 21; + private static readonly string[] VALID_STATE_TYPES = { "Region" }; + + [Fact] + public void GetCountry_ReturnsCorrectInformation_ForFinland() + { + // Arrange + CountryIdentifier existingCountryId = CountryIdentifier.Finland; + + // Act + var country = CountryProvider.GetCountry(existingCountryId); + + // Assert + Assert.NotNull(country); + Assert.Equal(existingCountryId, country.Id); + Assert.Equal(FINLAND_COUNTRY_NAME, country.Name); + Assert.Equal(FINLAND_OFFICIAL_NAME, country.OfficialName); + Assert.Equal(FINLAND_NATIVE_NAME, country.NativeName); + Assert.Equal(FINLAND_CAPITAL, country.Capital); + Assert.Equal(FINLAND_NUMERIC_CODE, country.NumericCode); + Assert.Equal(FINLAND_ISO2_CODE, country.ISO2Code); + Assert.Equal(FINLAND_ISO3_CODE, country.ISO3Code); + Assert.Equal(FINLAND_CALLING_CODE, country.CallingCode); + Assert.NotNull(country.States); + Assert.Equal(FINLAND_STATE_COUNT, country.States.Count()); + Assert.All(country.States, state => Assert.Contains(state.Type, VALID_STATE_TYPES)); + } +} + diff --git a/src/World.Net/Countries/FaroeIslands.cs b/src/World.Net/Countries/FaroeIslands.cs new file mode 100644 index 0000000..e53fae7 --- /dev/null +++ b/src/World.Net/Countries/FaroeIslands.cs @@ -0,0 +1,42 @@ +namespace World.Net.Countries; + +internal sealed class FaroeIslands : ICountry +{ + // + public CountryIdentifier Id => CountryIdentifier.FaroeIslands; + + // + public string Name { get; } = "Faroe Islands"; + + // + public string OfficialName { get; } = "Faroe Islands"; + + // + public string NativeName => "Føroyar"; + + // + public string Capital { get; } = "Tórshavn"; + + // + public int NumericCode { get; } = 234; + + // + public string ISO2Code { get; } = "FO"; + + // + public string ISO3Code { get; } = "FRO"; + + // + public string CallingCode { get; } = "+298"; + + // + public IEnumerable 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") + ]; +} diff --git a/src/World.Net/Countries/FijiIslands.cs b/src/World.Net/Countries/FijiIslands.cs new file mode 100644 index 0000000..8f9bc5c --- /dev/null +++ b/src/World.Net/Countries/FijiIslands.cs @@ -0,0 +1,51 @@ +namespace World.Net.Countries; + +internal sealed class FijiIslands : ICountry +{ + // + public CountryIdentifier Id => CountryIdentifier.FijiIslands; + + // + public string Name { get; } = "Fiji"; + + // + public string OfficialName { get; } = "Republic of Fiji"; + + // + public string NativeName => "Matanitu ko Viti"; + + // + public string Capital { get; } = "Suva"; + + // + public int NumericCode { get; } = 242; + + // + public string ISO2Code { get; } = "FJ"; + + // + public string ISO3Code { get; } = "FJI"; + + // + public string CallingCode { get; } = "+679"; + + // + public IEnumerable States => + [ + new("Ba", "FJ-01"), + new("Bua", "FJ-02"), + new("Cakaudrove", "FJ-03"), + new("Kadavu", "FJ-04"), + new("Lau", "FJ-05"), + new("Lomaiviti", "FJ-06"), + new("Macuata", "FJ-07"), + new("Nadroga-Navosa", "FJ-08"), + new("Naitasiri", "FJ-09"), + new("Namosi", "FJ-10"), + new("Ra", "FJ-11"), + new("Rewa", "FJ-12"), + new("Serua", "FJ-13"), + new("Tailevu", "FJ-14"), + new("Rotuma", "FJ-15", "Dependency") + ]; +} diff --git a/src/World.Net/Countries/Finland.cs b/src/World.Net/Countries/Finland.cs new file mode 100644 index 0000000..7d8738b --- /dev/null +++ b/src/World.Net/Countries/Finland.cs @@ -0,0 +1,57 @@ +namespace World.Net.Countries; + +internal sealed class Finland : ICountry +{ + // + public CountryIdentifier Id => CountryIdentifier.Finland; + + // + public string Name { get; } = "Finland"; + + // + public string OfficialName { get; } = "Republic of Finland"; + + // + public string NativeName => "Suomen tasavalta / Republiken Finland"; + + // + public string Capital { get; } = "Helsinki"; + + // + public int NumericCode { get; } = 246; + + // + public string ISO2Code { get; } = "FI"; + + // + public string ISO3Code { get; } = "FIN"; + + // + public string CallingCode { get; } = "+358"; + + // + public IEnumerable States => + [ + new("Åland", "FI-01", "Region"), + new("Central Finland", "FI-08", "Region"), + new("Central Ostrobothnia", "FI-07", "Region"), + new("Etelä-Karjala", "FI-02", "Region"), + new("Etelä-Pohjanmaa", "FI-03", "Region"), + new("Etelä-Savo", "FI-04", "Region"), + new("Kainuu", "FI-05", "Region"), + new("Kanta-Häme", "FI-06", "Region"), + new("Keski-Pohjanmaa", "FI-09", "Region"), + new("Keski-Suomi", "FI-10", "Region"), + new("Kymenlaakso", "FI-11", "Region"), + new("Lappi", "FI-12", "Region"), + new("Pirkanmaa", "FI-13", "Region"), + new("Pohjanmaa", "FI-14", "Region"), + new("Pohjois-Karjala", "FI-15", "Region"), + new("Pohjois-Pohjanmaa", "FI-16", "Region"), + new("Pohjois-Savo", "FI-17", "Region"), + new("Päijät-Häme", "FI-18", "Region"), + new("Satakunta", "FI-19", "Region"), + new("Uusimaa", "FI-20", "Region"), + new("Varsinais-Suomi", "FI-21", "Region") + ]; +} diff --git a/src/World.Net/Helpers/CountryInitializer.cs b/src/World.Net/Helpers/CountryInitializer.cs index b3747cf..bfeee73 100644 --- a/src/World.Net/Helpers/CountryInitializer.cs +++ b/src/World.Net/Helpers/CountryInitializer.cs @@ -68,6 +68,9 @@ public static Dictionary Initialize() { CountryIdentifier.TimorLeste, new TimorLeste() }, { CountryIdentifier.Ecuador, new Ecuador() }, { CountryIdentifier.Egypt, new Egypt() }, + { CountryIdentifier.FaroeIslands, new FaroeIslands() }, + { CountryIdentifier.FijiIslands, new FijiIslands() }, + { CountryIdentifier.Finland, new Finland() }, // Future countries can be added here in the same format. }; From 53054e3d6fe9c97580f01ccd3b2bda9830a70fc9 Mon Sep 17 00:00:00 2001 From: deanology Date: Tue, 8 Apr 2025 09:30:37 +0100 Subject: [PATCH 2/3] Refactor calling codes to use string arrays for Faroe Islands, Fiji Islands, and Finland --- src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs | 2 +- src/World.Net.UnitTests/Countries/FijiIslandsTest.cs | 2 +- src/World.Net.UnitTests/Countries/FinlandTest.cs | 2 +- src/World.Net/Countries/FaroeIslands.cs | 2 +- src/World.Net/Countries/FijiIslands.cs | 2 +- src/World.Net/Countries/Finland.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs b/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs index 11a98b2..227c50b 100644 --- a/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs +++ b/src/World.Net.UnitTests/Countries/FaroeIslandsTest.cs @@ -9,7 +9,7 @@ public sealed class FaroeIslandsTest private const string FAROEISLANDS_ISO2_CODE = "FO"; private const string FAROEISLANDS_ISO3_CODE = "FRO"; private const int FAROEISLANDS_NUMERIC_CODE = 234; - private const string FAROEISLANDS_CALLING_CODE = "+298"; + private readonly string[] FAROEISLANDS_CALLING_CODE = ["+298"]; private const int FAROEISLANDS_STATE_COUNT = 6; // 6 regions private static readonly string[] VALID_STATE_TYPES = { "Region" }; diff --git a/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs b/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs index 7cfc9be..49e111e 100644 --- a/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs +++ b/src/World.Net.UnitTests/Countries/FijiIslandsTest.cs @@ -9,7 +9,7 @@ public sealed class FijiIslandsTest private const string FIJI_ISO2_CODE = "FJ"; private const string FIJI_ISO3_CODE = "FJI"; private const int FIJI_NUMERIC_CODE = 242; - private const string FIJI_CALLING_CODE = "+679"; + 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" }; diff --git a/src/World.Net.UnitTests/Countries/FinlandTest.cs b/src/World.Net.UnitTests/Countries/FinlandTest.cs index d7b9a65..3b223c5 100644 --- a/src/World.Net.UnitTests/Countries/FinlandTest.cs +++ b/src/World.Net.UnitTests/Countries/FinlandTest.cs @@ -9,7 +9,7 @@ public sealed class FinlandTest private const string FINLAND_ISO2_CODE = "FI"; private const string FINLAND_ISO3_CODE = "FIN"; private const int FINLAND_NUMERIC_CODE = 246; - private const string FINLAND_CALLING_CODE = "+358"; + private readonly string[] FINLAND_CALLING_CODE = ["+358"]; private const int FINLAND_STATE_COUNT = 21; private static readonly string[] VALID_STATE_TYPES = { "Region" }; diff --git a/src/World.Net/Countries/FaroeIslands.cs b/src/World.Net/Countries/FaroeIslands.cs index e53fae7..0d6d47c 100644 --- a/src/World.Net/Countries/FaroeIslands.cs +++ b/src/World.Net/Countries/FaroeIslands.cs @@ -27,7 +27,7 @@ internal sealed class FaroeIslands : ICountry public string ISO3Code { get; } = "FRO"; // - public string CallingCode { get; } = "+298"; + public string[] CallingCode { get; } = ["+298"]; // public IEnumerable States => diff --git a/src/World.Net/Countries/FijiIslands.cs b/src/World.Net/Countries/FijiIslands.cs index 8f9bc5c..0a22236 100644 --- a/src/World.Net/Countries/FijiIslands.cs +++ b/src/World.Net/Countries/FijiIslands.cs @@ -27,7 +27,7 @@ internal sealed class FijiIslands : ICountry public string ISO3Code { get; } = "FJI"; // - public string CallingCode { get; } = "+679"; + public string[] CallingCode { get; } = ["+679"]; // public IEnumerable States => diff --git a/src/World.Net/Countries/Finland.cs b/src/World.Net/Countries/Finland.cs index 7d8738b..be510ac 100644 --- a/src/World.Net/Countries/Finland.cs +++ b/src/World.Net/Countries/Finland.cs @@ -27,7 +27,7 @@ internal sealed class Finland : ICountry public string ISO3Code { get; } = "FIN"; // - public string CallingCode { get; } = "+358"; + public string[] CallingCode { get; } = ["+358"]; // public IEnumerable States => From b16b27e047e4af1ff1017d49a0e39b90f2bd7306 Mon Sep 17 00:00:00 2001 From: deanology Date: Wed, 23 Apr 2025 19:45:53 +0100 Subject: [PATCH 3/3] Refactor: Re-add Denmark, Djibouti, Dominica entries Re-added entries for Denmark, Djibouti, and Dominica in the CountryInitializer dictionary. These changes do not affect functionality and may have been made for formatting or organizational purposes. --- src/World.Net/Helpers/CountryInitializer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/World.Net/Helpers/CountryInitializer.cs b/src/World.Net/Helpers/CountryInitializer.cs index 1c26be2..e898d83 100644 --- a/src/World.Net/Helpers/CountryInitializer.cs +++ b/src/World.Net/Helpers/CountryInitializer.cs @@ -64,6 +64,9 @@ public static Dictionary Initialize() { CountryIdentifier.Curacao, new Curaçao() }, { CountryIdentifier.Cyprus, new Cyprus() }, { CountryIdentifier.CzechRepublic, new CzechRepublic() }, + { CountryIdentifier.Denmark, new Denmark() }, + { CountryIdentifier.Djibouti, new Djibouti() }, + { CountryIdentifier.Dominica, new Dominica() }, { CountryIdentifier.DominicanRepublic, new DominicanRepublic() }, { CountryIdentifier.TimorLeste, new TimorLeste() }, { CountryIdentifier.Ecuador, new Ecuador() }, @@ -71,9 +74,6 @@ public static Dictionary Initialize() { CountryIdentifier.FaroeIslands, new FaroeIslands() }, { CountryIdentifier.FijiIslands, new FijiIslands() }, { CountryIdentifier.Finland, new Finland() }, - { CountryIdentifier.Denmark, new Denmark() }, - { CountryIdentifier.Djibouti, new Djibouti() }, - { CountryIdentifier.Dominica, new Dominica() }, { CountryIdentifier.France, new France() }, { CountryIdentifier.FrenchGuiana, new FrenchGuiana() }, { CountryIdentifier.FrenchPolynesia, new FrenchPolynesia() },