Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/World.Net.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@
Console.WriteLine($"Error: {ex.Message}");
}

PrintSeparator("Selected Countries");
var indentifiers = new List<CountryIdentifier>
{
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();
Expand Down
59 changes: 56 additions & 3 deletions src/World.Net.UnitTests/CountryProviderTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using World.Net.Helpers;

namespace World.Net.UnitTests;
namespace World.Net.UnitTests;

public sealed class CountryProviderTest
{
Expand Down Expand Up @@ -57,4 +55,59 @@ public void GetCountry_ShouldThrow_CountryNotFoundException_WhenCountryDoesNotEx
var exception = Assert.Throws<CountryNotFoundException>(() => 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>
{
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<CountryIdentifier>();

// 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>
{
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);
}
}
14 changes: 14 additions & 0 deletions src/World.Net/CountryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ public static ICountry GetCountry(CountryIdentifier countryIdentifier)

throw new CountryNotFoundException($"Country with id {countryIdentifier} was not found.");
}

/// <summary>
/// Retrieves multiple countries by their unique identifiers.
/// </summary>
/// <param name="countryIdentifiers">A collection of unique identifiers of the countries to retrieve.</param>
/// <returns>
/// A collection of <see cref="ICountry"/> instances corresponding to the specified <paramref name="countryIdentifiers"/>.
/// </returns>
public static IList<ICountry> GetCountries(IEnumerable<CountryIdentifier> countryIdentifiers)
{
var countries = _countries.Value.Where(x => countryIdentifiers.Contains(x.Key)).Select(x => x.Value);

return countries.ToList();
}
}
Loading