From 336deb6821bb49e339f0ded5eb6911330e7e2d88 Mon Sep 17 00:00:00 2001 From: Revazashvili Date: Mon, 2 Dec 2024 22:54:16 +0400 Subject: [PATCH 1/4] private readonly fields should start with lowercase --- src/CountryData.Standard/CountryHelper.cs | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/CountryData.Standard/CountryHelper.cs b/src/CountryData.Standard/CountryHelper.cs index 6dcb817..c9ec0d3 100644 --- a/src/CountryData.Standard/CountryHelper.cs +++ b/src/CountryData.Standard/CountryHelper.cs @@ -9,14 +9,14 @@ namespace CountryData.Standard { public class CountryHelper { - private readonly IEnumerable _Countries; + private readonly IEnumerable _countries; private const string strFileName = "CountryData.Standard.data.json"; public CountryHelper() { var json = GetJsonData(strFileName); - _Countries = JsonConvert.DeserializeObject>(json); - foreach (var country in _Countries) + _countries = JsonConvert.DeserializeObject>(json); + foreach (var country in _countries) { country.CountryFlag = GetCountryEmojiFlag(country.CountryShortCode); } @@ -49,7 +49,7 @@ private string GetJsonData(string path) /// IEnumerable public virtual IEnumerable GetCountryData() { - return _Countries; + return _countries; } @@ -60,7 +60,7 @@ public virtual IEnumerable GetCountryData() /// Country public Country GetCountryByCode(string shortCode) { - return _Countries.SingleOrDefault(c => c.CountryShortCode == shortCode); + return _countries.SingleOrDefault(c => c.CountryShortCode == shortCode); } /// @@ -81,7 +81,7 @@ public string GetCountryEmojiFlag(string shortCode) /// List a list of regions public List GetRegionByCountryCode(string ShortCode) { - return _Countries.Where(x => x.CountryShortCode == ShortCode) + return _countries.Where(x => x.CountryShortCode == ShortCode) .Select(r => r.Regions).FirstOrDefault() .ToList(); } @@ -90,7 +90,7 @@ public List GetRegionByCountryCode(string ShortCode) /// Gets the list of all countries in the worlld /// /// IEnumerable countries - public IEnumerable GetCountries() => _Countries.Select(c => c.CountryName); + public IEnumerable GetCountries() => _countries.Select(c => c.CountryName); @@ -102,7 +102,7 @@ public List GetRegionByCountryCode(string ShortCode) /// string public string GetPhoneCodeByCountryShortCode(string shortCode) { - var country = _Countries.SingleOrDefault(c => c.CountryShortCode == shortCode); + var country = _countries.SingleOrDefault(c => c.CountryShortCode == shortCode); return country?.PhoneCode; } @@ -115,7 +115,7 @@ public string GetPhoneCodeByCountryShortCode(string shortCode) /// Country public IEnumerable GetCountryByPhoneCode(string phoneCode) { - var Country = _Countries.Where(c => c.PhoneCode == phoneCode); + var Country = _countries.Where(c => c.PhoneCode == phoneCode); return Country; } @@ -127,7 +127,7 @@ public IEnumerable GetCountryByPhoneCode(string phoneCode) /// An IEnumerable of Currency objects associated with the specified country. public IEnumerable GetCurrencyCodesByCountryCode(string shortCode) { - return _Countries.Where(x => x.CountryShortCode == shortCode) + return _countries.Where(x => x.CountryShortCode == shortCode) .SelectMany(c => c.Currency) .ToList(); } @@ -141,12 +141,12 @@ public IEnumerable GetCurrencyCodesByCountryCode(string shortCode) /// Thrown when the country data is not initialized. public IEnumerable 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)); } From a15e0b655a6f1b5a4ea3c8a4ce7c64246af63a63 Mon Sep 17 00:00:00 2001 From: Revazashvili Date: Mon, 2 Dec 2024 22:54:32 +0400 Subject: [PATCH 2/4] constants should start with uppercase --- src/CountryData.Standard/CountryHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CountryData.Standard/CountryHelper.cs b/src/CountryData.Standard/CountryHelper.cs index c9ec0d3..0bea777 100644 --- a/src/CountryData.Standard/CountryHelper.cs +++ b/src/CountryData.Standard/CountryHelper.cs @@ -10,11 +10,11 @@ namespace CountryData.Standard public class CountryHelper { private readonly IEnumerable _countries; - private const string strFileName = "CountryData.Standard.data.json"; + private const string StrFileName = "CountryData.Standard.data.json"; public CountryHelper() { - var json = GetJsonData(strFileName); + var json = GetJsonData(StrFileName); _countries = JsonConvert.DeserializeObject>(json); foreach (var country in _countries) { From a354de01902b81dd9cb4361fa3cfa7b163480185 Mon Sep 17 00:00:00 2001 From: Revazashvili Date: Mon, 2 Dec 2024 22:56:11 +0400 Subject: [PATCH 3/4] fix local variable name --- src/CountryData.Standard/CountryHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CountryData.Standard/CountryHelper.cs b/src/CountryData.Standard/CountryHelper.cs index 0bea777..435c039 100644 --- a/src/CountryData.Standard/CountryHelper.cs +++ b/src/CountryData.Standard/CountryHelper.cs @@ -115,8 +115,8 @@ public string GetPhoneCodeByCountryShortCode(string shortCode) /// Country public IEnumerable GetCountryByPhoneCode(string phoneCode) { - var Country = _countries.Where(c => c.PhoneCode == phoneCode); - return Country; + var country = _countries.Where(c => c.PhoneCode == phoneCode); + return country; } From 0ee9224be9374dba37bf607d8ae4a535aff03720 Mon Sep 17 00:00:00 2001 From: Revazashvili Date: Mon, 2 Dec 2024 22:57:08 +0400 Subject: [PATCH 4/4] fix hard coded field name in tests --- test/CountryData.UnitTests/CountryHelperTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CountryData.UnitTests/CountryHelperTests.cs b/test/CountryData.UnitTests/CountryHelperTests.cs index b3738c4..8ade22a 100644 --- a/test/CountryData.UnitTests/CountryHelperTests.cs +++ b/test/CountryData.UnitTests/CountryHelperTests.cs @@ -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