From: Michael D. <mik...@us...> - 2005-01-05 02:44:56
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15832/NHibernate.Test/JoinedSubclass Modified Files: Address.cs Customer.cs Employee.cs JoinedSubclass.Customer.hbm.xml JoinedSubclass.Employee.hbm.xml JoinedSubclass.hbm.xml JoinedSubclass.Person.hbm.xml JoinedSubclassFixture.cs Person.cs Log Message: Modified JoinedSubclass tests to work with Proxies. Added another test to make sure NHibernateProxyHelper is working. Index: Employee.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/Employee.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Employee.cs 10 Dec 2004 16:40:03 -0000 1.1 --- Employee.cs 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 15,19 **** public Employee() {} ! public string Title { get { return _title; } --- 15,19 ---- public Employee() {} ! public virtual string Title { get { return _title; } *************** *** 21,25 **** } ! public Decimal Salary { get { return _salary; } --- 21,25 ---- } ! public virtual Decimal Salary { get { return _salary; } *************** *** 27,31 **** } ! public Employee Manager { get { return _manager; } --- 27,31 ---- } ! public virtual Employee Manager { get { return _manager; } Index: JoinedSubclass.hbm.xml =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/JoinedSubclass.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JoinedSubclass.hbm.xml 10 Dec 2004 16:40:03 -0000 1.1 --- JoinedSubclass.hbm.xml 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 15,18 **** --- 15,19 ---- name="NHibernate.Test.JoinedSubclass.Person, NHibernate.Test" table="person" + proxy="NHibernate.Test.JoinedSubclass.Person, NHibernate.Test" > <id *************** *** 38,41 **** --- 39,43 ---- name="NHibernate.Test.JoinedSubclass.Employee, NHibernate.Test" table="empl" + proxy="NHibernate.Test.JoinedSubclass.Employee, NHibernate.Test" > <key column="person_id"/> *************** *** 48,51 **** --- 50,54 ---- name="NHibernate.Test.JoinedSubclass.Customer, NHibernate.Test" table="cust" + proxy="NHibernate.Test.JoinedSubclass.Customer, NHibernate.Test" > <key column="person_id"/> Index: JoinedSubclassFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/JoinedSubclassFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JoinedSubclassFixture.cs 10 Dec 2004 16:40:03 -0000 1.1 --- JoinedSubclassFixture.cs 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 2,5 **** --- 2,7 ---- using System.Collections; + using NHibernate.Proxy; + using NUnit.Framework; *************** *** 79,83 **** { //TODO: proxies make this work ! // Assert.IsFalse( NHibernate.IsInitialized( c.Salesperson ) ); Assert.AreEqual( "Mark", c.Salesperson.Name ); } --- 81,85 ---- { //TODO: proxies make this work ! Assert.IsFalse( NHibernate.IsInitialized( c.Salesperson ) ); Assert.AreEqual( "Mark", c.Salesperson.Name ); } *************** *** 102,105 **** --- 104,155 ---- } + [Test] + public void TestHql() + { + // test the Save + ISession s = sessions.OpenSession(); + ITransaction t = s.BeginTransaction(); + + Employee wally = new Employee(); + wally.Name = "wally"; + wally.Title = "Unmanaged Employee"; + + Employee dilbert = new Employee(); + dilbert.Name = "dilbert"; + dilbert.Title = "office clown"; + + Employee pointyhair = new Employee(); + pointyhair.Name = "pointyhair"; + pointyhair.Title = "clown watcher"; + + dilbert.Manager = pointyhair; + + s.Save( wally ); + s.Save( dilbert ); + s.Save( pointyhair ); + t.Commit(); + s.Close(); + + // get a proxied - initialized version of manager + s = sessions.OpenSession(); + pointyhair = (Employee) s.Load( typeof(Employee), pointyhair.Id ); + NHibernate.Initialize( pointyhair ); + s.Close(); + + s = sessions.OpenSession(); + IQuery q = s.CreateQuery( "from Employee as e where e.Manager = :theMgr" ); + q.SetParameter( "theMgr", pointyhair ); + IList results = q.List(); + Assert.AreEqual( 1, results.Count, "should only return 1 employee."); + dilbert = (Employee)results[0]; + Assert.AreEqual( "dilbert", dilbert.Name, "should have been dilbert returned."); + + s.Delete( wally ); + s.Delete( pointyhair ); + s.Delete( dilbert ); + s.Flush(); + s.Close(); + } + /// <summary> /// Test the ability to insert a new row with a User Assigned Key *************** *** 135,145 **** // perform a load based on the base class ! Person empAsPerson = (Person)s.Load( typeof(Person), empId ); person = (Person)s.Load( typeof(Person), personId ); ! // the object with id=2 was loaded using the base class - lets make sure it actually loaded // the sublcass ! emp = empAsPerson as Employee; ! Assert.IsNotNull(emp); // lets update the objects --- 185,195 ---- // perform a load based on the base class ! Person empAsPerson = (Person)s.Find( "from Person as p where p.id = ?", empId, NHibernate.Int32 )[0]; person = (Person)s.Load( typeof(Person), personId ); ! // the object with id=2 was loaded using the base class - lets make sure it actually loaded // the sublcass ! Assert.AreEqual( typeof(Employee), empAsPerson.GetType(), "even though person was queried, should have returned correct subclass."); ! emp = (Employee)s.Load( typeof(Employee), empId ); // lets update the objects *************** *** 151,154 **** --- 201,207 ---- emp.Title = "office dunce"; + // verify the it actually changes the same object + Assert.AreEqual( emp.Name, empAsPerson.Name, "emp and empAsPerson should refer to same object." ); + // save it through the base class reference and make sure that the // subclass properties get updated. Index: Customer.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/Customer.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Customer.cs 10 Dec 2004 16:40:03 -0000 1.1 --- Customer.cs 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 15,19 **** } ! public Employee Salesperson { get { return _salesperson; } --- 15,19 ---- } ! public virtual Employee Salesperson { get { return _salesperson; } *************** *** 21,25 **** } ! public string Comments { get { return _comments; } --- 21,25 ---- } ! public virtual string Comments { get { return _comments; } Index: JoinedSubclass.Employee.hbm.xml =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/JoinedSubclass.Employee.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JoinedSubclass.Employee.hbm.xml 10 Dec 2004 16:40:03 -0000 1.1 --- JoinedSubclass.Employee.hbm.xml 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 13,16 **** --- 13,17 ---- name="NHibernate.Test.JoinedSubclass.Employee, NHibernate.Test" table="j_sc_one" + proxy="NHibernate.Test.JoinedSubclass.Employee, NHibernate.Test" > <key column="person_id"/> Index: JoinedSubclass.Customer.hbm.xml =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/JoinedSubclass.Customer.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JoinedSubclass.Customer.hbm.xml 10 Dec 2004 16:40:03 -0000 1.1 --- JoinedSubclass.Customer.hbm.xml 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 1,3 **** ! <?xml version="1.0" encoding="utf-8" ?> --- 1,3 ---- ! <?xml version="1.0" encoding="utf-8" ?> *************** *** 16,19 **** --- 16,20 ---- name="NHibernate.Test.JoinedSubclass.Customer, NHibernate.Test" table="cust" + proxy="NHibernate.Test.JoinedSubclass.Customer, NHibernate.Test" > <key column="person_id"/> Index: JoinedSubclass.Person.hbm.xml =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/JoinedSubclass.Person.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JoinedSubclass.Person.hbm.xml 10 Dec 2004 16:40:03 -0000 1.1 --- JoinedSubclass.Person.hbm.xml 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- name="NHibernate.Test.JoinedSubclass.Person, NHibernate.Test" table="j_sc" + proxy="NHibernate.Test.JoinedSubclass.Person, NHibernate.Test" > <id Index: Person.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/Person.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Person.cs 10 Dec 2004 16:40:03 -0000 1.1 --- Person.cs 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 17,26 **** } ! public int Id { get { return _id; } } ! public string Name { get { return _name; } --- 17,26 ---- } ! public virtual int Id { get { return _id; } } ! public virtual string Name { get { return _name; } *************** *** 28,32 **** } ! public char Sex { get { return _sex; } --- 28,32 ---- } ! public virtual char Sex { get { return _sex; } *************** *** 34,38 **** } ! public Address Address { get { return _address; } --- 34,38 ---- } ! public virtual Address Address { get { return _address; } Index: Address.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/JoinedSubclass/Address.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Address.cs 10 Dec 2004 16:40:02 -0000 1.1 --- Address.cs 5 Jan 2005 02:44:18 -0000 1.2 *************** *** 16,20 **** } ! public string Street { get { return _street; } --- 16,20 ---- } ! public virtual string Street { get { return _street; } *************** *** 22,26 **** } ! public string Zip { get { return _zip; } --- 22,26 ---- } ! public virtual string Zip { get { return _zip; } *************** *** 28,32 **** } ! public string Country { get { return _country; } --- 28,32 ---- } ! public virtual string Country { get { return _country; } |