From 8f46b1a4d962805c98a66f29856dcc855a734140 Mon Sep 17 00:00:00 2001 From: Alexander Zaytsev Date: Mon, 24 Nov 2014 23:39:09 +1300 Subject: [PATCH] NH-3491 - Add test case --- .../NHSpecificTest/NH3491/FixtureByCode.cs | 57 +++++++++++++++++++ src/NHibernate.Test/NHibernate.Test.csproj | 1 + 2 files changed, 58 insertions(+) create mode 100644 src/NHibernate.Test/NHSpecificTest/NH3491/FixtureByCode.cs diff --git a/src/NHibernate.Test/NHSpecificTest/NH3491/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/NH3491/FixtureByCode.cs new file mode 100644 index 00000000000..246e4340388 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3491/FixtureByCode.cs @@ -0,0 +1,57 @@ +using System; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +using System.Linq; + +namespace NHibernate.Test.NHSpecificTest.NH3491 +{ + [TestFixture] + public class FixtureByCode + { + class SomeComponent + { + public virtual string PropertyOne { get; set; } + public virtual string PropertyTwo { get; set; } + public virtual string PropertyThree { get; set; } + } + + class ClassWithComponents + { + public virtual Guid Id { get; set; } + + public virtual SomeComponent Component1 { get; set; } + + public virtual SomeComponent Component2 { get; set; } + } + + [Test(Description = "NH-3491"), KnownBug("NH-3491")] + public void ShouldProperlyMapComponentWhenMappingOnlyPartOfItInSomePlaces() + { + var mapper = new ModelMapper(); + mapper.Class(cm => + { + cm.Component(x => x.Component1, c => + { + c.Property(x => x.PropertyOne, p => p.Column("OnePropertyOne")); + }); + + cm.Component(x => x.Component2, c => + { + c.Property(x => x.PropertyOne, p => p.Column("TwoPropertyOne")); + c.Property(x => x.PropertyTwo, p => p.Column("TwoPropertyTwo")); + }); + }); + + //Compile, and get the component property in which we mapped only one inner property + var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); + + var component1PropertyMapping = (HbmComponent)mappings.RootClasses[0].Properties.Single(x => x.Name == "Component1"); + + //There should be only one inner property in the mapping of this component + // Note: take a look at how CURRENTLY the test fails with 1 expected vs 2, instead of vs 3. + // This means that the "PropertyThree" property of the component that was never mapped, is not taken into account (which is fine). + Assert.That(component1PropertyMapping.Items.Length, Is.EqualTo(1)); + } + } +} \ No newline at end of file diff --git a/src/NHibernate.Test/NHibernate.Test.csproj b/src/NHibernate.Test/NHibernate.Test.csproj index 7264b73aab0..fa15fa5b7c9 100644 --- a/src/NHibernate.Test/NHibernate.Test.csproj +++ b/src/NHibernate.Test/NHibernate.Test.csproj @@ -731,6 +731,7 @@ +