From: Sergey K. <jus...@us...> - 2005-05-06 23:41:57
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6714/src/NHibernate.Test/NHSpecificTest Modified Files: BasicClassFixture.cs BasicObjectFixture.cs BasicSerializableFixture.cs BasicTimeFixture.cs CollectionFixture.cs GetTest.cs LazyLoadBugTest.cs MapFixture.cs NH47Fixture.cs NodeFixture.cs SimpleComponentFixture.cs SimpleFooBarFixture.cs UnsavedValueFixture.cs UserTypeFixture.cs Log Message: Major TestCase refactoring: - schema is now always set up in TestCase.TestFixtureSetUp and dropped in TestCase.TestFixtureTearDown - added property Mappings and MappingsAssembly to specify mappings declaratively instead of manually calling SchemaExport ! all tests now have to clean up the database after themselves! This is checked in TestCase.TearDown. - test cases not cleaning up the database were fixed - SetUp and TearDown are non-virtual, test writers are supposed to override OnSetUp and OnTearDown instead. - Added TypeFixtureBase for type-related fixtures to reduce code duplication somewhat These modifications sped up tests 10 times on my machine. Index: BasicClassFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/BasicClassFixture.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** BasicClassFixture.cs 5 May 2005 19:27:55 -0000 1.13 --- BasicClassFixture.cs 6 May 2005 23:41:17 -0000 1.14 *************** *** 14,22 **** public class BasicClassFixture : TestCase { ! ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.BasicClass.hbm.xml"}, true ); } --- 14,23 ---- public class BasicClassFixture : TestCase { ! protected override IList Mappings { ! get ! { ! return new string[] { "NHSpecific.BasicClass.hbm.xml"}; ! } } *************** *** 43,46 **** --- 44,49 ---- bc = (BasicClass)s.Load( typeof(BasicClass), (int)1 ); Assert.AreEqual( 5, bc.ValueOfPrivateField, "private field accessor" ); + s.Delete( bc ); + s.Flush(); s.Close(); } *************** *** 665,668 **** --- 668,674 ---- s.Refresh( bc ); Assert.AreEqual( originalCount + 1, bc.StringBag.Count, "was refreshed correctly" ); + + s.Delete( bc ); + s.Flush(); s.Close(); } Index: CollectionFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/CollectionFixture.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CollectionFixture.cs 5 May 2005 19:27:55 -0000 1.2 --- CollectionFixture.cs 6 May 2005 23:41:17 -0000 1.3 *************** *** 13,20 **** public class CollectionFixture : TestCase { ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.LazyLoadBug.hbm.xml"} ); } --- 13,31 ---- public class CollectionFixture : TestCase { ! protected override System.Collections.IList Mappings { ! get ! { ! return new string[] { "NHSpecific.LazyLoadBug.hbm.xml"}; ! } ! } ! ! protected override void OnTearDown() ! { ! using( ISession session = sessions.OpenSession() ) ! { ! session.Delete( "from LLParent" ); ! session.Flush(); ! } } Index: SimpleComponentFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/SimpleComponentFixture.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SimpleComponentFixture.cs 5 May 2005 19:27:55 -0000 1.3 --- SimpleComponentFixture.cs 6 May 2005 23:41:17 -0000 1.4 *************** *** 7,39 **** namespace NHibernate.Test.NHSpecificTest { - [TestFixture] ! public class SimpleCompenentFixture : TestCase { private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.SimpleComponent.hbm.xml"} ); } ! [Test] ! public void TestLoad() { ! ISession s = OpenSession(); ! ITransaction t = s.BeginTransaction(); - TestInsert(); ! SimpleComponent simpleComp = (SimpleComponent)s.Load(typeof(SimpleComponent), 10); ! Assert.AreEqual(10, simpleComp.Key); ! Assert.AreEqual("TestCreated", simpleComp.Audit.CreatedUserId); ! Assert.AreEqual("TestUpdated", simpleComp.Audit.UpdatedUserId); ! t.Commit(); ! s.Close(); } /// <summary> --- 7,72 ---- namespace NHibernate.Test.NHSpecificTest { [TestFixture] ! public class SimpleComponentFixture : TestCase { private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); + protected override System.Collections.IList Mappings + { + get + { + return new string[] { "NHSpecific.SimpleComponent.hbm.xml"}; + } + } ! protected override void OnSetUp() ! { ! using( ISession s = OpenSession() ) ! using( ITransaction t = s.BeginTransaction() ) ! { ! // create a new ! SimpleComponent simpleComp = new SimpleComponent(); ! simpleComp.Name = "Simple 1"; ! simpleComp.Address = "Street 12"; ! simpleComp.Date = testDateTime; ! simpleComp.Count = 99; ! simpleComp.Audit.CreatedDate = System.DateTime.Now; ! simpleComp.Audit.CreatedUserId = "TestCreated"; ! simpleComp.Audit.UpdatedDate = System.DateTime.Now; ! simpleComp.Audit.UpdatedUserId = "TestUpdated"; ! ! ! s.Save(simpleComp, 10); ! ! t.Commit(); ! } } ! protected override void OnTearDown() ! { ! using( ISession s = OpenSession() ) ! { ! s.Delete( s.Load( typeof( SimpleComponent ), 10 ) ); ! s.Flush(); ! } ! } ! [Test] ! public void TestLoad() ! { ! using( ISession s = OpenSession() ) ! using( ITransaction t = s.BeginTransaction() ) ! { ! SimpleComponent simpleComp = (SimpleComponent)s.Load(typeof(SimpleComponent), 10); ! Assert.AreEqual(10, simpleComp.Key); ! Assert.AreEqual("TestCreated", simpleComp.Audit.CreatedUserId); ! Assert.AreEqual("TestUpdated", simpleComp.Audit.UpdatedUserId); + t.Commit(); + } } /// <summary> *************** *** 42,68 **** /// </summary> [Test] ! public void TestInsert() { ! ! ISession s = OpenSession(); ! ITransaction t = s.BeginTransaction(); ! ! // create a new ! SimpleComponent simpleComp = new SimpleComponent(); ! simpleComp.Name = "Simple 1"; ! simpleComp.Address = "Street 12"; ! simpleComp.Date = testDateTime; ! simpleComp.Count = 99; ! simpleComp.Audit.CreatedDate = System.DateTime.Now; ! simpleComp.Audit.CreatedUserId = "TestCreated"; ! simpleComp.Audit.UpdatedDate = System.DateTime.Now; ! simpleComp.Audit.UpdatedUserId = "TestUpdated"; ! ! ! s.Save(simpleComp, 10); ! ! t.Commit(); ! s.Close(); ! ! } } --- 75,81 ---- /// </summary> [Test] ! public void TestInsert() ! { ! // Do nothing, all the action is in OnSetUp. } } Index: UnsavedValueFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/UnsavedValueFixture.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** UnsavedValueFixture.cs 5 May 2005 19:27:55 -0000 1.4 --- UnsavedValueFixture.cs 6 May 2005 23:41:17 -0000 1.5 *************** *** 15,22 **** public static int newId = 0; ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.UnsavedType.hbm.xml"}); } --- 15,24 ---- public static int newId = 0; ! protected override IList Mappings { ! get ! { ! return new string[] { "NHSpecific.UnsavedType.hbm.xml"}; ! } } Index: BasicSerializableFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/BasicSerializableFixture.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BasicSerializableFixture.cs 5 May 2005 19:27:55 -0000 1.2 --- BasicSerializableFixture.cs 6 May 2005 23:41:17 -0000 1.3 *************** *** 16,25 **** [TestFixture] public class BasicSerializableFixture : TestCase ! { ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.BasicSerializable.hbm.xml"}, true ); } --- 16,27 ---- [TestFixture] public class BasicSerializableFixture : TestCase ! { ! protected override IList Mappings { ! get ! { ! return new string[] { "NHSpecific.BasicSerializable.hbm.xml"}; ! } } Index: SimpleFooBarFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/SimpleFooBarFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SimpleFooBarFixture.cs 26 Mar 2005 12:18:54 -0000 1.1 --- SimpleFooBarFixture.cs 6 May 2005 23:41:17 -0000 1.2 *************** *** 11,19 **** public class SimpleFooBarFixture : TestCase { ! ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "FooBar.hbm.xml"} ); } --- 11,20 ---- public class SimpleFooBarFixture : TestCase { ! protected override System.Collections.IList Mappings { ! get ! { ! return new string[] { "FooBar.hbm.xml"}; ! } } Index: UserTypeFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/UserTypeFixture.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** UserTypeFixture.cs 5 May 2005 19:27:55 -0000 1.2 --- UserTypeFixture.cs 6 May 2005 23:41:17 -0000 1.3 *************** *** 14,22 **** public class UserTypeFixture : TestCase { ! ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.ClassWithNullColumns.hbm.xml"}, true ); } --- 14,23 ---- public class UserTypeFixture : TestCase { ! protected override System.Collections.IList Mappings { ! get ! { ! return new string[] { "NHSpecific.ClassWithNullColumns.hbm.xml"}; ! } } *************** *** 28,41 **** public void InsertNull() { ! ISession s = OpenSession(); ! ! ClassWithNullColumns userTypeClass = new ClassWithNullColumns(); ! userTypeClass.Id = 5; ! userTypeClass.FirstInt32 = 4; ! userTypeClass.SecondInt32 = 0; // with the user type should set value to null ! s.Save(userTypeClass); ! s.Flush(); ! s.Close(); // manually read from the db --- 29,42 ---- public void InsertNull() { ! using( ISession s = OpenSession() ) ! { ! ClassWithNullColumns userTypeClass = new ClassWithNullColumns(); ! userTypeClass.Id = 5; ! userTypeClass.FirstInt32 = 4; ! userTypeClass.SecondInt32 = 0; // with the user type should set value to null ! s.Save(userTypeClass); ! s.Flush(); ! } // manually read from the db *************** *** 57,60 **** --- 58,67 ---- conn.Close(); + + using( ISession s = OpenSession() ) + { + s.Delete( "from ClassWithNullColumns" ); + s.Flush(); + } } } Index: BasicObjectFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/BasicObjectFixture.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** BasicObjectFixture.cs 5 May 2005 19:27:55 -0000 1.4 --- BasicObjectFixture.cs 6 May 2005 23:41:17 -0000 1.5 *************** *** 20,28 **** public class BasicObjectFixture : TestCase { ! ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.BasicObject.hbm.xml"}, true ); } --- 20,29 ---- public class BasicObjectFixture : TestCase { ! protected override System.Collections.IList Mappings { ! get ! { ! return new string[] { "NHSpecific.BasicObject.hbm.xml"}; ! } } Index: BasicTimeFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/BasicTimeFixture.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BasicTimeFixture.cs 5 May 2005 19:27:55 -0000 1.2 --- BasicTimeFixture.cs 6 May 2005 23:41:17 -0000 1.3 *************** *** 14,21 **** public class BasicTimeFixture : TestCase { ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.BasicTime.hbm.xml"}, true ); } --- 14,23 ---- public class BasicTimeFixture : TestCase { ! protected override System.Collections.IList Mappings { ! get ! { ! return new string[] { "NHSpecific.BasicTime.hbm.xml"}; ! } } Index: NH47Fixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/NH47Fixture.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NH47Fixture.cs 5 May 2005 19:27:55 -0000 1.3 --- NH47Fixture.cs 6 May 2005 23:41:17 -0000 1.4 *************** *** 15,22 **** public class NH47Fxiture : TestCase { ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.UnsavedType.hbm.xml"}); } --- 15,24 ---- public class NH47Fxiture : TestCase { ! protected override IList Mappings { ! get ! { ! return new string[] { "NHSpecific.UnsavedType.hbm.xml"}; ! } } Index: LazyLoadBugTest.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/LazyLoadBugTest.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** LazyLoadBugTest.cs 5 May 2005 19:27:55 -0000 1.3 --- LazyLoadBugTest.cs 6 May 2005 23:41:17 -0000 1.4 *************** *** 9,16 **** public class LazyLoadBugTest : TestCase { ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.LazyLoadBug.hbm.xml"} ); } --- 9,18 ---- public class LazyLoadBugTest : TestCase { ! protected override System.Collections.IList Mappings { ! get ! { ! return new string[] { "NHSpecific.LazyLoadBug.hbm.xml" }; ! } } *************** *** 35,49 **** } ! // try to Load the object to get the exception ! using( ISession s2 = OpenSession() ) ! using( ITransaction t2 = s2.BeginTransaction() ) { ! LLParent parent2 = (LLParent)s2.Load( typeof(LLParent), parentId ); ! // this should throw the exception - the property setter access is not mapped correctly. ! // Because it maintains logic to maintain the collection during the property set it should ! // tell NHibernate to skip the setter and access the field. If it doesn't, then throw ! // a LazyInitializationException. ! int count = parent2.Children.Count; } } --- 37,61 ---- } ! try { ! // try to Load the object to get the exception ! using( ISession s2 = OpenSession() ) ! using( ITransaction t2 = s2.BeginTransaction() ) ! { ! LLParent parent2 = (LLParent)s2.Load( typeof(LLParent), parentId ); ! // this should throw the exception - the property setter access is not mapped correctly. ! // Because it maintains logic to maintain the collection during the property set it should ! // tell NHibernate to skip the setter and access the field. If it doesn't, then throw ! // a LazyInitializationException. ! int count = parent2.Children.Count; ! } ! } ! finally ! { ! // Need to delete the objects using direct SQL in this case, ! // because of loading problems. ! ExecuteStatement( "delete from LLChild" ); ! ExecuteStatement( "delete from LLParent" ); } } *************** *** 76,79 **** --- 88,97 ---- Assert.AreEqual( 1, parent2.ChildrenNoAdd.Count ); } + + using( ISession session = sessions.OpenSession() ) + { + session.Delete( "from LLParent" ); + session.Flush(); + } } } Index: MapFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/MapFixture.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MapFixture.cs 5 May 2005 19:27:55 -0000 1.4 --- MapFixture.cs 6 May 2005 23:41:17 -0000 1.5 *************** *** 12,30 **** /// </summary> [TestFixture] ! public class MapFixture : TestCase { ! private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { ! "NHSpecific.Parent.hbm.xml", ! "NHSpecific.Child.hbm.xml", ! "NHSpecific.SexType.hbm.xml", ! "NHSpecific.Team.hbm.xml" }, true); } [Test] [Ignore("Have not written the Test yet.")] --- 12,47 ---- /// </summary> [TestFixture] ! public class MapFixture : TestCase ! { private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); + protected override IList Mappings + { + get + { + return new string[] + { + "NHSpecific.Parent.hbm.xml", + "NHSpecific.Child.hbm.xml", + "NHSpecific.SexType.hbm.xml", + "NHSpecific.Team.hbm.xml" + }; + } + } ! protected override void OnTearDown() ! { ! using( ISession session = sessions.OpenSession() ) ! { ! session.Delete( "from Team" ); ! session.Delete( "from Child" ); ! session.Delete( "from Parent" ); ! session.Delete( "from SexType" ); ! session.Flush(); ! } } + [Test] [Ignore("Have not written the Test yet.")] *************** *** 52,56 **** Child childOneRef = amyJones.FirstSibling; - t.Commit(); s.Close(); --- 69,72 ---- Index: NodeFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/NodeFixture.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NodeFixture.cs 5 May 2005 19:27:55 -0000 1.5 --- NodeFixture.cs 6 May 2005 23:41:17 -0000 1.6 *************** *** 13,24 **** public class NodeFixture : TestCase { ! ! [SetUp] ! public void SetUp() { ! ExportSchema( new string[] { "NHSpecific.Node.hbm.xml"}, true ); } - [Test] public void InsertNodes() --- 13,24 ---- public class NodeFixture : TestCase { ! protected override IList Mappings { ! get ! { ! return new string[] { "NHSpecific.Node.hbm.xml"}; ! } } [Test] public void InsertNodes() *************** *** 133,136 **** --- 133,141 ---- s.Close(); + using( ISession s3 = OpenSession() ) + { + s3.Delete( "from Node" ); + s3.Flush(); + } } Index: GetTest.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/GetTest.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GetTest.cs 5 May 2005 19:27:55 -0000 1.4 --- GetTest.cs 6 May 2005 23:41:17 -0000 1.5 *************** *** 9,17 **** public class GetTest : TestCase { ! [SetUp] ! public void SetUp() { ! // A class with a proxy is needed to actually test Get vs Load. ! ExportSchema( new string[] { "ABCProxy.hbm.xml" }, true ); } --- 9,27 ---- public class GetTest : TestCase { ! protected override System.Collections.IList Mappings { ! get ! { ! return new string[] { "ABCProxy.hbm.xml" }; ! } ! } ! ! protected override void OnTearDown() ! { ! using( ISession s = sessions.OpenSession() ) ! { ! s.Delete( "from A" ); ! s.Flush(); ! } } |