From: <jul...@us...> - 2010-07-18 15:05:54
|
Revision: 5008 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5008&view=rev Author: julian-maughan Date: 2010-07-18 15:05:47 +0000 (Sun, 18 Jul 2010) Log Message: ----------- Added Hibernate component tests, and contributed test for issue NH-2061 (Merge operation causes exception for null components that contain many-to-many relations) Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs trunk/nhibernate/src/NHibernate.Test/Legacy/SQLLoaderTest.cs trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Component/ trunk/nhibernate/src/NHibernate.Test/Component/Basic/ trunk/nhibernate/src/NHibernate.Test/Component/Basic/ComponentTest.cs trunk/nhibernate/src/NHibernate.Test/Component/Basic/Employee.cs trunk/nhibernate/src/NHibernate.Test/Component/Basic/OptionalComponent.cs trunk/nhibernate/src/NHibernate.Test/Component/Basic/Person.cs trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.cs trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Model.cs Added: trunk/nhibernate/src/NHibernate.Test/Component/Basic/ComponentTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Component/Basic/ComponentTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Component/Basic/ComponentTest.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,417 @@ +using System; +using System.Collections.Generic; +using NHibernate; +using NHibernate.Cfg; +using NHibernate.Criterion; +using NHibernate.Transaction; +using NUnit.Framework; + +namespace NHibernate.Test.Component.Basic +{ + [TestFixture] + public class ComponentTest : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override System.Collections.IList Mappings + { + get { return new string[] { "Component.Basic.User.hbm.xml" }; } + } + + protected override void Configure(Configuration configuration) + { + configuration.SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true"); + } + + protected override void OnTearDown() + { + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Delete("from User"); + s.Delete("from Employee"); + t.Commit(); + } + + base.OnTearDown(); + } + + [Test] + public void TestUpdateFalse() + { + User u; + + sessions.Statistics.Clear(); + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + u = new User("gavin", "secret", new Person("Gavin King", new DateTime(1999, 12, 31), "Karbarook Ave")); + s.Persist(u); + s.Flush(); + u.Person.Name = "XXXXYYYYY"; + t.Commit(); + s.Close(); + } + + Assert.That(sessions.Statistics.EntityInsertCount, Is.EqualTo(1)); + Assert.That(sessions.Statistics.EntityUpdateCount, Is.EqualTo(0)); + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + u = (User)s.Get(typeof(User), "gavin"); + Assert.That(u.Person.Name, Is.EqualTo("Gavin King")); + s.Delete(u); + t.Commit(); + s.Close(); + } + + Assert.That(sessions.Statistics.EntityDeleteCount, Is.EqualTo(1)); + } + + [Test] + public void TestComponent() + { + User u; + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + u = new User("gavin", "secret", new Person("Gavin King", new DateTime(1999, 12, 31), "Karbarook Ave")); + s.Persist(u); + s.Flush(); + u.Person.ChangeAddress("Phipps Place"); + t.Commit(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + u = (User)s.Get(typeof(User), "gavin"); + Assert.That(u.Person.Address, Is.EqualTo("Phipps Place")); + Assert.That(u.Person.PreviousAddress, Is.EqualTo("Karbarook Ave")); + Assert.That(u.Person.Yob, Is.EqualTo(u.Person.Dob.Year)); + u.Password = "$ecret"; + t.Commit(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + u = (User)s.Get(typeof(User), "gavin"); + Assert.That(u.Person.Address, Is.EqualTo("Phipps Place")); + Assert.That(u.Person.PreviousAddress, Is.EqualTo("Karbarook Ave")); + Assert.That(u.Password, Is.EqualTo("$ecret")); + s.Delete(u); + t.Commit(); + } + } + + [Test] + public void TestComponentStateChangeAndDirtiness() + { + // test for HHH-2366 + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + User u = new User("steve", "hibernater", new Person( "Steve Ebersole", new DateTime(1999, 12, 31), "Main St")); + s.Persist(u); + s.Flush(); + long intialUpdateCount = sessions.Statistics.EntityUpdateCount; + u.Person.Address = "Austin"; + s.Flush(); + Assert.That(sessions.Statistics.EntityUpdateCount, Is.EqualTo(intialUpdateCount + 1)); + intialUpdateCount = sessions.Statistics.EntityUpdateCount; + u.Person.Address = "Cedar Park"; + s.Flush(); + Assert.That(sessions.Statistics.EntityUpdateCount, Is.EqualTo(intialUpdateCount + 1)); + s.Delete(u); + t.Commit(); + s.Close(); + } + } + + [Test] + [Ignore("Ported from Hibernate. Read properties not supported in NH yet.")] + public void TestCustomColumnReadAndWrite() + { + const double HEIGHT_INCHES = 73; + const double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d; + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + User u = new User("steve", "hibernater", new Person( "Steve Ebersole", new DateTime(1999, 12, 31), "Main St")); + u.Person.HeightInches = HEIGHT_INCHES; + s.Persist(u); + s.Flush(); + + // Test value conversion during insert + double heightViaSql = (double)s.CreateSQLQuery("select height_centimeters from t_user where t_user.username='steve'").UniqueResult(); + Assert.That(heightViaSql, Is.EqualTo(HEIGHT_CENTIMETERS).Within(0.01d)); + + // Test projection + double heightViaHql = (double)s.CreateQuery("select u.Person.HeightInches from User u where u.Id = 'steve'").UniqueResult(); + Assert.That(heightViaHql, Is.EqualTo(HEIGHT_INCHES).Within(0.01d)); + + // Test restriction and entity load via criteria + u = (User)s.CreateCriteria(typeof(User)) + .Add(Restrictions.Between("Person.HeightInches", HEIGHT_INCHES - 0.01d, HEIGHT_INCHES + 0.01d)) + .UniqueResult(); + Assert.That(u.Person.HeightInches, Is.EqualTo(HEIGHT_INCHES).Within(0.01d)); + + // Test predicate and entity load via HQL + u = (User)s.CreateQuery("from User u where u.Person.HeightInches between ? and ?") + .SetDouble(0, HEIGHT_INCHES - 0.01d) + .SetDouble(1, HEIGHT_INCHES + 0.01d) + .UniqueResult(); + + Assert.That(u.Person.HeightInches, Is.EqualTo(HEIGHT_INCHES).Within(0.01d)); + + // Test update + u.Person.HeightInches = 1; + s.Flush(); + heightViaSql = (double)s.CreateSQLQuery("select height_centimeters from t_user where t_user.username='steve'").UniqueResult(); + Assert.That(heightViaSql, Is.EqualTo(2.54d).Within(0.01d)); + s.Delete(u); + t.Commit(); + s.Close(); + } + } + + [Test] + [Ignore("Ported from Hibernate - failing in NH")] + public void TestComponentQueries() + { + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + Employee emp = new Employee(); + emp.HireDate = new DateTime(1999, 12, 31); + emp.Person = new Person(); + emp.Person.Name = "steve"; + emp.Person.Dob = new DateTime(1999, 12, 31); + s.Save(emp); + + s.CreateQuery("from Employee e where e.Person = :p and 1=1 and 2=2").SetParameter("p", emp.Person).List(); + s.CreateQuery("from Employee e where :p = e.Person").SetParameter("p", emp.Person).List(); + s.CreateQuery("from Employee e where e.Person = ('steve', current_timestamp)").List(); + + s.Delete( emp ); + t.Commit(); + s.Close(); + } + } + + [Test] + public void TestComponentFormulaQuery() + { + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.CreateQuery("from User u where u.Person.Yob = 1999").List(); + s.CreateCriteria(typeof(User)) + .Add(Property.ForName("Person.Yob").Between(1999, 2002)) + .List(); + + if (Dialect.SupportsRowValueConstructorSyntax) + { + s.CreateQuery("from User u where u.Person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')") + .SetDateTime("dob", new DateTime(1974, 3, 25)).List(); + s.CreateQuery("from User where Person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')") + .SetDateTime("dob", new DateTime(1974, 3, 25)).List(); + } + t.Commit(); + s.Close(); + } + } + + [Test] + public void TestNamedQuery() + { + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.GetNamedQuery("userNameIn") + .SetParameterList( "nameList", new object[] {"1ovthafew", "turin", "xam"} ) + .List(); + t.Commit(); + s.Close(); + } + } + + [Test] + public void TestMergeComponent() + { + Employee emp = null; + IEnumerator<Employee> enumerator = null; + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = new Employee(); + emp.HireDate = new DateTime(1999, 12, 31); + emp.Person = new Person(); + emp.Person.Name = "steve"; + emp.Person.Dob = new DateTime(1999, 12, 31); + s.Persist(emp); + t.Commit(); + s.Close(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Get(typeof(Employee), emp.Id); + t.Commit(); + s.Close(); + } + + Assert.That(emp.OptionalComponent, Is.Null); + + emp.OptionalComponent = new OptionalComponent(); + emp.OptionalComponent.Value1 = "emp-value1"; + emp.OptionalComponent.Value2 = "emp-value2"; + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Merge(emp); + t.Commit(); + s.Close(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Get(typeof(Employee), emp.Id); + t.Commit(); + s.Close(); + } + + Assert.That(emp.OptionalComponent.Value1, Is.EqualTo("emp-value1")); + Assert.That(emp.OptionalComponent.Value2, Is.EqualTo("emp-value2")); + + emp.OptionalComponent.Value1 = null; + emp.OptionalComponent.Value2 = null; + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Merge(emp); + t.Commit(); + s.Close(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Get(typeof(Employee), emp.Id); + NHibernateUtil.Initialize(emp.DirectReports); + t.Commit(); + s.Close(); + } + + Assert.That(emp.OptionalComponent, Is.Null); + + Employee emp1 = new Employee(); + emp1.HireDate = new DateTime(1999, 12, 31); + emp1.Person = new Person(); + emp1.Person.Name = "bozo"; + emp1.Person.Dob = new DateTime(1999, 12, 31); + emp.DirectReports.Add(emp1); + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Merge(emp); + t.Commit(); + s.Close(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Get(typeof(Employee), emp.Id); + NHibernateUtil.Initialize(emp.DirectReports); + t.Commit(); + s.Close(); + } + + Assert.That(emp.DirectReports.Count, Is.EqualTo(1)); + + enumerator = emp.DirectReports.GetEnumerator(); + enumerator.MoveNext(); + emp1 = (Employee)enumerator.Current; + Assert.That(emp1.OptionalComponent, Is.Null); + + emp1.OptionalComponent = new OptionalComponent(); + emp1.OptionalComponent.Value1 = "emp1-value1"; + emp1.OptionalComponent.Value2 = "emp1-value2"; + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Merge(emp); + t.Commit(); + s.Close(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Get(typeof(Employee), emp.Id); + NHibernateUtil.Initialize(emp.DirectReports); + t.Commit(); + s.Close(); + } + + Assert.That(emp.DirectReports.Count, Is.EqualTo(1)); + + enumerator = emp.DirectReports.GetEnumerator(); + enumerator.MoveNext(); + emp1 = (Employee)enumerator.Current; + Assert.That(emp1.OptionalComponent.Value1, Is.EqualTo("emp1-value1")); + Assert.That(emp1.OptionalComponent.Value2, Is.EqualTo("emp1-value2")); + + emp1.OptionalComponent.Value1 = null; + emp1.OptionalComponent.Value2 = null; + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Merge(emp); + t.Commit(); + s.Close(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + emp = (Employee)s.Get(typeof(Employee), emp.Id); + NHibernateUtil.Initialize(emp.DirectReports); + t.Commit(); + s.Close(); + } + + Assert.That(emp.DirectReports.Count, Is.EqualTo(1)); + + enumerator = emp.DirectReports.GetEnumerator(); + enumerator.MoveNext(); + emp1 = (Employee)enumerator.Current; + Assert.That(emp1.OptionalComponent, Is.Null); + + using (ISession s = sessions.OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Delete( emp ); + t.Commit(); + s.Close(); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Component/Basic/Employee.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Component/Basic/Employee.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Component/Basic/Employee.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,18 @@ +using System; +using Iesi.Collections.Generic; + +namespace NHibernate.Test.Component.Basic +{ + public class Employee + { + public virtual long Id { get; set; } + + public virtual Person Person { get; set; } + + public virtual DateTime HireDate { get; set; } + + public virtual OptionalComponent OptionalComponent { get; set; } + + public virtual ISet<Employee> DirectReports { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Component/Basic/OptionalComponent.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Component/Basic/OptionalComponent.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Component/Basic/OptionalComponent.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,8 @@ +namespace NHibernate.Test.Component.Basic +{ + public class OptionalComponent + { + public string Value1 { get; set; } + public string Value2 { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Component/Basic/Person.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Component/Basic/Person.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Component/Basic/Person.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,75 @@ +using System; + +namespace NHibernate.Test.Component.Basic +{ + public class Person + { + private string name; + private DateTime dob; + private string address; + private string currentAddress; + private string previousAddress; + private int yob; + private double heightInches; + + public virtual string Name + { + get { return name; } + set { name = value; } + } + + public virtual DateTime Dob + { + get { return dob; } + set { dob = value; } + } + + public virtual string Address + { + get { return address; } + set { address = value; } + } + + public virtual string CurrentAddress + { + get { return currentAddress; } + set { currentAddress = value; } + } + + public virtual string PreviousAddress + { + get { return previousAddress; } + set { previousAddress = value; } + } + + public virtual int Yob + { + get { return yob; } + set { yob = value; } + } + + public virtual double HeightInches + { + get { return heightInches; } + set { heightInches = value; } + } + + public Person() + { + } + + public Person(String name, DateTime dob, String address) + { + this.name = name; + this.dob = dob; + this.address = address; + this.currentAddress = address; + } + + public virtual void ChangeAddress(String add) + { + this.PreviousAddress = this.Address; + this.Address = add; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,47 @@ +using System; + +namespace NHibernate.Test.Component.Basic +{ + public class User + { + private string userName; + private string password; + private Person person; + private DateTime lastModified; + + public virtual string UserName + { + get { return userName; } + set { userName = value; } + } + + public virtual string Password + { + get { return password; } + set { password = value; } + } + + public virtual Person Person + { + get { return person; } + set { person = value; } + } + + public virtual DateTime LastModified + { + get { return lastModified; } + set { lastModified = value; } + } + + public User() + { + } + + public User(string id, string pw, Person person) + { + this.userName = id; + this.password = pw; + this.person = person; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Component/Basic/User.hbm.xml 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.Component.Basic"> + + <class name="User" table="T_USER"> + <id name="UserName"/> + <timestamp name="LastModified"/> + <property name="Password" not-null="true" optimistic-lock="false"/> + <component name="Person"> + <property name="Name" update="false" not-null="true"/> + <property name="Dob" update="false" not-null="true"/> + <property name="Address"/> + <property name="PreviousAddress" insert="false"/> + <property name="Yob" formula="year(dob)"/> +<!-- + <property name="heightInches"> + <column name="height_centimeters" + not-null="true" + read="height_centimeters / 2.54" + write="? * 2.54"/> + </property> +--> + <property name="CurrentAddress" + column="address" + insert="false" + update="false"/> + </component> + </class> + + <class name="Employee" table="T_EMP"> + <id name="Id" type="long" column="ID"> + <generator class="increment"/> + </id> + <property name="HireDate" type="date" column="HIRE_DATE"/> + <component name="Person"> + <property name="Name" update="false" not-null="true"/> + <property name="Dob" update="false" not-null="true"/> + </component> + <component name="OptionalComponent"> + <property name="Value1" not-null="false"/> + <property name="Value2" not-null="false"/> + </component> + <set name="DirectReports" cascade="all-delete-orphan,merge" lazy="true"> + <key column="PARENT_ID" /> + <one-to-many class="Employee"/> + </set> + </class> + + <query name="userNameIn"><![CDATA[from User where Person.Name in (:nameList) or UserName in (:nameList)]]></query> + +</hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs 2010-07-15 16:20:51 UTC (rev 5007) +++ trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -1,7 +1,7 @@ using System; using System.Collections; +using NHibernate.Criterion; using NHibernate.DomainModel; -using NHibernate.Criterion; using NUnit.Framework; namespace NHibernate.Test.ExpressionTest @@ -174,7 +174,7 @@ Componentizable master = new Componentizable(); if (name != null) { - Component masterComp = new Component(); + NHibernate.DomainModel.Component masterComp = new NHibernate.DomainModel.Component(); masterComp.Name = name; if (subName != null || subName1 != null) { Modified: trunk/nhibernate/src/NHibernate.Test/Legacy/SQLLoaderTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Legacy/SQLLoaderTest.cs 2010-07-15 16:20:51 UTC (rev 5007) +++ trunk/nhibernate/src/NHibernate.Test/Legacy/SQLLoaderTest.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -457,7 +457,7 @@ Componentizable c = new Componentizable(); c.NickName = "Flacky"; - Component component = new Component(); + NHibernate.DomainModel.Component component = new NHibernate.DomainModel.Component(); component.Name = "flakky comp"; SubComponent subComponent = new SubComponent(); subComponent.SubName = "subway"; Modified: trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs 2010-07-15 16:20:51 UTC (rev 5007) +++ trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -71,7 +71,7 @@ Assert.That(compimplements, Is.Not.Null); Assert.That(compimplements.Value, Is.EqualTo("AnotherInterface")); - Property xp = ((Component)prop.Value).GetProperty("X"); + Property xp = ((NHibernate.Mapping.Component)prop.Value).GetProperty("X"); MetaAttribute propximplements = xp.GetMetaAttribute("implements"); Assert.That(propximplements, Is.Not.Null); Assert.That(propximplements.Value, Is.EqualTo("AnotherInterface")); @@ -97,7 +97,7 @@ assertEquals( "wicked level", propertyAttribute.getValues().get(1) );*/ Assert.That(propertyAttribute.Value, Is.EqualTo("monetaryamount level")); - var component = (Component)property.Value; + var component = (NHibernate.Mapping.Component)property.Value; property = component.GetProperty("X"); propertyAttribute = property.GetMetaAttribute("globalmutated"); @@ -126,7 +126,7 @@ Assert.That(propertyAttribute.Value, Is.EqualTo("wicked level")); var bag = (Bag)property.Value; - component = (Component)bag.Element; + component = (NHibernate.Mapping.Component)bag.Element; Assert.That(component.MetaAttributes.Count, Is.EqualTo(4)); Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Fixture.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2061 +{ + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void merge_with_many_to_many_inside_component_that_is_null() + { + // Order with null GroupComponent + Order newOrder = new Order(); + newOrder.GroupComponent = null; + + Order mergedCopy = null; + + using (ISession session = OpenSession()) + using (ITransaction tx = session.BeginTransaction()) + { + mergedCopy = (Order)session.Merge(newOrder); + tx.Commit(); + } + + Assert.That(mergedCopy, Is.Not.Null); + Assert.That(mergedCopy.GroupComponent, Is.Null); + } + + protected override void OnTearDown() + { + using (ISession session = OpenSession()) + using (ITransaction tx = session.BeginTransaction()) + { + session.Delete("from Order"); + session.Delete("from Country"); + tx.Commit(); + } + + base.OnTearDown(); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Mappings.hbm.xml 2010-07-18 15:05:47 UTC (rev 5008) @@ -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.NH2061"> + + <class name="Order" table="Orders"> + <id name="Id" unsaved-value="00000000-0000-0000-0000-000000000000"> + <generator class="guid.comb"/> + </id> + <component name="GroupComponent"> + <bag name="Countries" table="OrderCountries" cascade="none" > + <key column="OrderId" /> + <many-to-many column="CountryCode" class="Country" /> + </bag> + </component> + </class> + + <class name="Country" table="Countries"> + <id name="CountryCode"> + <generator class="assigned"/> + </id> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2061/Model.cs 2010-07-18 15:05:47 UTC (rev 5008) @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2061 +{ + public class Order + { + public virtual Guid Id { get; set; } + public virtual GroupComponent GroupComponent { get; set; } + } + + public class GroupComponent + { + public virtual IList<Country> Countries { get; set; } + } + + public class Country + { + public virtual string CountryCode { get; set; } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-15 16:20:51 UTC (rev 5007) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-18 15:05:47 UTC (rev 5008) @@ -132,6 +132,11 @@ <Compile Include="CollectionTest\IdBagFixture.cs" /> <Compile Include="CollectionTest\NullableValueTypeElementMapFixture.cs" /> <Compile Include="CollectionTest\Parent.cs" /> + <Compile Include="Component\Basic\ComponentTest.cs" /> + <Compile Include="Component\Basic\Employee.cs" /> + <Compile Include="Component\Basic\OptionalComponent.cs" /> + <Compile Include="Component\Basic\Person.cs" /> + <Compile Include="Component\Basic\User.cs" /> <Compile Include="CompositeCollection\BaseClassA.cs" /> <Compile Include="CompositeCollection\BaseClassB.cs" /> <Compile Include="CompositeCollection\ChildClassA.cs" /> @@ -443,6 +448,8 @@ <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Employee.cs" /> <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Fixture.cs" /> <Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Money.cs" /> + <Compile Include="NHSpecificTest\NH2061\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2061\Model.cs" /> <Compile Include="NHSpecificTest\NH2069\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2069\ITest.cs" /> <Compile Include="NHSpecificTest\NH2069\ITest2.cs" /> @@ -1591,6 +1598,8 @@ <Compile Include="VersionTest\Task.cs" /> <Compile Include="VersionTest\Thing.cs" /> <Compile Include="VersionTest\VersionFixture.cs" /> + <None Include="Component\Basic\User.hbm.xml" /> + <None Include="NHSpecificTest\NH2061\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="CompositeCollection\BaseClassA.hbm.xml" /> @@ -1670,6 +1679,9 @@ <Project>{5909BFE7-93CF-4E5F-BE22-6293368AF01D}</Project> <Name>NHibernate</Name> </ProjectReference> + <Folder Include="Component" /> + <Folder Include="Component\Basic" /> + <Folder Include="NHSpecificTest\NH2061" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="NHSpecificTest\NH386\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |