private static void CompareVarying(string one, string two, int compareValue, string culture, CompareOptions compareOptions) { StringComparer comp = new CultureInfo(culture).CompareInfo.GetStringComparer(compareOptions); Assert.Equal(compareValue, comp.Compare(one, two)); if (compareValue == 0) { Assert.True(comp.Equals(one, two)); } else { Assert.False(comp.Equals(one, two)); } }
/// <summary> /// Converts the given value object to the specified type, using the specified culture /// information. /// </summary> /// <returns> /// An <see cref="T:System.Object"/> that represents the converted value. /// </returns> /// <param name="culture"> /// A <see cref="T:System.Globalization.CultureInfo"/>. If null is passed, the current culture is assumed. /// </param> /// <param name="value">The <see cref="T:System.Object"/> to convert. </param> /// <param name="destinationType"> /// The <see cref="T:System.Type"/> to convert the <paramref name="value"/> parameter to. /// </param> /// <exception cref="T:System.ArgumentNullException"> /// The <paramref name="destinationType"/> parameter is null. /// </exception> /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. /// </exception> public virtual object ConvertTo(CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException(nameof(destinationType)); } if (destinationType == typeof(string)) { if (value == null) { return(string.Empty); } // Pre-whidbey we just did a ToString() here. To minimize the chance of a breaking change we // still send requests for the CurrentCulture to ToString() (which should return the same). if (culture?.Equals(CultureInfo.CurrentCulture) == false) { // VSWhidbey 75433 - If the object is IFormattable, use this interface to convert to string // so we use the specified culture rather than the CurrentCulture like object.ToString() does. if (value is IFormattable formattable) { return(formattable.ToString(/* format = */ null, /* formatProvider = */ culture)); } } return(value.ToString()); } throw this.GetConvertToException(value, destinationType); }
public void Equals(string cultureName1, CompareOptions options1, string cultureName2, CompareOptions options2, bool expected) { StringComparer comparer1 = new CultureInfo(cultureName1).CompareInfo.GetStringComparer(options1); StringComparer comparer2 = new CultureInfo(cultureName2).CompareInfo.GetStringComparer(options2); Assert.Equal(expected, comparer1.Equals(comparer2)); Assert.Equal(expected, comparer1.GetHashCode().Equals(comparer2.GetHashCode())); }
public static void CompareInfoIdentityTests() { StringComparer us = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase); StringComparer us2 = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase); StringComparer usNoSym = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreSymbols); StringComparer fr = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase); StringComparer frOrdinal = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.Ordinal); Assert.True(us.Equals(us2)); Assert.False(us.Equals(usNoSym)); Assert.False(us.Equals(fr)); Assert.False(us.Equals(frOrdinal)); Assert.Equal(us.GetHashCode(), us2.GetHashCode()); Assert.NotEqual(us.GetHashCode(), usNoSym.GetHashCode()); Assert.NotEqual(us.GetHashCode(), fr.GetHashCode()); Assert.NotEqual(frOrdinal.GetHashCode(), fr.GetHashCode()); }
private void LanguageChanged(Object sender, EventArgs e) { CultureInfo currLang = App.Language.Name; foreach (MenuItem menuItem in menuLanguage.Items) { CultureInfo cultureInfo = menuItem.Tag as CultureInfo; menuItem.IsChecked = cultureInfo?.Equals(currLang) ?? false; } }
internal VoiceInfo(CultureInfo culture) { // Fails if no culture is provided Helpers.ThrowIfNull(culture, nameof(culture)); if (culture.Equals(CultureInfo.InvariantCulture)) { throw new ArgumentException(SR.Get(SRID.InvariantCultureInfo), nameof(culture)); } _culture = culture; }
/// <summary> /// Documentation pending /// </summary> /// <param name="locale"></param> /// <returns></returns> public virtual CultureInfo ResolveLocale(CultureInfo locale) { CultureInfo localeToUse = locale ?? LocalizationScopeManager.CurrentLocalizationScope; if (localeToUse == null || localeToUse.Equals(CultureInfo.InvariantCulture)) { localeToUse = DataLocalizationFacade.DefaultLocalizationCulture; } return(localeToUse); }
protected virtual string GetResourceFileName(CultureInfo culture) { if (culture.Equals(CultureInfo.InvariantCulture)) { return(BaseNameField + ".resources"); } else { return(BaseNameField + "." + culture.Name + ".resources"); } }
internal StringSegmentCultureAwareComparer(CultureInfo culture, bool ignoreCase) { if (culture == null) { Throw.ArgumentNullException(Argument.culture); } compareInfo = culture.CompareInfo; options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None; #if NET35 || NET40 || NET45 stringComparer = StringComparer.Create(culture, ignoreCase); #endif #if NETSTANDARD2_1 || NETCOREAPP3_0 // span comparison is not supported with a custom culture even in .NET Core 3 so using StringComparison when possible knownComparison = culture.Equals(CultureInfo.InvariantCulture) ? ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture : culture.Equals(CultureInfo.CurrentCulture) ? ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture : default(StringComparison?); #endif }
private static string GetName(CultureInfo ci) { if (ci.Equals(CultureInfo.InvariantCulture)) { return("Invariant"); } else { return(ci.Name); } }
private Dictionary <string, IDictionary <string, string> > GetAreaStoredTranslations(IDictionary <CultureInfo, Lazy <XDocument> > xmlSource, CultureInfo cult) { var overallResult = new Dictionary <string, IDictionary <string, string> >(StringComparer.InvariantCulture); var areas = xmlSource[cult].Value.XPathSelectElements("//area"); foreach (var area in areas) { var result = new Dictionary <string, string>(StringComparer.InvariantCulture); var keys = area.XPathSelectElements("./key"); foreach (var key in keys) { var dictionaryKey = (string)key.Attribute("alias"); //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files if (result.ContainsKey(dictionaryKey) == false) { result.Add(dictionaryKey, key.Value); } } overallResult.Add(area.Attribute("alias").Value, result); } //Merge English Dictionary var englishCulture = new CultureInfo("en-US"); if (!cult.Equals(englishCulture)) { var enUS = xmlSource[englishCulture].Value.XPathSelectElements("//area"); foreach (var area in enUS) { IDictionary <string, string> result = new Dictionary <string, string>(StringComparer.InvariantCulture); if (overallResult.ContainsKey(area.Attribute("alias").Value)) { result = overallResult[area.Attribute("alias").Value]; } var keys = area.XPathSelectElements("./key"); foreach (var key in keys) { var dictionaryKey = (string)key.Attribute("alias"); //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files if (result.ContainsKey(dictionaryKey) == false) { result.Add(dictionaryKey, key.Value); } } if (!overallResult.ContainsKey(area.Attribute("alias").Value)) { overallResult.Add(area.Attribute("alias").Value, result); } } } return(overallResult); }
public static void CompareInfoBasicTests() { string one = "A test string"; string aCopyOfOne = one; StringComparer comp = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase); Assert.Equal(0, comp.Compare(one, aCopyOfOne)); Assert.True(comp.Equals(one, aCopyOfOne)); Assert.Equal(-1, comp.Compare(null, one)); Assert.Equal(0, comp.Compare(null, null)); Assert.Equal(1, comp.Compare(one, null)); Assert.False(comp.Equals(null, one)); Assert.True(comp.Equals(null, null)); Assert.False(comp.Equals(one, null)); Assert.Equal(comp.GetHashCode("abc"), comp.GetHashCode("ABC")); }
private void LanguageChanged(Object sender, EventArgs e) { CultureInfo currLang = App.Language; //Отмечаем нужный пункт смены языка как выбранный язык foreach (MenuItem i in menuLanguage.Items) { CultureInfo ci = i.Tag as CultureInfo; i.IsChecked = ci != null && ci.Equals(currLang); } }
void LookupFormInputLanguageChanged(object sender, InputLanguageChangedEventArgs e) { if (targetCulture != null && targetCulture.Equals(e.InputLanguage.Culture)) { SearchMode = SearchMode.Backward; } else if (sourceCulture != null && sourceCulture.Equals(e.InputLanguage.Culture)) { SearchMode = SearchMode.Forward; } }
/// <summary> /// Uppercases a string collection with Invariant culture. Tolerates nulls. /// </summary> /// <param name="src">Collection to lower-case</param> /// <param name="cultureInfo">Culture to use in the operation. Note that .NET's ToUpper doesn't accept a culture, so really, your only choices here are "Invariant" or "whatever .Net uses by default".</param> /// <returns>Input, lower-cased</returns> public static IEnumerable <string> ToUpper( this IEnumerable <string> src, CultureInfo cultureInfo ) { return(src.Select(s => cultureInfo.Equals(CultureInfo.InvariantCulture) ? s?.ToUpperInvariant() : s?.ToUpper() )); }
private static void ValidateCulture(CultureInfo culture) { if (culture == null) { throw new ArgumentNullException(nameof(culture)); } if (culture.IsNeutralCulture || culture.Equals(CultureInfo.InvariantCulture)) { throw new ArgumentException("Specific Culture Required", nameof(culture)); } }
private void LanguageChanged(Object sender, EventArgs e) { CultureInfo currLang = App.Language; foreach (MenuItem i in menuLanguage.Items) { CultureInfo ci = i.Tag as CultureInfo; i.IsChecked = ci != null && ci.Equals(currLang); } }
/// <summary> /// Returns a localizer instance based on the culture. /// </summary> public static BaseLocalizer GetLocalizerByCulture(CultureInfo ci) { if (customLocalizer != null) { return(customLocalizer); } if (ci.Equals(farsiCulture)) { return(fa); } else if (ci.Equals(arabicCulture)) { return(ar); } else { return(en); } }
public Options() { this.ThrowExceptionOnParseError = true; this.CasingType = CasingTypeEnum.Sentence; this.Verbose = false; this.DayOfWeekStartIndexZero = true; this.Use24HourTimeFormat = false; //culture specific default options CultureInfo cultureInfo = Thread.CurrentThread.CurrentUICulture; if (cultureInfo.Equals(new CultureInfo("ru")) || //Russian cultureInfo.Equals(new CultureInfo("uk")) || //Ukraninian cultureInfo.Equals(new CultureInfo("de")) || //German cultureInfo.Equals(new CultureInfo("it")) //Italian ) { this.Use24HourTimeFormat = true; } }
/// <summary> /// Removes the given locale, all data is lost /// </summary> /// <param name="cultureInfo"></param> /// <param name="makeFlush"></param> public static void RemoveLocale(CultureInfo cultureInfo, bool makeFlush = true) { Verify.That(!IsDefaultLocale(cultureInfo), "The locale '{0}' is the default locale and can not be removed", cultureInfo); Verify.That(!IsOnlyActiveLocaleForSomeUsers(cultureInfo), "The locale '{0}' is the only locale for some user(s) and can not be removed", cultureInfo); using (var transactionScope = TransactionsFacade.CreateNewScope()) { string cultureName = cultureInfo.Name; var systemActiveLocale = DataFacade.GetData <ISystemActiveLocale>().SingleOrDefault(f => f.CultureName == cultureName); Verify.IsNotNull(systemActiveLocale, "The locale '{0}' has not beed added and can not be removed", cultureInfo); List <string> usernames = (from u in DataFacade.GetData <IUser>() select u.Username).ToList(); foreach (string username in usernames) { if (cultureInfo.Equals(UserSettings.GetCurrentActiveLocaleCultureInfo(username))) { CultureInfo fallbackCultureInfo = UserSettings.GetActiveLocaleCultureInfos(username).First(f => !f.Equals(cultureInfo)); UserSettings.SetCurrentActiveLocaleCultureInfo(username, fallbackCultureInfo); } if (cultureInfo.Equals(UserSettings.GetForeignLocaleCultureInfo(username))) { UserSettings.SetForeignLocaleCultureInfo(username, null); } UserSettings.RemoveActiveLocaleCultureInfo(username, cultureInfo); } DataFacade.Delete <ISystemActiveLocale>(systemActiveLocale); transactionScope.Complete(); } DynamicTypeManager.RemoveLocale(cultureInfo); }
protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) { ResourceSet rs; if (!Resources.TryGetValue(culture, out rs)) { if (m_neutralResourcesCulture == null) { m_neutralResourcesCulture = GetNeutralResourcesLanguage(MainAssembly); } if (m_neutralResourcesCulture.Equals(culture)) { culture = CultureInfo.InvariantCulture; } string resourceFileName = GetResourceFileName(culture); Stream resStream = MainAssembly.GetManifestResourceStream(resourceFileName); if (resStream == null && !culture.IsNeutralCulture) { // try two-letter culture resourceFileName = GetResourceFileName(culture.Parent); resStream = MainAssembly.GetManifestResourceStream(resourceFileName); } if (resStream == null) { rs = base.InternalGetResourceSet(culture, createIfNotExists, tryParents); } else { using (resStream) { rs = new ResourceSet(resStream); } } if (rs != null) { lock (Resources) { ResourceSet ex; if (!Resources.TryGetValue(culture, out ex)) { Resources.Add(culture, rs); } else if (!object.ReferenceEquals(ex, rs)) { rs.Dispose(); rs = ex; } } } } return(rs); }
public bool Equals(TemplateCacheKey other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(string.Equals(_path, other._path) && _culture.Equals(other._culture)); }
public CultureInfoScope(CultureInfo cultureInfo) { if (cultureInfo != null && !cultureInfo.Equals(Thread.CurrentThread.CurrentCulture)) { if (cultureInfo.IsNeutralCulture) { cultureInfo = LanguageHelper.GetSpecificCultureInfo(cultureInfo); } originalCultureInfo = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = cultureInfo; } }
/// <summary> /// Sets the language to use. When the language is set the designer will be /// reloaded. /// </summary> public void SetLanguage(IComponent o, CultureInfo language) { CheckRoot(); if (language is null) { language = CultureInfo.InvariantCulture; } bool isInvariantCulture = (language.Equals(CultureInfo.InvariantCulture)); if (_language.Equals(language)) { return; } _language = language; if (!isInvariantCulture) { SetLocalizable(o, true); } if (_serviceProvider is not null && _host is not null) { IDesignerLoaderService ls = _serviceProvider.GetService(typeof(IDesignerLoaderService)) as IDesignerLoaderService; // Only reload if we're not in the process of loading! if (_host.Loading) { _loadLanguage = language; } else { bool reloadSuccessful = false; if (ls is not null) { reloadSuccessful = ls.Reload(); } if (!reloadSuccessful) { IUIService uis = (IUIService)_serviceProvider.GetService(typeof(IUIService)); if (uis is not null) { uis.ShowMessage(SR.LocalizationProviderManualReload); } } } } }
internal static string FindFolderForCulture(CultureInfo culture, string rootDirectory, bool useLcidFormat) { for (; culture != null && !culture.Equals((object)CultureInfo.InvariantCulture); culture = culture.Parent) { string path = useLcidFormat ? Path.Combine(rootDirectory, culture.LCID.ToString((IFormatProvider)CultureInfo.InvariantCulture)) : Path.Combine(rootDirectory, culture.Name); if (Microsoft.Expression.Utility.IO.PathHelper.DirectoryExists(path)) { return(path); } } return((string)null); }
private static int GetInvariantOrLocalizedNameHitIndex(List <string> ruleNameQueriesList, XElement currentResourceElement, CultureInfo mainThreadCulture, bool ignoreCase) { DataClassificationLocalizableDetails dataClassificationLocalizableDetails = XmlProcessingUtils.ReadDefaultRuleMetadata(currentResourceElement); int num = ruleNameQueriesList.BinarySearch(dataClassificationLocalizableDetails.Name, StringComparer.Create(dataClassificationLocalizableDetails.Culture, ignoreCase)); if (num < 0 && !dataClassificationLocalizableDetails.Culture.Equals(mainThreadCulture)) { Dictionary <CultureInfo, string> dictionary = XmlProcessingUtils.ReadAllRuleNames(currentResourceElement); CultureInfo cultureInfo = mainThreadCulture; string text = null; while (!cultureInfo.Equals(CultureInfo.InvariantCulture) && !dictionary.TryGetValue(cultureInfo, out text)) { cultureInfo = cultureInfo.Parent; } if (text != null && !cultureInfo.Equals(CultureInfo.InvariantCulture)) { num = ruleNameQueriesList.BinarySearch(text, StringComparer.Create(cultureInfo, ignoreCase)); } } return(num); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is LanguageWrapper && Culture.Equals(((LanguageWrapper)obj).Culture)); }
private void LanguageChanged(Object sender, EventArgs e) { CultureInfo currentLanguage = App.Language; foreach (MenuItem item in Menu.Items) { CultureInfo cultureInfo = item.Tag as CultureInfo; item.IsChecked = cultureInfo != null && cultureInfo.Equals(currentLanguage); } OnLanguageChanged?.Invoke(); }
public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedWindows, int expectedICU) { int expected = s_isWindows ? expectedWindows : expectedICU; StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options); Assert.Equal(expected, Math.Sign(comparer.Compare(x, y))); Assert.Equal((expected == 0), comparer.Equals(x, y)); if (x != null && y != null) { Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y))); } }
public static bool TryGet(CultureInfo culture, out Currency currency) { bool tryGet = false; currency = null; if (culture != null && !culture.IsNeutralCulture && !culture.Equals(CultureInfo.InvariantCulture)) { var region = new RegionInfo(culture.LCID); tryGet = TryGet(region, out currency); } return(tryGet); }
protected internal virtual CultureInfo GetMatchingCultureByAncestors(IEnumerable <CultureInfo> cultures, CultureInfo cultureToMatch) { cultures = (cultures ?? Enumerable.Empty <CultureInfo>()).ToArray(); var culture = cultures.FirstOrDefault(item => item.Equals(cultureToMatch)); if (culture == null && cultureToMatch != null && !cultureToMatch.Equals(cultureToMatch.Parent)) { culture = this.GetMatchingCultureByAncestors(cultures, cultureToMatch.Parent); } return(culture); }
public PromptBuilder(CultureInfo culture) { Helpers.ThrowIfNull(culture, nameof(culture)); if (culture.Equals(CultureInfo.InvariantCulture)) { throw new ArgumentException(SR.Get(SRID.InvariantCultureInfo), nameof(culture)); } _culture = culture; // Reset all value to default ClearContent(); }
public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedNls, int expectedICU) { int expected = PlatformDetection.IsNlsGlobalization ? expectedNls : expectedICU; StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options); Assert.Equal(expected, Math.Sign(comparer.Compare(x, y))); Assert.Equal((expected == 0), comparer.Equals(x, y)); if (x != null && y != null) { Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y))); } }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1:CultureTypes.SpecificCultures"); try { string myLcid = new CultureInfo("en-us").Name; if (!myLcid.Equals( new CultureInfo("en-us").TextInfo.CultureName ) ) { TestLibrary.TestFramework.LogError("001", "the licd of 'zh-CHT' culture should equal to textInfo.LCID."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Other (CultureTypes.NeutralCultures) CultureInfo comes from GetCultureInfo method with the same paramter is the same CultureInfo as the original"); try { CultureInfo myCultureInfo = new CultureInfo("en-US"); CultureInfo myCultureInfo1 = new CultureInfo("en-US"); if (!myCultureInfo1.Equals(myCultureInfo)) { TestLibrary.TestFramework.LogError("003", "Other CultureInfo comes from GetCultureInfo method with the same paramter should be the same CultureInfo as the original."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); retVal = false; } return retVal; }
public bool PosTest5() { bool retVal = true; const string c_TEST_DESC = "PosTest5: Verify the TextInfo not equal a int object . "; const string c_TEST_ID = "P005"; TextInfo textInfoUS = new CultureInfo("en-US").TextInfo; int i = TestLibrary.Generator.GetInt32(-55); object intObject = i as object; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (textInfoUS.Equals(intObject)) { string errorDesc = "the US CultureInfo's TextInfo should not equal int object. "; TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest5() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest5: Other (CultureTypes.NeutralCultures) CultureInfo comes from constroctor with the different paramter is not the same CultureInfo as the original( CultureTypes.SpecificCultures)"); try { CultureInfo myCultureInfo = new CultureInfo("en"); CultureInfo myCultureInfo1 = new CultureInfo("en-US"); if (myCultureInfo1.Equals(myCultureInfo)) { TestLibrary.TestFramework.LogError("009", "Should not be the same Culture."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; const string c_TEST_DESC = "PosTest3: Verify the TextInfo not equal a null reference . "; const string c_TEST_ID = "P003"; TextInfo textInfoUS = new CultureInfo("en-US").TextInfo; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (textInfoUS.Equals(null)) { string errorDesc = "the US CultureInfo's TextInfo should not equal a null reference. "; TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e); retVal = false; } return retVal; }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest7() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest5: Compare to null"); try { CultureInfo myCultureInfo = new CultureInfo("en-US"); if (myCultureInfo.Equals(null)) { TestLibrary.TestFramework.LogError("013", "Should not be the same Culture."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; const string c_TEST_DESC = "PosTest2: Verify the TextInfo is not same CultureInfo's . "; const string c_TEST_ID = "P002"; TextInfo textInfoFrance = new CultureInfo("fr-FR").TextInfo; TextInfo textInfoUS = new CultureInfo("en-US").TextInfo; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (textInfoFrance.Equals((object)textInfoUS)) { string errorDesc = "the TextInfos of differente CultureInfo should not equal. "; TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e); retVal = false; } return retVal; }
public void Equals(CultureInfo culture, object value, bool expected) { Assert.Equal(expected, culture.Equals(value)); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest6() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest6: Compare to itself "); try { CultureInfo myCultureInfo = new CultureInfo("en-US"); if (!myCultureInfo.Equals(myCultureInfo)) { TestLibrary.TestFramework.LogError("011", "Should be the same Culture."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e); retVal = false; } return retVal; }
public bool PosTest6() { bool retVal = true; const string c_TEST_DESC = "PosTest6: Verify the TextInfo not equal a string object . "; const string c_TEST_ID = "P006"; TextInfo textInfoUS = new CultureInfo("en-US").TextInfo; String str = TestLibrary.Generator.GetString(-55, false,c_MINI_STRING_LENGTH,c_MAX_STRING_LENGTH); object strObject = str as object; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (textInfoUS.Equals(strObject)) { string errorDesc = "the US CultureInfo's TextInfo should not equal string object. "; TestLibrary.TestFramework.LogError("009" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("010" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e); retVal = false; } return retVal; }
public bool PosTest4() { bool retVal = true; const string c_TEST_DESC = "PosTest4: Verify the TextInfo not equal another type object . "; const string c_TEST_ID = "P004"; TextInfo textInfoUS = new CultureInfo("en-US").TextInfo; object obj = (object)(new MyClass()); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (textInfoUS.Equals(obj)) { string errorDesc = "the US CultureInfo's TextInfo should not equal user-defined type object. "; TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e); retVal = false; } return retVal; }