|
From: <dar...@us...> - 2009-02-06 14:58:53
|
Revision: 4058
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4058&view=rev
Author: darioquintana
Date: 2009-02-06 14:58:31 +0000 (Fri, 06 Feb 2009)
Log Message:
-----------
- Bug fixed: TimeSpanType prepared to work with TimeSpan or DateTime, depends on dialect.
- Tests specifics for DbType supported
- Fixes in Tests
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs 2009-02-06 13:40:28 UTC (rev 4057)
+++ trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs 2009-02-06 14:58:31 UTC (rev 4058)
@@ -29,7 +29,12 @@
{
try
{
- return (TimeSpan)rs[index];
+ object value = rs[index];
+ if(value is TimeSpan)
+ return (TimeSpan)value;
+
+ DateTime time = (DateTime)rs[index];
+ return new TimeSpan(Convert.ToInt64(time.Ticks));
}
catch (Exception ex)
{
@@ -41,9 +46,12 @@
{
try
{
- //DateTime time = (DateTime)rs[name];
- //return new TimeSpan(Convert.ToInt64(time.Ticks));
- return (TimeSpan)rs[name];
+ object value = rs[name];
+ if (value is TimeSpan) //For those dialects where DbType.Time means TimeSpan.
+ return (TimeSpan)value;
+
+ DateTime time = (DateTime)rs[name];
+ return new TimeSpan(Convert.ToInt64(time.Ticks));
}
catch (Exception ex)
{
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs 2009-02-06 13:40:28 UTC (rev 4057)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs 2009-02-06 14:58:31 UTC (rev 4058)
@@ -1,5 +1,6 @@
using System;
using System.Collections;
+using System.Data;
using NUnit.Framework;
namespace NHibernate.Test.NHSpecificTest.Dates
@@ -12,6 +13,11 @@
get { return new[] {"NHSpecificTest.Dates.Mappings.DateTime2.hbm.xml"}; }
}
+ protected override DbType? AppliesTo()
+ {
+ return DbType.DateTime2;
+ }
+
[Test]
public void SavingAndRetrievingTest()
{
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs 2009-02-06 13:40:28 UTC (rev 4057)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs 2009-02-06 14:58:31 UTC (rev 4058)
@@ -1,5 +1,6 @@
using System;
using System.Collections;
+using System.Data;
using NUnit.Framework;
namespace NHibernate.Test.NHSpecificTest.Dates
@@ -12,6 +13,11 @@
get { return new[] {"NHSpecificTest.Dates.Mappings.DateTimeOffset.hbm.xml"}; }
}
+ protected override DbType? AppliesTo()
+ {
+ return DbType.DateTimeOffset;
+ }
+
[Test]
public void SavingAndRetrievingTest()
{
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs 2009-02-06 13:40:28 UTC (rev 4057)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs 2009-02-06 14:58:31 UTC (rev 4058)
@@ -1,6 +1,8 @@
using System;
using System.Collections;
+using System.Data;
using NHibernate.Dialect;
+using NHibernate.Util;
using NUnit.Framework;
namespace NHibernate.Test.NHSpecificTest.Dates
@@ -17,7 +19,25 @@
protected override bool AppliesTo(Dialect.Dialect dialect)
{
- return dialect is MsSql2008Dialect;
+ var typeNames = (TypeNames)typeof(Dialect.Dialect).GetField("typeNames", ReflectHelper.AnyVisibilityInstance).GetValue(Dialect);
+ try
+ {
+ var value = AppliesTo();
+
+ if (value == null) return true;
+
+ typeNames.Get(value.Value);
+ }
+ catch (ArgumentException arg)
+ {
+ return false;
+ }
+ catch (Exception arg)
+ {
+ Assert.Fail("Probably a bug in the test case.");
+ }
+
+ return true;
}
protected void SavingAndRetrievingAction(AllDates entity, Action<AllDates> action)
@@ -47,5 +67,10 @@
tx.Commit();
}
}
+
+ protected virtual DbType? AppliesTo()
+ {
+ return null;
+ }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs 2009-02-06 13:40:28 UTC (rev 4057)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs 2009-02-06 14:58:31 UTC (rev 4058)
@@ -1,5 +1,6 @@
using System;
using System.Collections;
+using NHibernate.Dialect;
using NUnit.Framework;
namespace NHibernate.Test.NHSpecificTest.Dates
@@ -16,8 +17,17 @@
public void SavingAndRetrievingTest()
{
var now = DateTime.Parse("23:59:59").TimeOfDay;
+
SavingAndRetrievingAction(new AllDates {Sql_time = now},
- entity => Assert.AreEqual(entity.Sql_time, now));
+ entity =>
+ {
+ Assert.AreEqual(entity.Sql_time.Hours, now.Hours);
+ Assert.AreEqual(entity.Sql_time.Minutes, now.Minutes);
+ Assert.AreEqual(entity.Sql_time.Seconds, now.Seconds);
+ });
+
+ if(Dialect is MsSql2008Dialect)
+ SavingAndRetrievingAction(new AllDates { Sql_time = now }, entity => Assert.AreEqual(entity.Sql_time, now));
}
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs 2009-02-06 13:40:28 UTC (rev 4057)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs 2009-02-06 14:58:31 UTC (rev 4058)
@@ -1,4 +1,5 @@
using System;
+using NHibernate.Dialect;
using NHibernate.Type;
using NUnit.Framework;
@@ -61,7 +62,13 @@
using (ITransaction tx = s.BeginTransaction())
{
entityReturned = s.CreateQuery("from TimeSpanClass").UniqueResult<TimeSpanClass>();
- Assert.AreEqual(ticks, entityReturned.TimeSpanValue);
+
+ if(Dialect is MsSql2008Dialect)
+ Assert.AreEqual(ticks, entityReturned.TimeSpanValue);
+
+ Assert.AreEqual(entityReturned.TimeSpanValue.Hours,ticks.Hours);
+ Assert.AreEqual(entityReturned.TimeSpanValue.Minutes, ticks.Minutes);
+ Assert.AreEqual(entityReturned.TimeSpanValue.Seconds, ticks.Seconds);
}
using (ISession s = OpenSession())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|