From 38cd1cad3ba6dc5468b17e3f06e647c5514918fc Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 29 Dec 2025 10:54:19 +0100 Subject: [PATCH 1/3] feat: add GetSelectedCountries method to CountryProvider class --- src/World.Net/CountryProvider.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/World.Net/CountryProvider.cs b/src/World.Net/CountryProvider.cs index b38996a..caef0b0 100644 --- a/src/World.Net/CountryProvider.cs +++ b/src/World.Net/CountryProvider.cs @@ -55,4 +55,18 @@ public static ICountry GetCountry(CountryIdentifier countryIdentifier) throw new CountryNotFoundException($"Country with id {countryIdentifier} was not found."); } + + /// + /// Retrieves multiple countries by their unique identifiers. + /// + /// A collection of unique identifiers of the countries to retrieve. + /// + /// A collection of instances corresponding to the specified . + /// + public static IList GetCountries(IEnumerable countryIdentifiers) + { + var countries = _countries.Value.Where(x => countryIdentifiers.Contains(x.Key)).Select(x => x.Value); + + return countries.ToList(); + } } From 19a02ff3a4b11a9da945772b00d573fb2ac68435 Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 29 Dec 2025 10:54:53 +0100 Subject: [PATCH 2/3] add unit tests for selected countries --- .../CountryProviderTest.cs | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/src/World.Net.UnitTests/CountryProviderTest.cs b/src/World.Net.UnitTests/CountryProviderTest.cs index be5b089..8c56406 100644 --- a/src/World.Net.UnitTests/CountryProviderTest.cs +++ b/src/World.Net.UnitTests/CountryProviderTest.cs @@ -1,6 +1,4 @@ -using World.Net.Helpers; - -namespace World.Net.UnitTests; +namespace World.Net.UnitTests; public sealed class CountryProviderTest { @@ -57,4 +55,59 @@ public void GetCountry_ShouldThrow_CountryNotFoundException_WhenCountryDoesNotEx var exception = Assert.Throws(() => CountryProvider.GetCountry(nonExistingCountryId)); Assert.Equal($"Country with id {nonExistingCountryId} was not found.", exception.Message); } + + [Fact] + public void GetCountries_ValidIdentifiers_ReturnsCorrectCountries() + { + // Arrange + var indentifiers = new List + { + CountryIdentifier.Afghanistan, + CountryIdentifier.Brazil + }; + + // Act + var result = CountryProvider.GetCountries(indentifiers); + + // Assert + Assert.NotNull(result); + Assert.NotEmpty(result); + Assert.Equal(indentifiers.Count, result.Count); + } + + [Fact] + public void GetCountries_EmptyIdentifiers_ReturnsEmptyList() + { + // Arrange + var emptyIdentifiers = new List(); + + // Act + var result = CountryProvider.GetCountries(emptyIdentifiers); + + // Assert + Assert.Empty(result); + Assert.Equal(emptyIdentifiers.Count, result.Count); + } + + [Fact] + public void GetCountries_WhenIdentifiersContainDuplicates_ReturnsDistinctCountries() + { + // Arrange + var indentifiers = new List + { + CountryIdentifier.Afghanistan, + CountryIdentifier.Afghanistan, + CountryIdentifier.Argentina, + CountryIdentifier.Brazil, + CountryIdentifier.Brazil + }; + + // Act + var result = CountryProvider.GetCountries(indentifiers); + + // Assert + Assert.NotNull(result); + Assert.NotEmpty(result); + Assert.Equal(3, result.Count); + } } \ No newline at end of file From 840893d84444453a53220ad86a91882d7d29966b Mon Sep 17 00:00:00 2001 From: Raphael Anyanwu Date: Mon, 29 Dec 2025 10:55:15 +0100 Subject: [PATCH 3/3] test implementation in program class --- src/World.Net.Console/Program.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/World.Net.Console/Program.cs b/src/World.Net.Console/Program.cs index ed5e5e5..f2235f5 100644 --- a/src/World.Net.Console/Program.cs +++ b/src/World.Net.Console/Program.cs @@ -21,6 +21,24 @@ Console.WriteLine($"Error: {ex.Message}"); } +PrintSeparator("Selected Countries"); +var indentifiers = new List +{ + CountryIdentifier.Afghanistan, + CountryIdentifier.Armenia, + CountryIdentifier.Niger, + CountryIdentifier.Nigeria, + CountryIdentifier.Brazil +}; + +var selectedCountries = CountryProvider.GetCountries(indentifiers); +foreach (var country in selectedCountries) +{ + Console.WriteLine($"Name: {country.Name,-20} | Capital: {country.Capital}"); +} + +Console.WriteLine(); + Console.WriteLine(); Console.WriteLine("Press any key to exit..."); Console.ReadKey();