コード例 #1
0
ファイル: Fixture.cs プロジェクト: owerkop/nhibernate-core
		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();
			}
		}
コード例 #2
0
ファイル: Fixture.cs プロジェクト: marchlud/nhibernate-core
		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();
			}
		}
コード例 #3
0
ファイル: Fixture.cs プロジェクト: zmp2000/nhibernate-core
        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();
                }
        }
コード例 #4
0
ファイル: Fixture.cs プロジェクト: jrauber/GH1429
        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());
                }
        }