Skip to content

Commit d9ce463

Browse files
committed
Merge pull request #381 from hazzik/NH-3491
NH-3491 - Add test case
2 parents 6e15d71 + 8f46b1a commit d9ce463

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NUnit.Framework;
5+
using System.Linq;
6+
7+
namespace NHibernate.Test.NHSpecificTest.NH3491
8+
{
9+
[TestFixture]
10+
public class FixtureByCode
11+
{
12+
class SomeComponent
13+
{
14+
public virtual string PropertyOne { get; set; }
15+
public virtual string PropertyTwo { get; set; }
16+
public virtual string PropertyThree { get; set; }
17+
}
18+
19+
class ClassWithComponents
20+
{
21+
public virtual Guid Id { get; set; }
22+
23+
public virtual SomeComponent Component1 { get; set; }
24+
25+
public virtual SomeComponent Component2 { get; set; }
26+
}
27+
28+
[Test(Description = "NH-3491"), KnownBug("NH-3491")]
29+
public void ShouldProperlyMapComponentWhenMappingOnlyPartOfItInSomePlaces()
30+
{
31+
var mapper = new ModelMapper();
32+
mapper.Class<ClassWithComponents>(cm =>
33+
{
34+
cm.Component(x => x.Component1, c =>
35+
{
36+
c.Property(x => x.PropertyOne, p => p.Column("OnePropertyOne"));
37+
});
38+
39+
cm.Component(x => x.Component2, c =>
40+
{
41+
c.Property(x => x.PropertyOne, p => p.Column("TwoPropertyOne"));
42+
c.Property(x => x.PropertyTwo, p => p.Column("TwoPropertyTwo"));
43+
});
44+
});
45+
46+
//Compile, and get the component property in which we mapped only one inner property
47+
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
48+
49+
var component1PropertyMapping = (HbmComponent)mappings.RootClasses[0].Properties.Single(x => x.Name == "Component1");
50+
51+
//There should be only one inner property in the mapping of this component
52+
// Note: take a look at how CURRENTLY the test fails with 1 expected vs 2, instead of vs 3.
53+
// This means that the "PropertyThree" property of the component that was never mapped, is not taken into account (which is fine).
54+
Assert.That(component1PropertyMapping.Items.Length, Is.EqualTo(1));
55+
}
56+
}
57+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@
731731
<Compile Include="NHSpecificTest\NH3487\Fixture.cs" />
732732
<Compile Include="NHSpecificTest\NH3567\DomainClass.cs" />
733733
<Compile Include="NHSpecificTest\NH3567\NH3567Tests.cs" />
734+
<Compile Include="NHSpecificTest\NH3491\FixtureByCode.cs" />
734735
<Compile Include="NHSpecificTest\NH3570\BiFixture.cs" />
735736
<Compile Include="NHSpecificTest\NH3570\Model.cs" />
736737
<Compile Include="NHSpecificTest\NH3570\UniFixture.cs" />

0 commit comments

Comments
 (0)