From: <aye...@us...> - 2008-07-18 06:51:54
|
Revision: 3639 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3639&view=rev Author: ayenderahien Date: 2008-07-18 06:52:02 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Applying patch from Will Shaver for NH-1291, Example.Create with anonymous objects Adding tests Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Home.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/NH1291AnonExampleFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Person.cs Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Home.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Home.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Home.cs 2008-07-18 06:52:02 UTC (rev 3639) @@ -0,0 +1,38 @@ +namespace NHibernate.Test.NHSpecificTest.NH1291AnonExample +{ + public class Home + { + private int id; + private int zip; + private string city; + + public Home() + { + + } + + public Home(string city, int zip) + { + this.city = city; + this.zip = zip; + } + + virtual public int Id + { + get { return id; } + set { id = value; } + } + + virtual public string City + { + get { return city; } + set { city = value; } + } + + virtual public int Zip + { + get { return zip; } + set { zip = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Mappings.hbm.xml 2008-07-18 06:52:02 UTC (rev 3639) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1291AnonExample"> + + <class name="Person" lazy="false"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="Name"/> + <property name="IQ"/> + <property name="ShoeSize"/> + <many-to-one name="Home" column="HomeID" /> + </class> + + <class name="Home" lazy="false"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="City"/> + <property name="Zip"/> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/NH1291AnonExampleFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/NH1291AnonExampleFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/NH1291AnonExampleFixture.cs 2008-07-18 06:52:02 UTC (rev 3639) @@ -0,0 +1,185 @@ +using System.Collections; +using System.Collections.Generic; +using NHibernate.Criterion; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1291AnonExample +{ + [TestFixture] + public class NH1291AnonExampleFixture : BugTestCase + { + public override string BugNumber + { + get { return "NH1291AnonExample"; } + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using(ISession session = OpenSession()) + { + using(ITransaction tx = session.BeginTransaction()) + { + session.Delete("from Person"); + session.Delete("from Home"); + tx.Commit(); + } + } + } + + protected override void OnSetUp() + { + using(ISession s = OpenSession()) + { + using(ITransaction tx = s.BeginTransaction()) + { + Person e1 = new Person("Joe", 10, 9); + Person e2 = new Person("Sally", 20, 8); + Person e3 = new Person("Tim", 20, 7); //20 + Person e4 = new Person("Fred", 40, 40); + Person e5 = new Person("Fred", 50, 50); + s.Save(e1); + s.Save(e2); + s.Save(e3); + s.Save(e4); + s.Save(e5); + tx.Commit(); + } + } + } + + protected class PersonIQAnon + { + private int _iq; + public PersonIQAnon(int iq) + { + IQ = iq; + } + + public int IQ + { + get { return _iq; } + set { _iq = value; } + } + } + + + + [Test] + public void CanCreateAnonExampleForInt() + { + using(ISession s = OpenSession()) + { + using(ITransaction tx = s.BeginTransaction()) + { + IList list = s.CreateCriteria(typeof(Person)) + .Add(Example.Create(new PersonIQAnon(40))).List(); + //c# 3.5: Example.Create( new { IQ = 40 } ) + Assert.AreEqual(1, list.Count); + Assert.AreEqual("Fred", ((Person)list[0]).Name); + tx.Commit(); + } + } + } + + protected class PersonNameAnon + { + private string name; + + public PersonNameAnon(string name) + { + Name = name; + } + + virtual public string Name + { + get { return name; } + set { name = value; } + } + } + + [Test] + public void CanCreateAnonExampleForStringLikeCompare() + { + using(ISession s = OpenSession()) + { + using(ITransaction tx = s.BeginTransaction()) + { + IList list = s.CreateCriteria(typeof(Person)) + .Add(Example.Create(new PersonNameAnon("%all%")).EnableLike()).List(); + //c# 3.5: Example.Create( new { Name = "%all%" } ) + Assert.AreEqual(1, list.Count); + Assert.AreEqual("Sally", ((Person)list[0]).Name); + tx.Commit(); + } + } + } + + [Test] + public void CanQueryUsingSavedRelations() + { + using(ISession s = OpenSession()) + { + using(ITransaction tx = s.BeginTransaction()) + { + IList<Person> people = s.CreateCriteria(typeof(Person)).List<Person>(); + Home h1 = new Home("Eugene", 97402); + Home h2 = new Home("Klamath Falls", 97603); + people[0].Home = h1; + people[1].Home = h2; + s.Save(h1); + s.Save(h2); + + IList list = s.CreateCriteria(typeof(Person)).CreateCriteria("Home") + .Add(Example.Create(h1)).List(); + + Assert.AreEqual(1, list.Count); + Assert.AreEqual("Joe", ((Person)list[0]).Name); + tx.Commit(); + } + } + } + + protected class HomeAnon + { + private int zip; + + public HomeAnon(int zip) + { + Zip = zip; + } + + virtual public int Zip + { + get { return zip; } + set { zip = value; } + } + } + + [Test] + public void CanQueryUsingAnonRelations() + { + using(ISession s = OpenSession()) + { + using(ITransaction tx = s.BeginTransaction()) + { + IList<Person> people = s.CreateCriteria(typeof(Person)).List<Person>(); + Home h1 = new Home("Eugene", 97402); + Home h2 = new Home("Klamath Falls", 97603); + people[0].Home = h1; + people[1].Home = h2; + s.Save(h1); + s.Save(h2); + + IList list = s.CreateCriteria(typeof(Person)) + .CreateCriteria("Home").Add(Example.Create(new HomeAnon(97402))).List(); + //c# 3.5: Example.Create( new { Zip = 97402 } ) + + Assert.AreEqual(1, list.Count); + Assert.AreEqual("Joe", ((Person)list[0]).Name); + tx.Commit(); + } + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Person.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Person.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1291AnonExample/Person.cs 2008-07-18 06:52:02 UTC (rev 3639) @@ -0,0 +1,54 @@ +namespace NHibernate.Test.NHSpecificTest.NH1291AnonExample +{ + public class Person + { + private int id; + private int iq; + private int shoeSize; + private string name; + private Home home; + + public Person() + { + + } + + public Person(string name, int iq, int shoeSize) + { + this.name = name; + this.iq = iq; + this.shoeSize = shoeSize; + } + + virtual public int Id + { + get { return id; } + set { id = value; } + } + + virtual public string Name + { + get { return name; } + set { name = value; } + } + + virtual public int IQ + { + get { return iq; } + set { iq = value; } + } + + virtual public int ShoeSize + { + get { return shoeSize; } + set { shoeSize = value; } + } + + virtual public Home Home + { + get { return home; } + set { home = value; } + } + + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |