Skip to content

Commit

Permalink
nhibernateGH-3530: Add additional test that uses the DateTime type wi…
Browse files Browse the repository at this point in the history
…th the

dilect's suggested type.

Perform some minor cleanup recommended by the DeepSource analysis.
  • Loading branch information
David Ellingsworth authored and David Ellingsworth committed May 16, 2024
1 parent cf110fb commit 9ea1441
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3530/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public class DateTimeEntity : Entity<DateTime> { }

public class DoubleEntity : Entity<double> { }
public class DecimalEntity : Entity<decimal> { }
public class NHDateTimeEntity : Entity<DateTime> { }
}
26 changes: 18 additions & 8 deletions src/NHibernate.Test/NHSpecificTest/GH3530/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ protected override void CreateSchema()
CreateTable("DateTime");
CreateTable("Double");
CreateTable("Decimal");

base.CreateSchema();
}

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

[Test, TestCaseSource(nameof(GetTestCases))]
public void TestNHDateTime(CultureInfo from, CultureInfo to)
{
DateTime leapDay = new DateTime(2024, 2, 29, new GregorianCalendar(GregorianCalendarTypes.USEnglish));

PerformTest<DateTime, NHDateTimeEntity>(from, to, leapDay, (expected, actual) => Assert.AreEqual(expected, actual));
}

[Test, TestCaseSource(nameof(GetTestCases))]
public void TestDateTime(CultureInfo from, CultureInfo to)
{
Expand Down Expand Up @@ -168,14 +184,8 @@ public void TestInteger(CultureInfo from, CultureInfo to)

private CultureInfo CurrentCulture
{
get
{
return CultureInfo.CurrentCulture;
}
set
{
CultureInfo.CurrentCulture = value;
}
get => CultureInfo.CurrentCulture;
set => CultureInfo.CurrentCulture = value;
}

public static object[][] GetTestCases()
Expand Down
22 changes: 18 additions & 4 deletions src/NHibernate.Test/NHSpecificTest/GH3530/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.GH3530">
<class name="IntegerEntity">
<!--
The following classes have custom-built schema to override the
database column type to a text type as the SchemaExporter does
not provide a mechanism of doing this, hence they have a
schema-action of 'none'.
-->
<class name="IntegerEntity" schema-action="none">
<id name="Id" generator="guid.comb" />
<property name="DataValue" column="DataValue"/>
</class>
<class name="DateTimeEntity">
<class name="DateTimeEntity" schema-action="none">
<id name="Id" generator="guid.comb" />
<property name="DataValue" column="DataValue"/>
</class>
<class name="DoubleEntity">
<class name="DoubleEntity" schema-action="none">
<id name="Id" generator="guid.comb" />
<property name="DataValue" column="DataValue"/>
</class>
<class name="DecimalEntity">
<class name="DecimalEntity" schema-action="none">
<id name="Id" generator="guid.comb" />
<property name="DataValue" column="DataValue"/>
</class>

<!--
The following classes will be exported as expected by the SchemaExport.
-->
<class name="NHDateTimeEntity">
<id name="Id" generator="guid.comb" />
<property name="DataValue" column="DataValue"/>
</class>
Expand Down

0 comments on commit 9ea1441

Please sign in to comment.