Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor naming #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 15 additions & 15 deletions src/CountryData.Standard/CountryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace CountryData.Standard
{
public class CountryHelper
{
private readonly IEnumerable<Country> _Countries;
private const string strFileName = "CountryData.Standard.data.json";
private readonly IEnumerable<Country> _countries;
private const string StrFileName = "CountryData.Standard.data.json";

public CountryHelper()
{
var json = GetJsonData(strFileName);
_Countries = JsonConvert.DeserializeObject<List<Country>>(json);
foreach (var country in _Countries)
var json = GetJsonData(StrFileName);
_countries = JsonConvert.DeserializeObject<List<Country>>(json);
foreach (var country in _countries)
{
country.CountryFlag = GetCountryEmojiFlag(country.CountryShortCode);
}
Expand Down Expand Up @@ -49,7 +49,7 @@ private string GetJsonData(string path)
/// <returns>IEnumerable<Country></returns>
public virtual IEnumerable<Country> GetCountryData()
{
return _Countries;
return _countries;
}


Expand All @@ -60,7 +60,7 @@ public virtual IEnumerable<Country> GetCountryData()
/// <returns>Country</returns>
public Country GetCountryByCode(string shortCode)
{
return _Countries.SingleOrDefault(c => c.CountryShortCode == shortCode);
return _countries.SingleOrDefault(c => c.CountryShortCode == shortCode);
}

/// <summary>
Expand All @@ -81,7 +81,7 @@ public string GetCountryEmojiFlag(string shortCode)
/// <returns>List<Regions> a list of regions</returns>
public List<Regions> GetRegionByCountryCode(string ShortCode)
{
return _Countries.Where(x => x.CountryShortCode == ShortCode)
return _countries.Where(x => x.CountryShortCode == ShortCode)
.Select(r => r.Regions).FirstOrDefault()
.ToList();
}
Expand All @@ -90,7 +90,7 @@ public List<Regions> GetRegionByCountryCode(string ShortCode)
/// Gets the list of all countries in the worlld
/// </summary>
/// <returns>IEnumerable<string> countries</returns>
public IEnumerable<string> GetCountries() => _Countries.Select(c => c.CountryName);
public IEnumerable<string> GetCountries() => _countries.Select(c => c.CountryName);



Expand All @@ -102,7 +102,7 @@ public List<Regions> GetRegionByCountryCode(string ShortCode)
/// <returns>string</returns>
public string GetPhoneCodeByCountryShortCode(string shortCode)
{
var country = _Countries.SingleOrDefault(c => c.CountryShortCode == shortCode);
var country = _countries.SingleOrDefault(c => c.CountryShortCode == shortCode);
return country?.PhoneCode;
}

Expand All @@ -115,8 +115,8 @@ public string GetPhoneCodeByCountryShortCode(string shortCode)
/// <returns>Country</returns>
public IEnumerable<Country> GetCountryByPhoneCode(string phoneCode)
{
var Country = _Countries.Where(c => c.PhoneCode == phoneCode);
return Country;
var country = _countries.Where(c => c.PhoneCode == phoneCode);
return country;
}


Expand All @@ -127,7 +127,7 @@ public IEnumerable<Country> GetCountryByPhoneCode(string phoneCode)
/// <returns>An IEnumerable of Currency objects associated with the specified country.</returns>
public IEnumerable<Currency> GetCurrencyCodesByCountryCode(string shortCode)
{
return _Countries.Where(x => x.CountryShortCode == shortCode)
return _countries.Where(x => x.CountryShortCode == shortCode)
.SelectMany(c => c.Currency)
.ToList();
}
Expand All @@ -141,12 +141,12 @@ public IEnumerable<Currency> GetCurrencyCodesByCountryCode(string shortCode)
/// <exception cref="InvalidOperationException">Thrown when the country data is not initialized.</exception>
public IEnumerable<Country> GetCountryByCurrencyCode(string currencyCode)
{
if (_Countries == null)
if (_countries == null)
{
throw new InvalidOperationException("Country data is not initialized.");
}

return _Countries.Where(c => c.Currency != null && c.Currency.Exists(currency => currency.Code == currencyCode));
return _countries.Where(c => c.Currency != null && c.Currency.Exists(currency => currency.Code == currencyCode));
}


Expand Down
2 changes: 1 addition & 1 deletion test/CountryData.UnitTests/CountryHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void GetCountryByCurrencyCode_WhenCountryDataIsNotInitialized_ShouldThrow
{
// Arrange
var countryHelper = new CountryHelper();
var field = typeof(CountryHelper).GetField("_Countries", BindingFlags.NonPublic | BindingFlags.Instance);
var field = typeof(CountryHelper).GetField("_countries", BindingFlags.NonPublic | BindingFlags.Instance);
field.SetValue(countryHelper, null);

// Act
Expand Down