-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contributed unit test for NH-3142, with cleanups.
- Loading branch information
Showing
4 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3142 | ||
{ | ||
[TestFixture] | ||
public class ChildrenTest : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
base.OnSetUp(); | ||
|
||
using (var session = OpenSession()) | ||
{ | ||
for (int h = 1; h < 3; h++) | ||
{ | ||
for (int i = 1; i < 4; i++) | ||
{ | ||
var parent = new DomainParent { Id1 = h, Id2 = i }; | ||
session.Save(parent); | ||
|
||
var parentId = new DomainParentWithComponentId { Id = { Id1 = h, Id2 = i } }; | ||
session.Save(parentId); | ||
|
||
for (int j = 1; j < 4; j++) | ||
{ | ||
var child = new DomainChild { ParentId1 = h, ParentId2 = i }; | ||
session.Save(child); | ||
|
||
var childId = new DomainChildWCId { ParentId1 = h, ParentId2 = i }; | ||
session.Save(childId); | ||
} | ||
} | ||
} | ||
|
||
session.Flush(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
base.OnTearDown(); | ||
using (var session = OpenSession()) | ||
{ | ||
session.Delete("from DomainChild"); | ||
session.Delete("from DomainChildWCId"); | ||
session.Delete("from System.Object"); | ||
session.Flush(); | ||
} | ||
} | ||
|
||
|
||
[Test] | ||
public void ChildrenCollectionOfAllParentsShouldContainsThreeElements() | ||
{ | ||
using (var session = OpenSession()) | ||
{ | ||
var entities = session.CreateQuery("from DomainParent").List<DomainParent>(); | ||
|
||
foreach (var parent in entities) | ||
Assert.AreEqual(3, parent.Children.Count); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ChildrenCollectionOfAllParentsWithComponentIdShouldContainsThreeElements() | ||
{ | ||
using (var session = OpenSession()) | ||
{ | ||
var entities = session.CreateQuery("from DomainParentWithComponentId").List<DomainParentWithComponentId>(); | ||
|
||
foreach (var parent in entities) | ||
Assert.AreEqual(3, parent.Children.Count); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
|
||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3142 | ||
{ | ||
public class DomainParent | ||
{ | ||
public virtual int Id1 { get; set; } | ||
public virtual int Id2 { get; set; } | ||
|
||
public virtual ICollection<DomainChild> Children { get; set; } | ||
|
||
public override bool Equals(object other) | ||
{ | ||
var otherParent = other as DomainParent; | ||
if (otherParent == null) | ||
return false; | ||
return Id1 == otherParent.Id1 && | ||
Id2 == otherParent.Id2; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Id1.GetHashCode() ^ Id2.GetHashCode(); | ||
} | ||
} | ||
|
||
public class DomainChild | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual int ParentId1 { get; set; } | ||
public virtual int ParentId2 { get; set; } | ||
} | ||
|
||
[Serializable] | ||
public class DomainParentIdentifier | ||
{ | ||
public virtual int Id1 { get; set; } | ||
public virtual int Id2 { get; set; } | ||
|
||
public override bool Equals(object other) | ||
{ | ||
var otherParent = other as DomainParentIdentifier; | ||
if (otherParent == null) | ||
return false; | ||
return Id1 == otherParent.Id1 && | ||
Id2 == otherParent.Id2; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Id1.GetHashCode() ^ Id2.GetHashCode(); | ||
} | ||
} | ||
|
||
public class DomainParentWithComponentId | ||
{ | ||
public DomainParentWithComponentId() | ||
{ | ||
Id = new DomainParentIdentifier(); | ||
} | ||
|
||
public virtual DomainParentIdentifier Id { get; protected set; } | ||
|
||
public virtual ICollection<DomainChildWCId> Children { get; set; } | ||
} | ||
|
||
public class DomainChildWCId | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual int ParentId1 { get; set; } | ||
public virtual int ParentId2 { get; set; } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/NHibernate.Test/NHSpecificTest/NH3142/Mappings.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.NH3142" default-access="property" | ||
default-lazy="true"> | ||
<class name="DomainParent"> | ||
<composite-id> | ||
<key-property name="Id1"/> | ||
<key-property name="Id2"/> | ||
</composite-id> | ||
<set name="Children" inverse="true" batch-size="4"> | ||
<key> | ||
<column name="ParentId1" /> | ||
<column name="ParentId2" /> | ||
</key> | ||
<one-to-many class="DomainChild" /> | ||
</set> | ||
</class> | ||
|
||
<class name="DomainChild"> | ||
<id name="Id"> | ||
<generator class="identity" /> | ||
</id> | ||
<property name="ParentId1"/> | ||
<property name="ParentId2"/> | ||
</class> | ||
|
||
<class name="DomainParentWithComponentId"> | ||
<composite-id name="Id" class="DomainParentIdentifier"> | ||
<key-property name="Id1"/> | ||
<key-property name="Id2"/> | ||
</composite-id> | ||
<set name="Children" inverse="true" batch-size="4"> | ||
<key> | ||
<column name="ParentId1" /> | ||
<column name="ParentId2" /> | ||
</key> | ||
<one-to-many class="DomainChildWCId" /> | ||
</set> | ||
</class> | ||
|
||
<class name="DomainChildWCId"> | ||
<id name="Id"> | ||
<generator class="identity" /> | ||
</id> | ||
<property name="ParentId1"/> | ||
<property name="ParentId2"/> | ||
</class> | ||
</hibernate-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters