public void FormatUsingDefaults() { CurrencyFormatter fmt = new CurrencyFormatter("en-US"); Assert.AreEqual("$1,234.00", fmt.Format(1234)); Assert.AreEqual("$1,234.56", fmt.Format(1234.56)); Assert.AreEqual("($1,234.00)", fmt.Format(-1234)); Assert.AreEqual("($1,234.56)", fmt.Format(-1234.56)); fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName); if (CultureInfoUtils.OperatingSystemIsAfterWindows7AndBeforeWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater) { Assert.AreEqual("1.234,00 din.", fmt.Format(1234)); Assert.AreEqual("1.234,56 din.", fmt.Format(1234.56)); Assert.AreEqual("-1.234,00 din.", fmt.Format(-1234)); Assert.AreEqual("-1.234,56 din.", fmt.Format(-1234.56)); } else if (CultureInfoUtils.OperatingSystemIsAtLeastWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater) { Assert.AreEqual("1.234 RSD", fmt.Format(1234)); Assert.AreEqual("1.235 RSD", fmt.Format(1234.56)); Assert.AreEqual("-1.234 RSD", fmt.Format(-1234)); Assert.AreEqual("-1.235 RSD", fmt.Format(-1234.56)); } else { Assert.AreEqual("1.234,00 Din.", fmt.Format(1234)); Assert.AreEqual("1.234,56 Din.", fmt.Format(1234.56)); Assert.AreEqual("-1.234,00 Din.", fmt.Format(-1234)); Assert.AreEqual("-1.234,56 Din.", fmt.Format(-1234.56)); } }
public void ParseNullOrEmptyValue() { CurrencyFormatter fmt = new CurrencyFormatter(); Assert.AreEqual(0, fmt.Parse(null)); Assert.IsTrue(fmt.Parse("") is double); }
public void FormatUsingCustomSettings() { CurrencyFormatter fmt = new CurrencyFormatter("en-US"); fmt.DecimalDigits = 0; fmt.NegativePattern = 1; Assert.AreEqual("$1,234", fmt.Format(1234)); Assert.AreEqual("$1,235", fmt.Format(1234.56)); Assert.AreEqual("-$1,234", fmt.Format(-1234)); Assert.AreEqual("-$1,235", fmt.Format(-1234.56)); fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName); fmt.PositivePattern = 1; fmt.CurrencySymbol = "din"; if (CultureInfoUtils.OperatingSystemIsAtLeastWindows10Build10586 && CultureInfoUtils.ClrIsVersion4OrLater) { Assert.AreEqual("1.234din", fmt.Format(1234)); Assert.AreEqual("1.235din", fmt.Format(1234.56)); Assert.AreEqual("-1.234 din", fmt.Format(-1234)); Assert.AreEqual("-1.235 din", fmt.Format(-1234.56)); } else { Assert.AreEqual("1.234,00din", fmt.Format(1234)); Assert.AreEqual("1.234,56din", fmt.Format(1234.56)); Assert.AreEqual("-1.234,00 din", fmt.Format(-1234)); Assert.AreEqual("-1.234,56 din", fmt.Format(-1234.56)); } fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName); fmt.GroupSizes = new int[] { 1, 2 }; fmt.GroupSeparator = "'"; if (CultureInfoUtils.OperatingSystemIsAfterWindows7 && CultureInfoUtils.ClrIsVersion4OrLater) { Assert.AreEqual("1'23'4,00 дин.", fmt.Format(1234)); Assert.AreEqual("1'23'4,56 дин.", fmt.Format(1234.56)); Assert.AreEqual("-1'23'4,00 дин.", fmt.Format(-1234)); Assert.AreEqual("-1'23'4,56 дин.", fmt.Format(-1234.56)); } else { Assert.AreEqual("1'23'4,00 Дин.", fmt.Format(1234)); Assert.AreEqual("1'23'4,56 Дин.", fmt.Format(1234.56)); Assert.AreEqual("-1'23'4,00 Дин.", fmt.Format(-1234)); Assert.AreEqual("-1'23'4,56 Дин.", fmt.Format(-1234.56)); } }
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 Дин.")); } }
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")); }
public void FormatNonNumber() { CurrencyFormatter fmt = new CurrencyFormatter(); Assert.Throws <ArgumentException>(() => fmt.Format("not a number")); }
public void FormatNullValue() { CurrencyFormatter fmt = new CurrencyFormatter(); Assert.Throws <ArgumentNullException>(() => fmt.Format(null)); }