From: Michael D. <mik...@us...> - 2004-04-14 18:08:39
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/TypesTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28570/TypesTest Added Files: GuidTypeFixture.cs TypeFactoryFixture.cs Log Message: Added test for the classes GuidType and TypeFactory --- NEW FILE: TypeFactoryFixture.cs --- using System; using NHibernate.Type; using NUnit.Framework; namespace NHibernate.Test.TypesTest { /// <summary> /// Test Fixture for TypeFactory. /// </summary> [TestFixture] public class TypeFactoryFixture { /// <summary> /// Test that calling GetGuidType multiple times returns the /// exact same GuidType object by reference. /// </summary> [Test] public void GetGuidSingleton() { NullableType guidType = TypeFactory.GetGuidType(); NullableType guidType2 = TypeFactory.GetGuidType(); Assert.AreSame(guidType, guidType2); } /// <summary> /// Test that Strings with different lengths return different StringTypes. /// </summary> [Test] public void GetStringWithDiffLength() { NullableType string25 = TypeFactory.GetStringType(25); NullableType string30 = TypeFactory.GetStringType(30); Assert.IsFalse(string25==string30, "string25 & string30 should be different strings"); } /// <summary> /// Test that the String returned from NHibernate.String and TypeFactory.GetStringType /// returns the exact same Type. /// </summary> [Test] public void GetDefaultString() { NullableType stringFromNH = NHibernate.String; NullableType stringFromTF = TypeFactory.GetStringType(); Assert.AreSame(stringFromNH, stringFromTF); } } } --- NEW FILE: GuidTypeFixture.cs --- using System; using System.Data; using NHibernate.Type; using NUnit.Framework; namespace NHibernate.Test.TypesTest { /// <summary> /// The Unit Tests for the GuidType. /// </summary> [TestFixture] public class GuidTypeFixture : BaseTypeFixture { public GuidTypeFixture() { } /// <summary> /// Test that Get(IDataReader, index) returns a boxed Guid value that is what /// we expect. /// </summary> [Test] [Ignore("MockReader has not implemented GetGuid yet")] public void Get() { NullableType type = NHibernate.Guid; Guid expected = new Guid("{01234567-abcd-abcd-abcd-0123456789ab}"); // move to the first record reader.Read(); Guid actual = (Guid)type.Get(reader, GuidTypeColumnIndex); Assert.AreEqual(expected, actual); } [Test] public void EqualsTrue() { Guid lhs = new Guid("{01234567-abcd-abcd-abcd-0123456789ab}"); Guid rhs = new Guid("{01234567-abcd-abcd-abcd-0123456789ab}"); NullableType type = NHibernate.Guid; Assert.IsTrue(type.Equals(lhs, rhs)); } [Test] public void EqualsFalse() { Guid lhs = new Guid("{01234567-abcd-abcd-abcd-0123456789ab}"); Guid rhs = new Guid("{11234567-abcd-abcd-abcd-0123456789ab}"); NullableType type = NHibernate.Guid; Assert.IsFalse(type.Equals(lhs, rhs)); } /// <summary> /// Test to make sure that a boxed Guid and a struct Guid compare the /// same as two struct Guids. /// </summary> [Test] public void EqualsWithSnapshot() { Guid busObjValue = new Guid("{01234567-abcd-abcd-abcd-0123456789ab}"); object snapshotValue = busObjValue; NullableType type = NHibernate.Guid; Assert.IsTrue(type.Equals(busObjValue, snapshotValue)); // simulate the UI changing the busObjValue busObjValue = new Guid("{11234567-abcd-abcd-abcd-0123456789ab}"); Assert.IsFalse(type.Equals(busObjValue, snapshotValue)); } } } |