Skip to content

Commit b9e8e74

Browse files
David EllingsworthDavid Ellingsworth
authored andcommitted
GH3530: Add locale specific tests to check for invalid type conversions.
1 parent 705d794 commit b9e8e74

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace NHibernate.Test.NHSpecificTest.GH3530
8+
{
9+
public class LocaleEntity
10+
{
11+
public virtual Guid Id { get; set; }
12+
public virtual int IntegerValue { get; set; }
13+
public virtual DateTime DateTimeValue { get; set; }
14+
public virtual double DoubleValue { get; set; }
15+
public virtual decimal DecimalValue { get; set; }
16+
}
17+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Globalization;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.GH3530
6+
{
7+
[TestFixture]
8+
public class Fixture : BugTestCase
9+
{
10+
private CultureInfo initialCulture;
11+
12+
[OneTimeSetUp]
13+
public void FixtureSetup()
14+
{
15+
initialCulture = CurrentCulture;
16+
}
17+
18+
[OneTimeTearDown]
19+
public void FixtureTearDown()
20+
{
21+
CurrentCulture = initialCulture;
22+
}
23+
24+
protected override void OnTearDown()
25+
{
26+
using (var session = OpenSession())
27+
using (var transaction = session.BeginTransaction())
28+
{
29+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
30+
31+
transaction.Commit();
32+
}
33+
}
34+
35+
[TestCaseSource(nameof(GetTestCases))]
36+
public void TestLocales(CultureInfo from, CultureInfo to)
37+
{
38+
DateTime leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish));
39+
double doubleValue = 12.3f;
40+
int intValue = 4;
41+
object id;
42+
43+
CurrentCulture = from;
44+
using (var session = OpenSession())
45+
using (var tx = session.BeginTransaction())
46+
{
47+
var entity = new LocaleEntity()
48+
{
49+
DateTimeValue = leapDay,
50+
DoubleValue = doubleValue,
51+
IntegerValue = intValue,
52+
};
53+
54+
id = session.Save(entity);
55+
tx.Commit();
56+
}
57+
58+
CurrentCulture = to;
59+
using (var session = OpenSession())
60+
using (var tx = session.BeginTransaction())
61+
{
62+
var entity = session.Get<LocaleEntity>(id);
63+
64+
Assert.AreEqual(leapDay, entity.DateTimeValue);
65+
Assert.AreEqual(intValue, entity.IntegerValue);
66+
Assert.True(doubleValue - entity.DoubleValue < double.Epsilon);
67+
}
68+
}
69+
70+
private CultureInfo CurrentCulture
71+
{
72+
get
73+
{
74+
return CultureInfo.CurrentCulture;
75+
}
76+
set
77+
{
78+
CultureInfo.CurrentCulture = value;
79+
}
80+
}
81+
82+
public static object[][] GetTestCases()
83+
{
84+
return [
85+
[new CultureInfo("en-US"), new CultureInfo("de-DE")],
86+
[new CultureInfo("en-US"), new CultureInfo("ar-SA", false)],
87+
[new CultureInfo("en-US"), new CultureInfo("th-TH", false)],
88+
];
89+
}
90+
}
91+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.NHSpecificTest.GH3530">
4+
<class name="LocaleEntity">
5+
<id name="Id" generator="guid.comb" />
6+
<property name="IntegerValue" column="IntegerValue"/>
7+
<property name="DateTimeValue" column="DateTimeValue"/>
8+
<property name="DoubleValue" column="DoubleValue"/>
9+
</class>
10+
</hibernate-mapping>

0 commit comments

Comments
 (0)