Пример #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 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());
        }
Пример #3
0
        public void Constructor()
        {
            var localized = new LocalizableString("Width");
            Assert.IsNotNull(localized);
            Assert.IsInstanceOfType(localized, typeof(LocalizableString));
            Assert.IsNull(localized.ResourceType);

            ExceptionAssert.Throws<ArgumentException>(() => new LocalizableString(""));
            ExceptionAssert.Throws<ArgumentNullException>(() => new LocalizableString(null));
            ExceptionAssert.Throws<ArgumentException>(() => new LocalizableString("    "));
        }
Пример #4
0
 public void LocalValue()
 {
     var localized = new LocalizableString("Width");
     localized.Value = "100px";
     Assert.AreEqual("100px", localized.Value);
     Assert.AreEqual("100px", localized.GetLocalizableValue());
 }
Пример #5
0
 public void MissingValue()
 {
     var localized = new LocalizableString("RelativeDateFormatStringTomorrow");
     localized.ResourceType = typeof(Properties.Resources);
     Assert.IsNotNull(localized.ResourceType);
     Assert.IsNull(localized.GetLocalizableValue());
 }