File tree Expand file tree Collapse file tree
test/CountryData.UnitTests Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1- using CountryData . Standard ;
1+ using CountryData . Standard ;
22using FluentAssertions ;
33using System . Collections . Generic ;
44using 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" ) ]
You can’t perform that action at this time.
0 commit comments