Пример #1
0
        public void CheckAllCulture()
        {
            ICountryProvider countryProvider = new CountryProvider();

            CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

            foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
            {
                var countryInfo = countryProvider.GetCountry(countryCode);
                if (countryInfo == null)
                {
                    continue;
                }

                var expectedLanguages = countryInfo.Translations.Select(x => x.LanguageCode).ToList();
                foreach (var culture in cultures)
                {
                    bool expectResult = false;
                    if (Enum.TryParse(culture.TwoLetterISOLanguageName, true, out LanguageCode code) == true)
                    {
                        expectResult = expectedLanguages.Any(x => x == code);
                    }

                    var translatedCountryName = countryProvider.GetCountryTranslatedName(countryCode, culture);
                    if (expectResult == true && String.IsNullOrWhiteSpace(translatedCountryName) == true)
                    {
                        Assert.Fail($"A result was expected but there was no translated country name found for {countryCode} and culture {culture.Name} (language {culture.TwoLetterISOLanguageName})");
                    }
                }
            }
        }
Пример #2
0
        public void GetCountry(string countryCode)
        {
            ICountryProvider countryProvider = new CountryProvider();

            var countryInfo = countryProvider.GetCountry(countryCode);

            if (countryInfo == null)
            {
                Assert.Fail($"Cannot found countryCode: {countryCode}");
            }
        }
Пример #3
0
        public void CheckTranslationsAvailableTest()
        {
            ICountryProvider countryProvider = new CountryProvider();

            foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
            {
                var countryInfo = countryProvider.GetCountry(countryCode);
                if (countryInfo == null)
                {
                    continue;
                }

                var translationCount = countryInfo.Translations.Length;
                Assert.IsTrue(translationCount > 5, $"missing translations {countryCode}");
            }
        }
        public async Task CompareWithMledozeCountryProject()
        {
            using (var httpClient = new HttpClient())
            {
                var json = await httpClient.GetStringAsync("https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json");

                var items = JsonConvert.DeserializeObject <MledozeCountry[]>(json);

                ICountryProvider countryProvider = new CountryProvider();
                foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
                {
                    var countryInfo = countryProvider.GetCountry(countryCode);
                    Trace.WriteLine($"check {countryInfo.CommonName}");
                    if (countryInfo == null)
                    {
                        Assert.Fail($"countryInfo is null for {countryCode}");
                    }

                    var compareCountry = items.FirstOrDefault(o => o.Cca2.Equals(countryInfo.Alpha2Code.ToString()));
                    if (compareCountry == null)
                    {
                        Assert.Inconclusive(countryCode.ToString());
                        continue;
                    }

                    //TODO: Check how can check after change structure
                    //countryInfo.Currencies
                    //    .Should()
                    //    .BeEquivalentTo(compareCountry.Currencies.ChildrenToke.Name.ToArray(),
                    //    because: $"{countryCode} {string.Join(",", compareCountry.Currencies.Keys)}  {string.Join(",", countryInfo.Currencies)}");

                    Assert.AreEqual(compareCountry.Ccn3, countryInfo.NumericCode, $"wrong numeric code by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(compareCountry.Region, countryInfo.Region.ToString(), $"wrong region by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(this.AdaptMledozeSubRegion(compareCountry.Subregion), this.GetSubRegion(countryInfo.SubRegion), $"wrong subregion by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(compareCountry.Cca3, countryInfo.Alpha3Code.ToString(), $"wrong alpha 3 code by {countryCode} {countryInfo.CommonName}");
                    Assert.AreEqual(compareCountry.Name.Common, countryInfo.CommonName.ToString(), $"wrong common name by {countryCode} {countryInfo.CommonName}");
                }
            }
        }
Пример #5
0
        public void DuplicateTranslationTest()
        {
            var missingCountries = new List <Alpha2Code>();

            ICountryProvider countryProvider = new CountryProvider();

            foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
            {
                var countryInfo = countryProvider.GetCountry(countryCode);
                if (countryInfo == null)
                {
                    missingCountries.Add(countryCode);
                    continue;
                }

                var duplicateTranslation = countryInfo.Translations.GroupBy(o => o.LanguageCode).Where(o => o.Count() > 1).Any();
                Assert.IsFalse(duplicateTranslation);
            }

            if (missingCountries.Count > 0)
            {
                Assert.Inconclusive(string.Join(",", missingCountries));
            }
        }
Пример #6
0
        public async Task CompareWithMledozeCountryProject()
        {
            using (var httpClient = new HttpClient())
            {
                var json = await httpClient.GetStringAsync("https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.json");

                var items = JsonConvert.DeserializeObject <MledozeCountry[]>(json);

                ICountryProvider countryProvider = new CountryProvider();
                foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
                {
                    var countryInfo = countryProvider.GetCountry(countryCode);
                    if (countryInfo == null)
                    {
                        Assert.Fail($"countryInfo is null for {countryCode}");
                    }

                    var compareCountry = items.FirstOrDefault(o => o.Cca2.Equals(countryInfo.Alpha2Code.ToString()));
                    if (compareCountry == null)
                    {
                        Assert.Inconclusive(countryCode.ToString());
                        continue;
                    }

                    countryInfo.Currencies
                    .Should()
                    .BeEquivalentTo(compareCountry.Currency,
                                    because: $"{countryCode} {string.Join(",", compareCountry.Currency)}  {string.Join(",", countryInfo.Currencies)}");

                    Assert.AreEqual(compareCountry.Ccn3, countryInfo.NumericCode, $"wrong numeric code by {countryCode}");
                    //Assert.AreEqual(countryInfo.Region.ToString(), compareCountry.Region, $"wrong region by {countryCode}");
                    Assert.AreEqual(compareCountry.Cca3, countryInfo.Alpha3Code.ToString(), $"wrong alpha 3 code by {countryCode}");
                    Assert.AreEqual(compareCountry.Name.Common, countryInfo.CommonName.ToString(), $"wrong common name by {countryCode}");
                }
            }
        }