public void TryGetEnumerationValueDisplayName_WithMultiLingualNameAttribute_ReturnsTheName() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); string multiLingualName; var result = service.TryGetEnumerationValueDisplayName(TestEnum.ValueWithMultiLingualNameAttributeForInvariantCulture, out multiLingualName); Assert.That(result, Is.True); Assert.That(multiLingualName, Is.EqualTo("The Name")); }
public void TryGetEnumerationValueDisplayName_WithCombinedFlagsEnumValue_ReturnsNull() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); string multiLingualName; var result = service.TryGetEnumerationValueDisplayName(FlagsEnum.Value1 | FlagsEnum.Value2, out multiLingualName); Assert.That(result, Is.False); Assert.That(multiLingualName, Is.Null); }
public void TryGetEnumerationValueDisplayName_WithUnknownEnumValue_ReturnsNull() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); string multiLingualName; var result = service.TryGetEnumerationValueDisplayName((TestEnum)100, out multiLingualName); Assert.That(result, Is.False); Assert.That(multiLingualName, Is.Null); }
public void TryGetEnumerationValueDisplayName_WithMultipleCalls_UsesCacheToRetrieveTheLocalizedName() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); using (new CultureScope("", "en-US")) { string multiLingualName; var result = service.TryGetEnumerationValueDisplayName(TestEnum.ValueWithMultiLingualNameAttributes, out multiLingualName); Assert.That(result, Is.True); Assert.That(multiLingualName, Is.EqualTo("The Name en-US")); } using (new CultureScope("", "fr-FR")) { string multiLingualName; var result = service.TryGetEnumerationValueDisplayName(TestEnum.ValueWithMultiLingualNameAttributes, out multiLingualName); Assert.That(result, Is.True); Assert.That(multiLingualName, Is.EqualTo("The Name fr-FR")); } }
public void TryGetEnumerationValueDisplayName_WithMultiLingualNameAttributesForDifferentCulturesAndCurrentUICultureOnlyMatchesNeutralCulture_ReturnsForTheNeutralCulture() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); using (new CultureScope("it-IT", "en-GB")) { string multiLingualName; var result = service.TryGetEnumerationValueDisplayName(TestEnum.ValueWithMultiLingualNameAttributes, out multiLingualName); Assert.That(result, Is.True); Assert.That(multiLingualName, Is.EqualTo("The Name en")); } }
public void Test_WithMultiLingualNameAttributesNotMatchingTheNeutralResourcesLanguageAttribute_ThrowsInvalidOperationException() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); using (new CultureScope("it-IT", "en-GB")) { string multiLingualName; Assert.That( () => service.TryGetEnumerationValueDisplayName(TestEnum.ValueWithoutInvariantCulture, out multiLingualName), Throws.TypeOf <InvalidOperationException>().With.Message.StartsWith( "The enum value 'ValueWithoutInvariantCulture' declared on type " + "'Remotion.Globalization.UnitTests.Implementation.MultiLingualNameBasedEnumerationGlobalizationServiceTest+TestEnum' " + "has no MultiLingualNameAttribute for the assembly's neutral resource language ('') applied.")); } }
public void TryGetEnumerationValueDisplayName_WithMultipleMultiLingualNameAttributesForSameCulture_ThrowsInvalidOperationException() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); using (new CultureScope("it-IT", "en-US")) { string multiLingualName; Assert.That( () => service.TryGetEnumerationValueDisplayName(TestEnum.ValueWithDuplicateMultiLingualNameAttributes, out multiLingualName), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo( "The enum value 'ValueWithDuplicateMultiLingualNameAttributes' declared on type " + "'Remotion.Globalization.UnitTests.Implementation.MultiLingualNameBasedEnumerationGlobalizationServiceTest+TestEnum' " + "has more than one MultiLingualNameAttribute for the culture 'fr-FR' applied. " + "The used cultures must be unique within the set of MultiLingualNameAttributes.")); } }
public void Test_WithNeutralResourcesLanguageAttributeSpecifiesSpecificCulture_DoesNotOverrideExistingSpecificCulture() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); var testEnumType = TestAssemblies.EnUS.Value.GetType("TestEnum", true, false); var enumValue = (Enum)Enum.Parse(testEnumType, "ValueWithEnAndEnUSAndEnGB"); using (new CultureScope("en-GB", "en-GB")) { string multiLingualName; var result = service.TryGetEnumerationValueDisplayName(enumValue, out multiLingualName); Assert.That(result, Is.True); Assert.That(multiLingualName, Is.EqualTo("The Name en-GB")); } }
public void Test_WithNeutralResourcesLanguageAttributeSpecifiesNeutralCulture_ReturnsTheSpecifiedCultureAsFallbackForInvariantCulture() { var service = new MultiLingualNameBasedEnumerationGlobalizationService(); var testEnumType = TestAssemblies.En.Value.GetType("TestEnum", true, false); var enumValue = (Enum)Enum.Parse(testEnumType, "ValueWithEnAndEnUS"); using (new CultureScope("", "")) { string multiLingualName; var result = service.TryGetEnumerationValueDisplayName(enumValue, out multiLingualName); Assert.That(result, Is.True); Assert.That(multiLingualName, Is.EqualTo("The Name en")); } }