From: <dar...@us...> - 2009-02-08 22:57:04
|
Revision: 4077 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4077&view=rev Author: darioquintana Date: 2009-02-08 22:56:59 +0000 (Sun, 08 Feb 2009) Log Message: ----------- You cannot ask for this: Assert.AreEqual(10m, ((InvoiceItem)invLoaded.Items[0]).Quantity); Because for example in PostgreSQL the items are loaded in different order. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Invoice.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Fixture.cs 2009-02-08 22:33:44 UTC (rev 4076) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Fixture.cs 2009-02-08 22:56:59 UTC (rev 4077) @@ -86,11 +86,15 @@ [Test] public void IdBagWithCompositeElementThatContainsAManyToOne_Update() { + InvoiceItem itemToUpdate = null; IdBagWithCompositeElementThatContainsAManyToOne_Setup(); using (ISession s = OpenSession()) { Invoice invToUpdate = s.Get<Invoice>(inv.Id); - ((InvoiceItem)invToUpdate.Items[0]).Quantity = 10m; // update information of an element + + itemToUpdate = ((InvoiceItem)invToUpdate.Items[0]); // update information of an element + itemToUpdate.Quantity = 10m; + invToUpdate.Items.Add(new InvoiceItem(product3, 1)); // update the idbag collection s.Flush(); s.Clear(); @@ -98,8 +102,9 @@ using (ISession s = OpenSession()) { Invoice invLoaded = s.Get<Invoice>(inv.Id); - Assert.AreEqual(10m, ((InvoiceItem)invLoaded.Items[0]).Quantity); Assert.AreEqual(3, invLoaded.Items.Count, "The collection should have a new item"); + Assert.IsTrue(invLoaded.Items.Contains(itemToUpdate)); + s.Clear(); } IdBagWithCompositeElementThatContainsAManyToOne_CleanUp(); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Invoice.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Invoice.cs 2009-02-08 22:33:44 UTC (rev 4076) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH364/Invoice.cs 2009-02-08 22:56:59 UTC (rev 4077) @@ -53,6 +53,29 @@ get { return _Quantity; } set { _Quantity = value; } } + + public bool Equals(InvoiceItem other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other._Quantity == _Quantity && Equals(other._Product, _Product); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof(InvoiceItem)) return false; + return Equals((InvoiceItem)obj); + } + + public override int GetHashCode() + { + unchecked + { + return (_Quantity.GetHashCode() * 397) ^ (_Product != null ? _Product.GetHashCode() : 0); + } + } } [Serializable] @@ -77,5 +100,25 @@ get { return _Name; } set { _Name = value; } } + + public bool Equals(Product other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other._Id == _Id; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Product)) return false; + return Equals((Product) obj); + } + + public override int GetHashCode() + { + return _Id; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |