예제 #1
0
파일: Fixture.cs 프로젝트: jrauber/GH1429
        public void ComplexNest()
        {
            Component comp1 = GetInitializedComponent();
            var       nest  = new Nest {
                Name = "NAME", Components = new List <Component> {
                    comp1
                }
            };
            var deep1 = new DeepComponent {
                Prop1 = "PROP1", Prop2 = "PROP2", Prop3 = "PROP3", Prop4 = "PROP4"
            };
            Component innerComp = GetInitializedComponent();

            deep1.Component = innerComp;
            Component innerComp2 = GetInitializedComponent();
            var       deep2      = new DeepComponent
            {
                Prop1 = "PROP1", Prop2 = "PROP2", Prop3 = "PROP3", Prop4 = "PROP4", Component = innerComp2
            };

            nest.ComplexComponents = new List <DeepComponent> {
                deep1, deep2
            };

            object nestId;

            using (ISession session = OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(nest);
                    transaction.Commit();
                    nestId = nest.Id;
                }
            }

            using (ISession session = OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var loadedNest = session.Load <Nest>(nestId);
                    transaction.Commit();

                    Assert.AreEqual(2, loadedNest.ComplexComponents.Count);
                    Assert.IsNotNull(((DeepComponent)loadedNest.ComplexComponents[0]).Component.SubComponent.Nested.SubName1);
                    Assert.IsNull(((DeepComponent)loadedNest.ComplexComponents[0]).Component.SubComponent.SubName1);
                }
            }

            using (ISession s = OpenSession())
            {
                using (ITransaction t = s.BeginTransaction())
                {
                    s.Delete("from Nest");
                    t.Commit();
                }
            }
        }
예제 #2
0
		public void ComplexNest()
		{
			Component comp1 = GetInitializedComponent();
			var nest = new Nest {Name = "NAME", Components = new ArrayList {comp1}};
			var deep1 = new DeepComponent {Prop1 = "PROP1", Prop2 = "PROP2", Prop3 = "PROP3", Prop4 = "PROP4"};
			Component innerComp = GetInitializedComponent();
			deep1.Component = innerComp;
			Component innerComp2 = GetInitializedComponent();
			var deep2 = new DeepComponent
			            	{Prop1 = "PROP1", Prop2 = "PROP2", Prop3 = "PROP3", Prop4 = "PROP4", Component = innerComp2};

			nest.ComplexComponents = new ArrayList {deep1, deep2};

			object nestId;
			using (ISession session = OpenSession())
			{
				using (ITransaction transaction = session.BeginTransaction())
				{
					session.Save(nest);
					transaction.Commit();
					nestId = nest.Id;
				}
			}

			using (ISession session = OpenSession())
			{
				using (ITransaction transaction = session.BeginTransaction())
				{
					var loadedNest = session.Load<Nest>(nestId);
					transaction.Commit();

					Assert.AreEqual(2, loadedNest.ComplexComponents.Count);
					Assert.IsNotNull(((DeepComponent) loadedNest.ComplexComponents[0]).Component.SubComponent.Nested.SubName1);
					Assert.IsNull(((DeepComponent) loadedNest.ComplexComponents[0]).Component.SubComponent.SubName1);
				}
			}

			using (ISession s = OpenSession())
			{
				using (ITransaction t = s.BeginTransaction())
				{
					s.Delete("from Nest");
					t.Commit();
				}
			}
		}