Merge branch 'master' into common-logging-220-upgrade
This commit is contained in:
@@ -18,17 +18,21 @@
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Spring.Globalization
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class to pick the appropriate culture name for serbian due to changes of the CultureInfo classes
|
||||
/// in recent releases of the .NET framework.
|
||||
/// Helper class for Globalization Tests
|
||||
/// </summary>
|
||||
/// <remarks>In short, sr-SP-Latn->sr-Latn-CS and sr-SP-Cyrl->sr-Cyrl-CS. See http://blogs.msdn.com/kierans/archive/2006/08/02/687267.aspx
|
||||
/// <remarks>Ensure the appropriate culture name for serbian due to changes of the CultureInfo classes
|
||||
/// in recent releases of the .NET framework.In short, sr-SP-Latn->sr-Latn-CS and sr-SP-Cyrl->sr-Cyrl-CS. See http://blogs.msdn.com/kierans/archive/2006/08/02/687267.aspx
|
||||
/// and http://blogs.msdn.com/shawnste/archive/2006/11/14/problems-compiling-resources-in-net-2-0-apps-after-updates.aspx for
|
||||
/// additional information.</remarks>
|
||||
/// additional information.
|
||||
/// Also, provide for detection of runtime OS to respond to need for different asserts to reflect changes in Serbian Localization within the OS
|
||||
/// introduced after Windows7.
|
||||
/// </remarks>
|
||||
/// <author>Mark Pollack</author>
|
||||
public class CultureInfoUtils
|
||||
{
|
||||
@@ -57,5 +61,10 @@ namespace Spring.Globalization
|
||||
{
|
||||
get { return srLatn; }
|
||||
}
|
||||
|
||||
public static bool OperatingSystemIsLaterThanWindows7
|
||||
{
|
||||
get { return Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 2; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,29 +65,39 @@ namespace Spring.Globalization.Formatters
|
||||
Assert.AreEqual("($1,234.56)", fmt.Format(-1234.56));
|
||||
|
||||
fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName);
|
||||
#if NET_4_0
|
||||
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
|
||||
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));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
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
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);
|
||||
#if NET_4_0
|
||||
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));
|
||||
#else
|
||||
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));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -100,30 +110,39 @@ namespace Spring.Globalization.Formatters
|
||||
Assert.AreEqual(-1234.56, fmt.Parse("($1,234.56)"));
|
||||
|
||||
fmt = new CurrencyFormatter(CultureInfoUtils.SerbianLatinCultureName);
|
||||
#if NET_4_0
|
||||
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
|
||||
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."));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
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
|
||||
{
|
||||
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 NET_4_0
|
||||
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 Дин."));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
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 Дин."));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -149,17 +168,20 @@ namespace Spring.Globalization.Formatters
|
||||
fmt.GroupSizes = new int[] { 1, 2 };
|
||||
fmt.GroupSeparator = "'";
|
||||
|
||||
#if NET_4_0
|
||||
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));
|
||||
#endif
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -184,17 +206,22 @@ namespace Spring.Globalization.Formatters
|
||||
fmt = new CurrencyFormatter(CultureInfoUtils.SerbianCyrillicCultureName);
|
||||
fmt.GroupSizes = new int[] { 1, 2 };
|
||||
fmt.GroupSeparator = "'";
|
||||
#if NET_4_0
|
||||
Assert.AreEqual(1234, fmt.Parse("1'23'4,00 дин."));
|
||||
Assert.AreEqual(1234.56, fmt.Parse("1'23'4,56 дин."));
|
||||
Assert.AreEqual(-1234, fmt.Parse("-1'23'4,00 дин."));
|
||||
Assert.AreEqual(-1234.56, fmt.Parse("-1'23'4,56 дин."));
|
||||
#else
|
||||
Assert.AreEqual(1234, fmt.Parse("1'23'4,00 Дин."));
|
||||
Assert.AreEqual(1234.56, fmt.Parse("1'23'4,56 Дин."));
|
||||
Assert.AreEqual(-1234, fmt.Parse("-1'23'4,00 Дин."));
|
||||
Assert.AreEqual(-1234.56, fmt.Parse("-1'23'4,56 Дин."));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
Assert.AreEqual(1234, fmt.Parse("1'23'4,00 дин."));
|
||||
Assert.AreEqual(1234.56, fmt.Parse("1'23'4,56 дин."));
|
||||
Assert.AreEqual(-1234, fmt.Parse("-1'23'4,00 дин."));
|
||||
Assert.AreEqual(-1234.56, fmt.Parse("-1'23'4,56 дин."));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(1234, fmt.Parse("1'23'4,00 Дин."));
|
||||
Assert.AreEqual(1234.56, fmt.Parse("1'23'4,56 Дин."));
|
||||
Assert.AreEqual(-1234, fmt.Parse("-1'23'4,00 Дин."));
|
||||
Assert.AreEqual(-1234.56, fmt.Parse("-1'23'4,56 Дин."));
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ using NUnit.Framework;
|
||||
|
||||
namespace Spring.Globalization.Formatters
|
||||
{
|
||||
/// <summary>
|
||||
/// Unit tests for DateTimeFormatter class.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Unit tests for DateTimeFormatter class.
|
||||
/// </summary>
|
||||
/// <author>Aleksandar Seovic</author>
|
||||
[TestFixture]
|
||||
public class DateTimeFormatterTests
|
||||
{
|
||||
{
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void FormatNullValue()
|
||||
@@ -61,27 +61,37 @@ namespace Spring.Globalization.Formatters
|
||||
DateTimeFormatter fmt = new DateTimeFormatter("d", "en-US");
|
||||
Assert.AreEqual("8/14/2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("8/24/1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
|
||||
|
||||
fmt = new DateTimeFormatter("dd-MMM-yyyy", "en-US");
|
||||
Assert.AreEqual("14-Aug-2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24-Aug-1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
|
||||
fmt = new DateTimeFormatter("D", CultureInfoUtils.SerbianLatinCultureName);
|
||||
#if NET_4_0
|
||||
Assert.AreEqual("14. avgust 2004.", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24. avgust 1974.", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
#else
|
||||
Assert.AreEqual("14. avgust 2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24. avgust 1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
Assert.AreEqual("14. avgust 2004.", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24. avgust 1974.", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual("14. avgust 2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24. avgust 1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
}
|
||||
|
||||
fmt = new DateTimeFormatter("dd-MMM-yyyy", CultureInfoUtils.SerbianCyrillicCultureName);
|
||||
#if NET_4_0
|
||||
Assert.AreEqual("14-авг.-2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24-авг.-1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
#else
|
||||
Assert.AreEqual("14-авг-2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24-авг-1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
Assert.AreEqual("14-авг.-2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24-авг.-1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual("14-авг-2004", fmt.Format(new DateTime(2004, 8, 14)));
|
||||
Assert.AreEqual("24-авг-1974", fmt.Format(new DateTime(1974, 8, 24)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -90,28 +100,37 @@ namespace Spring.Globalization.Formatters
|
||||
DateTimeFormatter fmt = new DateTimeFormatter("d", "en-US");
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("8/14/2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("8/24/1974"));
|
||||
|
||||
|
||||
fmt = new DateTimeFormatter("dd-MMM-yyyy", "en-US");
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-Aug-2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-Aug-1974"));
|
||||
|
||||
fmt = new DateTimeFormatter("D", CultureInfoUtils.SerbianLatinCultureName);
|
||||
#if NET_4_0
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14. avgust 2004."));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24. avgust 1974."));
|
||||
#else
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14. avgust 2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24. avgust 1974"));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14. avgust 2004."));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24. avgust 1974."));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14. avgust 2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24. avgust 1974"));
|
||||
}
|
||||
|
||||
fmt = new DateTimeFormatter("dd-MMM-yyyy", CultureInfoUtils.SerbianCyrillicCultureName);
|
||||
#if NET_4_0
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-авг.-2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-авг.-1974"));
|
||||
#else
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-авг-2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-авг-1974"));
|
||||
#endif
|
||||
|
||||
if (CultureInfoUtils.OperatingSystemIsLaterThanWindows7)
|
||||
{
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-авг.-2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-авг.-1974"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(new DateTime(2004, 8, 14), fmt.Parse("14-авг-2004"));
|
||||
Assert.AreEqual(new DateTime(1974, 8, 24), fmt.Parse("24-авг-1974"));
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user