Skip to content

Test case for ComposedId Entity with Lazy Property is not proxified #1440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1439/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace NHibernate.Test.NHSpecificTest.GH1439
{
public class CompositeEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string LazyProperty { get; set; }

public override int GetHashCode()
{
return (Id + "|" + Name).GetHashCode();
}

public override bool Equals(object obj)
{
if (obj == null)
return false;

return obj.GetHashCode() == GetHashCode();
}
}
}
78 changes: 78 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH1439/FixtureByCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using NHibernate.Test.NHSpecificTest.GH0000;

namespace NHibernate.Test.NHSpecificTest.GH1439
{
/// <summary>
/// Fixture using 'by code' mappings
/// </summary>
/// <remarks>
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entity" /> mapping is performed
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
/// if you prefer.
/// </remarks>
public class ByCodeFixture : TestCaseMappingByCode
{
protected override void Configure(Configuration configuration)
{
configuration.SetProperty(Cfg.Environment.ShowSql, "true");
}

protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<CompositeEntity>(rc =>
{
rc.ComposedId(
c =>
{
c.Property(t => t.Id);
c.Property(t => t.Name);
});

rc.Property(x => x.LazyProperty, x => x.Lazy(true));
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

protected override void OnSetUp()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
var e1 = new CompositeEntity { Id = 1, Name = "Bob", LazyProperty = "LazyProperty"};
session.Save(e1);

session.Flush();
transaction.Commit();
}
}

protected override void OnTearDown()
{
using (ISession session = OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete("from System.Object");

session.Flush();
transaction.Commit();
}
}

[Test]
public void YourTestName()
{
using (ISession session = OpenSession())
using (var tran = session.BeginTransaction())
{
var result = (from e in session.Query<CompositeEntity>()
where e.Name == "Bob"
select e).ToList();
session.Flush();
tran.Commit();
Assert.AreEqual(1, result.ToList().Count);
}
}
}
}