Skip to content

Instantly share code, notes, and snippets.

@fabiomaulo
Created June 28, 2010 11:47
Show Gist options
  • Save fabiomaulo/455739 to your computer and use it in GitHub Desktop.
Save fabiomaulo/455739 to your computer and use it in GitHub Desktop.
namespace NHibernate.Test.NHSpecificTest.NH2230
{
[TestFixture]
public class Fixture : BugTestCase
{
[Test]
public void CanCreacteRetrieveDeleteComponentsWithPrivateReferenceSetterToParent()
{
var entity = new MyEntity();
var component = new MyComponentWithParent(entity){Something = "A"};
entity.Component = component;
entity.Children = new List<MyComponentWithParent>
{
new MyComponentWithParent(entity){Something = "B"},
new MyComponentWithParent(entity){Something = "C"}
};
object poid;
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
poid = s.Save(entity);
tx.Commit();
}
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
var savedEntity = s.Get<MyEntity>(poid);
var myComponentWithParent = savedEntity.Component;
myComponentWithParent.Should().Not.Be.Null();
myComponentWithParent.Parent.Should().Be.SameInstanceAs(savedEntity);
myComponentWithParent.Something.Should().Be("A");
savedEntity.Children.Select(c => c.Something).Should().Have.SameValuesAs("B", "C");
savedEntity.Children.Select(child=> child.Parent).All(parent => parent.Satisfy(myEntity => ReferenceEquals(myEntity, savedEntity)));
s.Delete(savedEntity);
tx.Commit();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment