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(); } }
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; Assert.That(myComponentWithParent, Is.Not.Null); Assert.That(myComponentWithParent.Parent, Is.SameAs(savedEntity)); Assert.That(myComponentWithParent.Something, Is.EqualTo("A")); Assert.That(savedEntity.Children.Select(c => c.Something), Is.EquivalentTo(new [] {"B", "C"})); Assert.That(savedEntity.Children.All(c => ReferenceEquals(c.Parent, savedEntity)), Is.True); s.Delete(savedEntity); tx.Commit(); } }
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(); } }
public async Task CanCreacteRetrieveDeleteComponentsWithPrivateReferenceSetterToParentAsync() { 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 = await(s.SaveAsync(entity)); await(tx.CommitAsync()); } using (var s = OpenSession()) using (var tx = s.BeginTransaction()) { var savedEntity = await(s.GetAsync <MyEntity>(poid)); var myComponentWithParent = savedEntity.Component; Assert.That(myComponentWithParent, Is.Not.Null); Assert.That(myComponentWithParent.Parent, Is.SameAs(savedEntity)); Assert.That(myComponentWithParent.Something, Is.EqualTo("A")); Assert.That(savedEntity.Children.Select(c => c.Something), Is.EquivalentTo(new [] { "B", "C" })); Assert.That(savedEntity.Children.All(c => ReferenceEquals(c.Parent, savedEntity)), Is.True); await(s.DeleteAsync(savedEntity)); await(tx.CommitAsync()); } }