Skip to content

Commit f8c9212

Browse files
Ignitionchester89
authored andcommitted
Added a test for RelationshipPairingVisitor that fails
1 parent cace0e4 commit f8c9212

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@
395395
<Compile Include="Utils\TypeReferenceEqualityTests.cs" />
396396
<Compile Include="Visitors\ComponentColumnPrefixVisitorSpecs.cs" />
397397
<Compile Include="Visitors\ComponentReferenceResolutionVisitorSpecs.cs" />
398+
<Compile Include="Visitors\RelationshipPairingVisitorSpec.cs" />
399+
<Compile Include="Visitors\RelationshipPairingVisitorSpecSupportClasses.cs" />
398400
<Compile Include="Xml\MappingXmlTestHelper.cs" />
399401
</ItemGroup>
400402
<ItemGroup>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Linq;
2+
using FakeItEasy;
3+
using FluentNHibernate.MappingModel;
4+
using FluentNHibernate.MappingModel.Collections;
5+
using FluentNHibernate.Visitors;
6+
using NUnit.Framework;
7+
8+
namespace FluentNHibernate.Testing.Visitors
9+
{
10+
public abstract class RelationshipPairingVisitorSpec : Specification
11+
{
12+
protected RelationshipPairingVisitor visitor;
13+
protected CollectionMapping collectionMappingToZ;
14+
protected ManyToOneMapping manyToOneZToHolder;
15+
protected ManyToOneMapping manyToOneYToHolder;
16+
}
17+
18+
[TestFixture]
19+
public class when_the_relationship_pairing_visitor_visits_with_multiple_many_to_one_mapping_references : RelationshipPairingVisitorSpec
20+
{
21+
public override void establish_context()
22+
{
23+
manyToOneYToHolder = new ManyToOneMapping();
24+
manyToOneYToHolder.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(Holder)));
25+
manyToOneYToHolder.Set(x => x.Name, Layer.Defaults, "ARankedFirstProperty");
26+
manyToOneYToHolder.ContainingEntityType = typeof(ARankedFirst);
27+
manyToOneYToHolder.Member = new PropertyMember(typeof(ARankedFirst).GetProperty("ARankedFirstProperty"));
28+
29+
manyToOneZToHolder = new ManyToOneMapping();
30+
manyToOneZToHolder.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(Holder)));
31+
manyToOneZToHolder.Set(x => x.Name, Layer.Defaults, "BRankedSecondProperty");
32+
manyToOneZToHolder.ContainingEntityType = typeof(BRankedSecond);
33+
manyToOneZToHolder.Member = new PropertyMember(typeof(BRankedSecond).GetProperty("BRankedSecondProperty"));
34+
35+
var relationship = new OneToManyMapping();
36+
relationship.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(BRankedSecond)));
37+
relationship.ContainingEntityType = typeof(Holder);
38+
39+
collectionMappingToZ = CollectionMapping.Bag();
40+
collectionMappingToZ.Set(x => x.ChildType, Layer.Defaults, typeof(BRankedSecond));
41+
collectionMappingToZ.Set(x => x.Name, Layer.Defaults, "ColectionOfBRankedSeconds");
42+
collectionMappingToZ.Set(x => x.Relationship, Layer.Defaults, relationship);
43+
collectionMappingToZ.ContainingEntityType = typeof(Holder);
44+
45+
visitor = new RelationshipPairingVisitor(A.Fake<PairBiDirectionalManyToManySidesDelegate>());
46+
}
47+
48+
[Test]
49+
public void should_associate_the_collection_mapping_to_the_correct_type()
50+
{
51+
visitor.ProcessCollection(collectionMappingToZ);
52+
visitor.ProcessManyToOne(manyToOneYToHolder);
53+
visitor.ProcessManyToOne(manyToOneZToHolder);
54+
visitor.Visit(Enumerable.Empty<HibernateMapping>());
55+
56+
var otherSide = (ManyToOneMapping)collectionMappingToZ.OtherSide;
57+
otherSide.ContainingEntityType.ShouldEqual(typeof(BRankedSecond));
58+
}
59+
}
60+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
3+
namespace FluentNHibernate.Testing.Visitors
4+
{
5+
public class Holder
6+
{
7+
public virtual ICollection<BRankedSecond> ColectionOfBRankedSeconds { get; set; }
8+
}
9+
10+
public class BRankedSecond
11+
{
12+
public virtual Holder BRankedSecondProperty { get; set; }
13+
}
14+
15+
public class ARankedFirst
16+
{
17+
public virtual Holder ARankedFirstProperty { get; set; }
18+
}
19+
}

0 commit comments

Comments
 (0)