Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions RakeFile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ namespace :source do
info.product_name = 'FluentNHibernate'
info.description = commit_hash[0..(commit_hash.length - 3)]
info.copyright = "Copyright 2008-#{Time.new.year} James Gregory and contributors (Paul Batum, Hudson Akridge et al). All rights reserved."
info.namespaces = ['System.Security']
info.namespaces = ['System.Security','System.Runtime.CompilerServices']
info.custom_attributes :InternalsVisibleTo => "FluentNHibernate.Testing"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why InternalsVisibleTo?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see - because you used PropertyMember


puts "The new version is #{info.version}"
end
Expand Down Expand Up @@ -257,4 +258,4 @@ task :sln do
Thread.new do
system "devenv #{SLN}"
end
end
end
2 changes: 2 additions & 0 deletions src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@
<Compile Include="Utils\TypeReferenceEqualityTests.cs" />
<Compile Include="Visitors\ComponentColumnPrefixVisitorSpecs.cs" />
<Compile Include="Visitors\ComponentReferenceResolutionVisitorSpecs.cs" />
<Compile Include="Visitors\RelationshipPairingVisitorSpec.cs" />
<Compile Include="Visitors\RelationshipPairingVisitorSpecSupportClasses.cs" />
<Compile Include="Xml\MappingXmlTestHelper.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Linq;
using FakeItEasy;
using FluentNHibernate.MappingModel;
using FluentNHibernate.MappingModel.Collections;
using FluentNHibernate.Visitors;
using NUnit.Framework;

namespace FluentNHibernate.Testing.Visitors
{
public abstract class RelationshipPairingVisitorSpec : Specification
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe abstract class is not necessary here. If we had several test cases that can share the functionality - sure

{
protected RelationshipPairingVisitor visitor;
protected CollectionMapping collectionMappingToZ;
protected ManyToOneMapping manyToOneZToHolder;
protected ManyToOneMapping manyToOneYToHolder;
}

[TestFixture]
public class when_the_relationship_pairing_visitor_visits_with_multiple_many_to_one_mapping_references : RelationshipPairingVisitorSpec
{
public override void establish_context()
{
manyToOneYToHolder = new ManyToOneMapping();
manyToOneYToHolder.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(Holder)));
manyToOneYToHolder.Set(x => x.Name, Layer.Defaults, "ARankedFirstProperty");
manyToOneYToHolder.ContainingEntityType = typeof(ARankedFirst);
manyToOneYToHolder.Member = new PropertyMember(typeof(ARankedFirst).GetProperty("ARankedFirstProperty"));

manyToOneZToHolder = new ManyToOneMapping();
manyToOneZToHolder.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(Holder)));
manyToOneZToHolder.Set(x => x.Name, Layer.Defaults, "BRankedSecondProperty");
manyToOneZToHolder.ContainingEntityType = typeof(BRankedSecond);
manyToOneZToHolder.Member = new PropertyMember(typeof(BRankedSecond).GetProperty("BRankedSecondProperty"));

var relationship = new OneToManyMapping();
relationship.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(BRankedSecond)));
relationship.ContainingEntityType = typeof(Holder);

collectionMappingToZ = CollectionMapping.Bag();
collectionMappingToZ.Set(x => x.ChildType, Layer.Defaults, typeof(BRankedSecond));
collectionMappingToZ.Set(x => x.Name, Layer.Defaults, "ColectionOfBRankedSeconds");
collectionMappingToZ.Set(x => x.Relationship, Layer.Defaults, relationship);
collectionMappingToZ.ContainingEntityType = typeof(Holder);

visitor = new RelationshipPairingVisitor(A.Fake<PairBiDirectionalManyToManySidesDelegate>());
}

[Test]
public void should_associate_the_collection_mapping_to_the_correct_type()
{
visitor.ProcessCollection(collectionMappingToZ);
visitor.ProcessManyToOne(manyToOneYToHolder);
visitor.ProcessManyToOne(manyToOneZToHolder);
visitor.Visit(Enumerable.Empty<HibernateMapping>());

var otherSide = (ManyToOneMapping)collectionMappingToZ.OtherSide;
otherSide.ContainingEntityType.ShouldEqual(typeof(BRankedSecond));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;

namespace FluentNHibernate.Testing.Visitors
{
public class Holder
{
public virtual ICollection<BRankedSecond> ColectionOfBRankedSeconds { get; set; }
}

public class BRankedSecond
{
public virtual Holder BRankedSecondProperty { get; set; }
}

public class ARankedFirst
{
public virtual Holder ARankedFirstProperty { get; set; }
}
}
7 changes: 6 additions & 1 deletion src/FluentNHibernate/Visitors/RelationshipPairingVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ static void PairOneToManys(IEnumerable<CollectionMapping> collections, IEnumerab
foreach (var collection in orderedCollections)
{
var type = collection.ContainingEntityType;
var reference = orderedRefs.FirstOrDefault(x => x.OtherSide == null && x.Class.GetUnderlyingSystemType() == type);
var childType = collection.ChildType;
var reference = orderedRefs
.FirstOrDefault(x =>
x.OtherSide == null &&
x.Class.GetUnderlyingSystemType() == type &&
x.ContainingEntityType == childType);

if (reference == null) continue;

Expand Down