public void WhenReassociateCollectionUsingLockThenTheCommitNotThrows() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (session.BeginTransaction()) { // When I reassociate the collections the Owner is null session.Lock(scenario.Entity, LockMode.None); // If I change something in each collection, there is no problems scenario.Entity.Children.Add(new MyChild { Parent = scenario.Entity }); scenario.Entity.Components.Add(new MyComponent { Something = "something" }); scenario.Entity.Elements.Add("somethingelse"); session.Transaction.Commit(); } using (var session = OpenSession()) using (session.BeginTransaction()) { var fresh = session.Get <MyClass>(scenario.Entity.Id); Assert.That(fresh.Children, Has.Count.EqualTo(2)); Assert.That(fresh.Components, Has.Count.EqualTo(2)); Assert.That(fresh.Elements, Has.Count.EqualTo(2)); session.Transaction.Commit(); } } }
public async Task WhenReassociateCollectionUsingSaveOrUpdateThenTheCommitNotThrowsAsync() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (var tran = session.BeginTransaction()) { scenario.Entity.Children.Add(new MyChild { Parent = scenario.Entity }); scenario.Entity.Components.Add(new MyComponent { Something = "something" }); scenario.Entity.Elements.Add("somethingelse"); // When I reassociate the collections the Owner is null await(session.SaveOrUpdateAsync(scenario.Entity)); await(tran.CommitAsync()); } using (var session = OpenSession()) using (var tran = session.BeginTransaction()) { var fresh = await(session.GetAsync <MyClass>(scenario.Entity.Id)); Assert.That(fresh.Children, Has.Count.EqualTo(2)); Assert.That(fresh.Components, Has.Count.EqualTo(2)); Assert.That(fresh.Elements, Has.Count.EqualTo(2)); await(tran.CommitAsync()); } } }
public void WhenReassociateCollectionUsingLockThenTheCommitNotThrows() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (session.BeginTransaction()) { // When I reassociate the collections the Owner is null session.Lock(scenario.Entity, LockMode.None); // If I change something in each collection, there is no problems scenario.Entity.Children.Add(new MyChild { Parent = scenario.Entity }); scenario.Entity.Components.Add(new MyComponent { Something = "something" }); scenario.Entity.Elements.Add("somethingelse"); session.Transaction.Commit(); } using (var session = OpenSession()) using (session.BeginTransaction()) { var fresh = session.Get<MyClass>(scenario.Entity.Id); fresh.Children.Should().Have.Count.EqualTo(2); fresh.Components.Should().Have.Count.EqualTo(2); fresh.Elements.Should().Have.Count.EqualTo(2); session.Transaction.Commit(); } } }
public void WhenReassociateCollectionUsingSaveOrUpdateThenTheCommitNotThrows() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (session.BeginTransaction()) { scenario.Entity.Children.Add(new MyChild { Parent = scenario.Entity }); scenario.Entity.Components.Add(new MyComponent { Something = "something" }); scenario.Entity.Elements.Add("somethingelse"); // When I reassociate the collections the Owner is null session.SaveOrUpdate(scenario.Entity); session.Transaction.Commit(); } using (var session = OpenSession()) using (session.BeginTransaction()) { var fresh = session.Get <MyClass>(scenario.Entity.Id); fresh.Children.Should().Have.Count.EqualTo(2); fresh.Components.Should().Have.Count.EqualTo(2); fresh.Elements.Should().Have.Count.EqualTo(2); session.Transaction.Commit(); } } }
public void WhenReassociateCollectionUsingMergeThenReassingOwner() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; // When I reassociate the collections the Owner has value using (var session = OpenSession()) using (session.BeginTransaction()) { var merged = (MyClass)session.Merge(scenario.Entity); Assert.That(((IPersistentCollection)merged.Children).Owner, Is.Not.Null); Assert.That(((IPersistentCollection)merged.Components).Owner, Is.Not.Null); Assert.That(((IPersistentCollection)merged.Elements).Owner, Is.Not.Null); session.Transaction.Commit(); } } }
public void WhenReassociateCollectionUsingMergeThenReassingOwner() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; // When I reassociate the collections the Owner has value using (var session = OpenSession()) using (session.BeginTransaction()) { var merged = (MyClass)session.Merge(scenario.Entity); ((IPersistentCollection)merged.Children).Owner.Should().Not.Be.Null(); ((IPersistentCollection)merged.Components).Owner.Should().Not.Be.Null(); ((IPersistentCollection)merged.Elements).Owner.Should().Not.Be.Null(); session.Transaction.Commit(); } } }
public void WhenReassociateCollectionUsingDeleteThenTheCommitNotThrows() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (session.BeginTransaction()) { session.Delete(scenario.Entity); session.Transaction.Commit(); } using (var session = OpenSession()) using (session.BeginTransaction()) { var fresh = session.Get <MyClass>(scenario.Entity.Id); Assert.That(fresh, Is.Null); session.Transaction.Commit(); } } }
public async Task WhenReassociateCollectionUsingDeleteThenTheCommitNotThrowsAsync() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (var tran = session.BeginTransaction()) { await(session.DeleteAsync(scenario.Entity)); await(tran.CommitAsync()); } using (var session = OpenSession()) using (var tran = session.BeginTransaction()) { var fresh = await(session.GetAsync <MyClass>(scenario.Entity.Id)); Assert.That(fresh, Is.Null); await(tran.CommitAsync()); } } }
public void WhenReassociateCollectionUsingDeleteThenTheCommitNotThrows() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (session.BeginTransaction()) { session.Delete(scenario.Entity); session.Transaction.Commit(); } using (var session = OpenSession()) using (session.BeginTransaction()) { var fresh = session.Get<MyClass>(scenario.Entity.Id); fresh.Should().Be.Null(); session.Transaction.Commit(); } } }
public void WhenReassociateCollectionUsingSaveOrUpdateThenTheCommitNotThrows() { using (var scenario = new FullInitializedRetrievedEntity(Sfi)) { ((IPersistentCollection)scenario.Entity.Children).Owner = null; ((IPersistentCollection)scenario.Entity.Components).Owner = null; ((IPersistentCollection)scenario.Entity.Elements).Owner = null; using (var session = OpenSession()) using (session.BeginTransaction()) { scenario.Entity.Children.Add(new MyChild { Parent = scenario.Entity }); scenario.Entity.Components.Add(new MyComponent { Something = "something" }); scenario.Entity.Elements.Add("somethingelse"); // When I reassociate the collections the Owner is null session.SaveOrUpdate(scenario.Entity); session.Transaction.Commit(); } using (var session = OpenSession()) using (session.BeginTransaction()) { var fresh = session.Get<MyClass>(scenario.Entity.Id); Assert.That(fresh.Children, Has.Count.EqualTo(2)); Assert.That(fresh.Components, Has.Count.EqualTo(2)); Assert.That(fresh.Elements, Has.Count.EqualTo(2)); session.Transaction.Commit(); } } }