Exemplo n.º 1
0
        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());
                    }
            }
        }
Exemplo n.º 3
0
		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();
				}
			}
		}
Exemplo n.º 4
0
        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();
                    }
            }
        }
Exemplo n.º 5
0
        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();
                    }
            }
        }
Exemplo n.º 6
0
		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();
				}
			}
		}
Exemplo n.º 7
0
        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());
                    }
            }
        }
Exemplo n.º 9
0
		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();
				}
			}
		}
Exemplo n.º 10
0
		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();
				}
			}
		}