コード例 #1
0
        public void LocalizedValue()
        {
            var localized = new LocalizableString("RelativeDateFormatStringTomorrow");

            localized.Value = "RelativeDateFormatStringTomorrow";
            Assert.IsNull(localized.ResourceType);
            Assert.AreEqual("RelativeDateFormatStringTomorrow", localized.Value);
            Assert.AreEqual("RelativeDateFormatStringTomorrow", localized.GetLocalizableValue());

            localized.ResourceType = typeof(Properties.Resources);
            Assert.IsNotNull(localized.ResourceType);
            Assert.AreEqual("RelativeDateFormatStringTomorrow", localized.Value);
            Assert.AreEqual("Tomorrow", localized.GetLocalizableValue());

            var currentCulture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("es-ES");
                localized.ResourceType = typeof(Properties.Resources);
                Assert.IsNotNull(localized.ResourceType);
                Assert.AreEqual("RelativeDateFormatStringTomorrow", localized.Value);
                Assert.AreEqual("Mañana", localized.GetLocalizableValue());
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = currentCulture;
            }
        }
コード例 #2
0
        public void LocalizableString_Null_Value_Returned() {
            LocalizableString prop = new LocalizableString("MyProperty");
            Assert.IsNull(prop.Value);

            Assert.IsNull(prop.GetLocalizableValue(), "LocalizedValue should be null when Value and resourceType are null");

            prop.ResourceType = typeof(LocalizableStringTest);
            Assert.IsNull(prop.GetLocalizableValue(), "LocalizedValue should be null when Value is null and resourceType is not null");
        }
コード例 #3
0
        public void LocalizableString_Null_Value_Returned()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            Assert.IsNull(prop.Value);

            Assert.IsNull(prop.GetLocalizableValue(), "LocalizedValue should be null when Value and resourceType are null");

            prop.ResourceType = typeof(LocalizableStringTest);
            Assert.IsNull(prop.GetLocalizableValue(), "LocalizedValue should be null when Value is null and resourceType is not null");
        }
コード例 #4
0
        public void MissingValue()
        {
            var localized = new LocalizableString("RelativeDateFormatStringTomorrow");

            localized.ResourceType = typeof(Properties.Resources);
            Assert.IsNotNull(localized.ResourceType);
            Assert.IsNull(localized.GetLocalizableValue());
        }
コード例 #5
0
        public void LocalizableString_ProtectedStaticStringProperty_Throws()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            prop.Value        = "ProtectedStaticStringProperty";
            prop.ResourceType = typeof(LocalizableString_Resources);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { prop.GetLocalizableValue(); }, GetExpectedErrorMessage(prop.Value));
        }
コード例 #6
0
        public void LocalizableString_GetLocalizedValue_Fails_When_Resource_Key_Is_Empty()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            prop.Value        = string.Empty;
            prop.ResourceType = typeof(LocalizableString_Resources);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { prop.GetLocalizableValue(); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "MyProperty", prop.ResourceType.FullName, prop.Value));
        }
コード例 #7
0
        public void LocalizableString_Literal_Value_Returned()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            prop.Value = "theValue";
            Assert.AreEqual("theValue", prop.Value);
            Assert.AreEqual("theValue", prop.GetLocalizableValue());
        }
コード例 #8
0
        public void LocalValue()
        {
            var localized = new LocalizableString("Width");

            localized.Value = "100px";
            Assert.AreEqual("100px", localized.Value);
            Assert.AreEqual("100px", localized.GetLocalizableValue());
        }
コード例 #9
0
        public void LocalizableString_PublicStaticStringProperty_On_Public_Class_Succeeds()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            prop.Value        = "PublicStaticString";
            prop.ResourceType = typeof(LocalizableString_Resources);
            Assert.AreEqual("Public Static String", prop.GetLocalizableValue(), "LocalizedValue should contain the value of the public static string property");
        }
コード例 #10
0
        public void LocalizableString_PublicStaticStringProperty_On_Internal_Class_Throws()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            prop.Value        = "PublicStaticString";
            prop.ResourceType = typeof(LocalizableString_Resources_NonPublic);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { prop.GetLocalizableValue(); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "MyProperty", typeof(LocalizableString_Resources_NonPublic).FullName, prop.Value));
        }
コード例 #11
0
        public void InvalidResource()
        {
            var localized = new LocalizableString("RelativeDateFormatStringTomorrow");

            localized.ResourceType = typeof(Properties.Resources);
            localized.Value        = "RelativeDateFormatStringYesterday";
            Assert.AreEqual("RelativeDateFormatStringYesterday", localized.Value);
            Assert.IsNotNull(localized.ResourceType);

            ExceptionAssert.Throws <InvalidOperationException>(() => localized.GetLocalizableValue());

            localized.ResourceType = typeof(LocalizbleStringTests.ResourceTester);
            localized.Value        = "Invalid";
            ExceptionAssert.Throws <InvalidOperationException>(() => localized.GetLocalizableValue());

            localized.Value = "InvalidStatic";
            ExceptionAssert.Throws <InvalidOperationException>(() => localized.GetLocalizableValue());

            localized.Value = "Invalid2";
            ExceptionAssert.Throws <InvalidOperationException>(() => localized.GetLocalizableValue());

            localized.Value = "Invalid3";
            ExceptionAssert.Throws <InvalidOperationException>(() => localized.GetLocalizableValue());

            localized.Value = "Invalid4";
            ExceptionAssert.Throws <InvalidOperationException>(() => localized.GetLocalizableValue());

            localized.Value = "Invalid5";
            ExceptionAssert.Throws <InvalidOperationException>(() => localized.GetLocalizableValue());
        }
コード例 #12
0
        public void LocalizableString_GetLocalizedValue_Respects_Current_UI_Culture()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            prop.Value        = "Language";
            prop.ResourceType = typeof(LocalizableString_Resources_WithGermanSupport);

            CultureInfo defaultCulture = CultureInfo.CurrentUICulture;

            try {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
                Assert.AreEqual("English", prop.GetLocalizableValue(), "GetLocalizableValue should return 'English' with the 'en' culture");

                Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
                Assert.AreEqual("German", prop.GetLocalizableValue(), "GetLocalizableValue should return 'German' with the 'de' culture");
            } finally {
                Thread.CurrentThread.CurrentUICulture = defaultCulture;
            }
        }
コード例 #13
0
        public void LocalizableString_Resource_File_Can_Be_Used()
        {
            LocalizableString prop = new LocalizableString("MyProperty");

            prop.Value        = "LocalizableStringTest_Resource";
            prop.ResourceType = typeof(DataAnnotationsTestResources);

            string expected = "This is a localized string";

            Assert.AreEqual(expected, prop.GetLocalizableValue(), "LocalizedValue should contain the localized string found in the resources file");
        }
コード例 #14
0
        public void LocalizableString_Resource_File_Can_Be_Used() {
            LocalizableString prop = new LocalizableString("MyProperty");
            prop.Value = "LocalizableStringTest_Resource";
            prop.ResourceType = typeof(DataAnnotationsTestResources);

            string expected = "This is a localized string";
            Assert.AreEqual(expected, prop.GetLocalizableValue(), "LocalizedValue should contain the localized string found in the resources file");
        }
コード例 #15
0
 /// <summary>
 ///     Gets the UI display string for NullDisplayText.
 ///     <para>
 ///         This can be either a literal, non-localized string provided to <see cref="NullDisplayText" /> or the
 ///         localized string found when <see cref="NullDisplayTextResourceType" /> has been specified and <see cref="NullDisplayText" />
 ///         represents a resource key within that resource type.
 ///     </para>
 /// </summary>
 /// <returns>
 ///     When <see cref="NullDisplayTextResourceType" /> has not been specified, the value of
 ///     <see cref="NullDisplayText" /> will be returned.
 ///     <para>
 ///         When <see cref="NullDisplayTextResourceType" /> has been specified and <see cref="NullDisplayText" />
 ///         represents a resource key within that resource type, then the localized value will be returned.
 ///     </para>
 ///     <para>
 ///         When <see cref="NullDisplayText" /> and <see cref="NullDisplayTextResourceType" /> have not been set, returns <c>null</c>.
 ///     </para>
 /// </returns>
 /// <exception cref="InvalidOperationException">
 ///     After setting both the <see cref="NullDisplayTextResourceType" /> property and the <see cref="NullDisplayText" /> property,
 ///     but a public static property with a name matching the <see cref="NullDisplayText" /> value couldn't be found
 ///     on the <see cref="NullDisplayTextResourceType" />.
 /// </exception>
 public string GetNullDisplayText()
 {
     return(_nullDisplayText.GetLocalizableValue());
 }
コード例 #16
0
 /// <summary>
 /// Gets the localized name of the property.
 /// </summary>
 /// <returns>The localized property name.</returns>
 public string GetName()
 {
     return(_name.GetLocalizableValue());
 }
コード例 #17
0
 public void LocalizableString_PublicConstString_Throws() {
     LocalizableString prop = new LocalizableString("MyProperty");
     prop.Value = "PublicConstString";
     prop.ResourceType = typeof(LocalizableString_Resources);
     ExceptionHelper.ExpectException<InvalidOperationException>(() => { prop.GetLocalizableValue(); }, GetExpectedErrorMessage(prop.Value));
 }
コード例 #18
0
 public void LocalizableString_PublicStaticStringProperty_On_Internal_Class_Throws() {
     LocalizableString prop = new LocalizableString("MyProperty");
     prop.Value = "PublicStaticString";
     prop.ResourceType = typeof(LocalizableString_Resources_NonPublic);
     ExceptionHelper.ExpectException<InvalidOperationException>(() => { prop.GetLocalizableValue(); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "MyProperty", typeof(LocalizableString_Resources_NonPublic).FullName, prop.Value));
 }
コード例 #19
0
 /// <summary>
 /// Возвращает локализованное значение текста команды.
 /// </summary>
 /// <returns>Локализованное значение текста команды</returns>
 public string GetCommandText()
 {
     return(_commandText.GetLocalizableValue());
 }
コード例 #20
0
 public void LocalizableString_GetLocalizedValue_Fails_When_Resource_Key_Is_Empty() {
     LocalizableString prop = new LocalizableString("MyProperty");
     prop.Value = string.Empty;
     prop.ResourceType = typeof(LocalizableString_Resources);
     ExceptionHelper.ExpectException<InvalidOperationException>(() => { prop.GetLocalizableValue(); }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "MyProperty", prop.ResourceType.FullName, prop.Value));
 }
コード例 #21
0
 public void LocalizableString_Literal_Value_Returned() {
     LocalizableString prop = new LocalizableString("MyProperty");
     prop.Value = "theValue";
     Assert.AreEqual("theValue", prop.Value);
     Assert.AreEqual("theValue", prop.GetLocalizableValue());
 }
コード例 #22
0
        public void LocalizableString_GetLocalizedValue_Respects_Current_UI_Culture() {
            LocalizableString prop = new LocalizableString("MyProperty");
            prop.Value = "Language";
            prop.ResourceType = typeof(LocalizableString_Resources_WithGermanSupport);

            CultureInfo defaultCulture = CultureInfo.CurrentUICulture;

            try {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
                Assert.AreEqual("English", prop.GetLocalizableValue(), "GetLocalizableValue should return 'English' with the 'en' culture");

                Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
                Assert.AreEqual("German", prop.GetLocalizableValue(), "GetLocalizableValue should return 'German' with the 'de' culture");
            } finally {
                Thread.CurrentThread.CurrentUICulture = defaultCulture;
            }
        }
コード例 #23
0
 public void LocalizableString_PublicStaticStringProperty_On_Public_Class_Succeeds() {
     LocalizableString prop = new LocalizableString("MyProperty");
     prop.Value = "PublicStaticString";
     prop.ResourceType = typeof(LocalizableString_Resources);
     Assert.AreEqual("Public Static String", prop.GetLocalizableValue(), "LocalizedValue should contain the value of the public static string property");
 }