Skip to content

Commit 1deef2b

Browse files
David EllingsworthDavid Ellingsworth
authored andcommitted
GH-3530: Add additional test that uses the DateTime type with the
dilect's suggested type. Perform some minor cleanup recommended by the DeepSource analysis.
1 parent 7e68ad0 commit 1deef2b

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/NHibernate.Test/NHSpecificTest/GH3530/Entities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ public class DateTimeEntity : Entity<DateTime> { }
2222

2323
public class DoubleEntity : Entity<double> { }
2424
public class DecimalEntity : Entity<decimal> { }
25+
public class NHDateTimeEntity : Entity<DateTime> { }
2526
}

src/NHibernate.Test/NHSpecificTest/GH3530/Fixture.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ protected override void CreateSchema()
4242
CreateTable("DateTime");
4343
CreateTable("Double");
4444
CreateTable("Decimal");
45+
46+
base.CreateSchema();
4547
}
4648

49+
/// <summary>
50+
/// This function creates the schema for our custom entities.
51+
/// If the SchemaExporter provided a mechanism to override the database
52+
/// type, this method would not be required.
53+
/// </summary>
54+
/// <param name="name"></param>
4755
private void CreateTable(string name)
4856
{
4957
var sb = new StringBuilder();
@@ -131,6 +139,14 @@ private void PerformTest<T, U>(CultureInfo from, CultureInfo to, T expectedValue
131139
}
132140
}
133141

142+
[Test, TestCaseSource(nameof(GetTestCases))]
143+
public void TestNHDateTime(CultureInfo from, CultureInfo to)
144+
{
145+
DateTime leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish));
146+
147+
PerformTest<DateTime, NHDateTimeEntity>(from, to, leapDay, (expected, actual) => Assert.AreEqual(expected, actual));
148+
}
149+
134150
[Test, TestCaseSource(nameof(GetTestCases))]
135151
public void TestDateTime(CultureInfo from, CultureInfo to)
136152
{
@@ -168,14 +184,8 @@ public void TestInteger(CultureInfo from, CultureInfo to)
168184

169185
private CultureInfo CurrentCulture
170186
{
171-
get
172-
{
173-
return CultureInfo.CurrentCulture;
174-
}
175-
set
176-
{
177-
CultureInfo.CurrentCulture = value;
178-
}
187+
get => CultureInfo.CurrentCulture;
188+
set => CultureInfo.CurrentCulture = value;
179189
}
180190

181191
public static object[][] GetTestCases()

src/NHibernate.Test/NHSpecificTest/GH3530/Mappings.hbm.xml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
33
namespace="NHibernate.Test.NHSpecificTest.GH3530">
4-
<class name="IntegerEntity">
4+
<!--
5+
The following classes have custom-built schema to override the
6+
database column type to a text type as the SchemaExporter does
7+
not provide a mechanism of doing this, hence they have a
8+
schema-action of 'none'.
9+
-->
10+
<class name="IntegerEntity" schema-action="none">
511
<id name="Id" generator="guid.comb" />
612
<property name="DataValue" column="DataValue"/>
713
</class>
8-
<class name="DateTimeEntity">
14+
<class name="DateTimeEntity" schema-action="none">
915
<id name="Id" generator="guid.comb" />
1016
<property name="DataValue" column="DataValue"/>
1117
</class>
12-
<class name="DoubleEntity">
18+
<class name="DoubleEntity" schema-action="none">
1319
<id name="Id" generator="guid.comb" />
1420
<property name="DataValue" column="DataValue"/>
1521
</class>
16-
<class name="DecimalEntity">
22+
<class name="DecimalEntity" schema-action="none">
23+
<id name="Id" generator="guid.comb" />
24+
<property name="DataValue" column="DataValue"/>
25+
</class>
26+
27+
<!--
28+
The following classes will be exported as expected by the SchemaExport.
29+
-->
30+
<class name="NHDateTimeEntity">
1731
<id name="Id" generator="guid.comb" />
1832
<property name="DataValue" column="DataValue"/>
1933
</class>

0 commit comments

Comments
 (0)