Beispiel #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})");
                    }
                }
            }
        }
        public void GetCountryTranslatedName()
        {
            ICountryProvider countryProvider = new CountryProvider();

            var translatedCountryName = countryProvider.GetCountryTranslatedName(Alpha2Code.DE, LanguageCode.EN);

            Assert.AreEqual("Germany", translatedCountryName);
        }