Exemplo n.º 1
0
		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();
			}
		}
Exemplo n.º 2
0
		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();
			}
		}
Exemplo n.º 3
0
		public MyComponentWithParent(MyEntity parent)
		{
			this.parent = parent;
		}
Exemplo n.º 4
0
 public MyComponentWithParent(MyEntity parent)
 {
     this.parent = parent;
 }