From: Michael D. <mik...@us...> - 2004-11-03 03:37:19
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10534/NHibernate.Test/NHSpecificTest Added Files: BasicTimeFixture.cs Log Message: Moved TimeType to its own test classes in the NHSpecific area and out of the ported classes. MySql does not follow the DbType.Time docs so this will help to isolate failing tests to just that datatype. --- NEW FILE: BasicTimeFixture.cs --- using System; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { /// <summary> /// Tests for mapping a type="Time" for a DateTime Property to a database field. /// </summary> [TestFixture] public class BasicTimeFixture : TestCase { [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.BasicTime.hbm.xml"}, true ); } [Test] public void Insert() { BasicTime basic = Create(1); ISession s = sessions.OpenSession(); s.Save(basic); s.Flush(); s.Close(); s = sessions.OpenSession(); BasicTime basicLoaded = (BasicTime)s.Load( typeof(BasicTime), 1 ); Assert.IsNotNull( basicLoaded ); Assert.IsFalse( basic==basicLoaded ); Assert.AreEqual( basic.TimeValue.Hour, basicLoaded.TimeValue.Hour ); Assert.AreEqual( basic.TimeValue.Minute, basicLoaded.TimeValue.Minute ); Assert.AreEqual( basic.TimeValue.Second, basicLoaded.TimeValue.Second ); s.Delete( basicLoaded ); s.Flush(); s.Close(); } [Test] public void TimeArray() { BasicTime basic = Create(1); ISession s = sessions.OpenSession(); s.Save(basic); s.Flush(); s.Close(); s = sessions.OpenSession(); BasicTime basicLoaded = (BasicTime)s.Load( typeof(BasicTime), 1 ); Assert.AreEqual( 0, basicLoaded.TimeArray.Length ); basicLoaded.TimeArray = new DateTime[] {new DateTime( 2000, 01, 01, 12, 1, 1 ), new DateTime(1500, 1, 1) }; s.Flush(); s.Close(); s = sessions.OpenSession(); basic = (BasicTime)s.Load( typeof(BasicTime), 1 ); // make sure the 0 index saved with values in Time Assert.AreEqual( 12, basic.TimeArray[0].Hour ); Assert.AreEqual( 1, basic.TimeArray[0].Minute ); Assert.AreEqual( 1, basic.TimeArray[0].Second ); // make sure the value below 1753 was not written to db - per msdn docs // meaning of DbType.Time. If not written to the db it will have the value // of an uninitialized DateTime - which is the min value. Assert.AreEqual( DateTime.MinValue, basic.TimeArray[1], "date before 1753 should not have been written" ); s.Delete( basic ); s.Flush(); s.Close(); } [Test] public void Update() { BasicTime basic = Create(1); ISession s = sessions.OpenSession(); s.Save( basic ); s.Flush(); s.Close(); s = sessions.OpenSession(); basic = (BasicTime)s.Load( typeof(BasicTime), 1 ); basic.TimeValue = new DateTime( 2000, 12, 1, 13, 1, 2 ); s.Flush(); s.Close(); s = sessions.OpenSession(); // make sure the update went through BasicTime basicLoaded = (BasicTime)s.Load( typeof(BasicTime), 1 ); Assert.AreEqual( 13, basicLoaded.TimeValue.Hour ); Assert.AreEqual( 1, basicLoaded.TimeValue.Minute ); Assert.AreEqual( 2, basicLoaded.TimeValue.Second ); s.Delete( basicLoaded ); s.Flush(); s.Close(); } private BasicTime Create(int id) { BasicTime basic = new BasicTime(); basic.Id = id; basic.TimeValue = new DateTime(1753, 01, 01, 12, 00, 00, 00 ); return basic; } } } |