Ejemplo n.º 1
0
        public void ParseNullOrEmptyValue()
        {
            CurrencyFormatter fmt = new CurrencyFormatter();

            Assert.AreEqual(0, fmt.Parse(null));
            Assert.IsTrue(fmt.Parse("") is double);
        }
Ejemplo n.º 2
0
        public void ParseUsingDefaults()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");

            Assert.AreEqual(1234, fmt.Parse("$1,234.00"));
            Assert.AreEqual(1234.56, fmt.Parse("$1,234.56"));
            Assert.AreEqual(-1234, fmt.Parse("($1,234.00)"));
            Assert.AreEqual(-1234.56, fmt.Parse("($1,234.56)"));

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7AndBeforeWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 din."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 din."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 din."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 din."));
            }

            else if (CultureInfoUtils.OperatingSystemIsAtLeastWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234 RSD"));
                Assert.AreEqual(-1234, fmt.Parse("-1.234 RSD"));
            }

            else
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 Din."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Din."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Din."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Din."));
            }

            fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);

            if (CultureInfoUtils.OperatingSystemIsAfterWindows7 && CultureInfoUtils.ClrIsVersion4OrLater)
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 дин."));
            }
            else
            {
                Assert.AreEqual(1234, fmt.Parse("1.234,00 Дин."));
                Assert.AreEqual(1234.56, fmt.Parse("1.234,56 Дин."));
                Assert.AreEqual(-1234, fmt.Parse("-1.234,00 Дин."));
                Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 Дин."));
            }
        }
Ejemplo n.º 3
0
        public void ParseUsingCustomSettings()
        {
            CurrencyFormatter fmt = new CurrencyFormatter("en-US");

            fmt.DecimalDigits   = 0;
            fmt.NegativePattern = 1;
            Assert.AreEqual(1234, fmt.Parse("$1,234"));
            Assert.AreEqual(1234.56, fmt.Parse("$1,234.56"));
            Assert.AreEqual(-1234, fmt.Parse("-$1,234"));
            Assert.AreEqual(-1234.56, fmt.Parse("-$1,234.56"));

            fmt = new CurrencyFormatter("sr-SP-Latn");
            fmt.PositivePattern = 1;
            fmt.CurrencySymbol  = "din";
            Assert.AreEqual(1234, fmt.Parse("1.234,00din"));
            Assert.AreEqual(1234.56, fmt.Parse("1.234,56din"));
            Assert.AreEqual(-1234, fmt.Parse("-1.234,00 din"));
            Assert.AreEqual(-1234.56, fmt.Parse("-1.234,56 din"));
        }