Skip to content

Commit 80a743c

Browse files
committed
Fixed #16 added the possibility to get a couuntry's flag in the form of an emoji.
1 parent 2ad881e commit 80a743c

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/CountryData.Standard/CountryHelper.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public class CountryHelper
1010
{
1111
private readonly IEnumerable<Country> _Countries;
1212
private const string strFileName = "CountryData.Standard.data.json";
13+
1314
public CountryHelper()
1415
{
1516
var json = GetJsonData(strFileName);
1617
_Countries = JsonConvert.DeserializeObject<List<Country>>(json);
1718
}
1819

19-
2020
private string GetJsonData(string path)
2121
{
2222
string json = "";
@@ -51,6 +51,15 @@ public Country GetCountryByCode(string shortCode)
5151
return _Countries.SingleOrDefault(c => c.CountryShortCode == shortCode);
5252
}
5353

54+
/// <summary>
55+
/// Gets the flag of the country, in the form of an emoji.
56+
/// </summary>
57+
/// <param name="country"></param>
58+
/// <returns></returns>
59+
public string GetCountryEmojiFlag(string shortCode)
60+
{
61+
return string.Concat(shortCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
62+
}
5463

5564
/// <summary>
5665
/// Selects Regions in a Particular Country

test/CountryData.UnitTests/CountryHelperTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CountryData.Standard;
1+
using CountryData.Standard;
22
using FluentAssertions;
33
using System.Collections.Generic;
44
using Xunit;
@@ -34,6 +34,25 @@ public void GetCountryByCode_WithCorrectCode_ShouldReturnCountry(string shortCod
3434
country.CountryShortCode.Should().Be(shortCode);
3535
}
3636

37+
[Theory]
38+
[InlineData("GH")]
39+
[InlineData("CM")]
40+
[InlineData("US")]
41+
public void GetCountryFlagByCode_WithCorrectCode_ShouldReturnEmojiFlag(string shortCode)
42+
{
43+
//Act
44+
var countryFlag = _countryHelper.GetCountryEmojiFlag(shortCode);
45+
46+
//Assert
47+
countryFlag.Should().NotBeNull();
48+
if (shortCode == "GH")
49+
countryFlag.Should().Be("🇬🇭");
50+
else if (shortCode == "CM")
51+
countryFlag.Should().Be("🇨🇲");
52+
else if (shortCode == "US")
53+
countryFlag.Should().Be("🇺🇸");
54+
}
55+
3756
[Theory]
3857
[InlineData("GHA")]
3958
[InlineData("G")]

0 commit comments

Comments
 (0)