示例#1
0
        public void ConcreteInheritance_RelationsWorkCorrectly()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var objectWithRelations = ConcreteInheritanceObjectWithRelations.NewObject();
                objectWithRelations.ScalarProperty = ConcreteInheritanceFirstDerivedClass.NewObject();
                objectWithRelations.VectorProperty.Add(ConcreteInheritanceFirstDerivedClass.NewObject());
                objectWithRelations.VectorProperty.Add(ConcreteInheritanceSecondDerivedClass.NewObject());

                ClientTransaction.Current.Commit();
            }

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var query = new Query(new QueryDefinition("QueryOverUnionView", TestDomainStorageProviderDefinition,
                                                          "SELECT * FROM [ConcreteInheritanceObjectWithRelationsView]", QueryType.Collection), new QueryParameterCollection());
                var actualObjectWithRelations = ClientTransaction.Current.QueryManager.GetCollection <ConcreteInheritanceObjectWithRelations> (query)
                                                .AsEnumerable().Single();

                Assert.IsInstanceOf(typeof(ConcreteInheritanceFirstDerivedClass), actualObjectWithRelations.ScalarProperty);
                Assert.That(actualObjectWithRelations.VectorProperty.Count, Is.EqualTo(2));
                Assert.That(actualObjectWithRelations.VectorProperty.OfType <ConcreteInheritanceFirstDerivedClass> ().Single(), Is.Not.Null);
                Assert.That(actualObjectWithRelations.VectorProperty.OfType <ConcreteInheritanceSecondDerivedClass> ().Single(), Is.Not.Null);
            }
        }
示例#2
0
        public void AccessingMixinProperties_OfDerivedClass()
        {
            SetDatabaseModifyable();

            var singleInheritanceFirstDerivedClass1 = SingleInheritanceFirstDerivedClass.NewObject();

            ((ISingleInheritancePersistentMixin)singleInheritanceFirstDerivedClass1).PersistentProperty = "value 1";
            var singleInheritanceFirstDerivedClass2 = SingleInheritanceFirstDerivedClass.NewObject();

            ((ISingleInheritancePersistentMixin)singleInheritanceFirstDerivedClass2).PersistentProperty = "value 2";

            var singleInheritanceSecondDerivedClass1 = SingleInheritanceSecondDerivedClass.NewObject();

            ((ISingleInheritancePersistentMixin)singleInheritanceSecondDerivedClass1).PersistentProperty = "value 1";
            var singleInheritanceSecondDerivedClass2 = SingleInheritanceSecondDerivedClass.NewObject();

            ((ISingleInheritancePersistentMixin)singleInheritanceSecondDerivedClass2).PersistentProperty = "value 2";

            ClientTransaction.Current.Commit();

            var queryWithSingleTableInheritance =
                from obj in QueryFactory.CreateLinqQuery <SingleInheritanceBaseClass> ()
                where
                (obj is SingleInheritanceFirstDerivedClass || obj is SingleInheritanceSecondDerivedClass) &&
                (((ISingleInheritancePersistentMixin)obj).PersistentProperty == "value 1")
                select obj;

            CheckQueryResult(queryWithSingleTableInheritance, singleInheritanceFirstDerivedClass1.ID, singleInheritanceSecondDerivedClass1.ID);

            var concreteInheritanceFirstDerivedClass1 = ConcreteInheritanceFirstDerivedClass.NewObject();

            ((IConcreteInheritancePersistentMixin)concreteInheritanceFirstDerivedClass1).PersistentProperty = "value 1";
            var concreteInheritanceFirstDerivedClass2 = ConcreteInheritanceFirstDerivedClass.NewObject();

            ((IConcreteInheritancePersistentMixin)concreteInheritanceFirstDerivedClass2).PersistentProperty = "value 2";

            var concreteInheritanceSecondDerivedClass1 = ConcreteInheritanceSecondDerivedClass.NewObject();

            ((IConcreteInheritancePersistentMixin)concreteInheritanceSecondDerivedClass1).PersistentProperty = "value 1";
            var concreteInheritanceSecondDerivedClass2 = ConcreteInheritanceSecondDerivedClass.NewObject();

            ((IConcreteInheritancePersistentMixin)concreteInheritanceSecondDerivedClass2).PersistentProperty = "value 2";

            ClientTransaction.Current.Commit();

            var queryWithConcreteTableInheritance =
                from obj in QueryFactory.CreateLinqQuery <ConcreteInheritanceBaseClass> ()
                where
                (obj is ConcreteInheritanceFirstDerivedClass || obj is ConcreteInheritanceSecondDerivedClass) &&
                (((IConcreteInheritancePersistentMixin)obj).PersistentProperty == "value 1")
                select obj;

            CheckQueryResult(queryWithConcreteTableInheritance, concreteInheritanceFirstDerivedClass1.ID, concreteInheritanceSecondDerivedClass1.ID);
        }
示例#3
0
        public void ConcreteInheritance_GetObject()
        {
            ObjectID firstDerivedClassObjectID;
            ObjectID secondDerivedClassObjectID;

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var firstDerivedClass = ConcreteInheritanceFirstDerivedClass.NewObject();
                firstDerivedClassObjectID = firstDerivedClass.ID;
                var secondDerivedClass = ConcreteInheritanceSecondDerivedClass.NewObject();
                secondDerivedClassObjectID = secondDerivedClass.ID;

                ClientTransaction.Current.Commit();
            }

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                Assert.IsInstanceOf(typeof(ConcreteInheritanceFirstDerivedClass), LifetimeService.GetObject(ClientTransaction.Current, firstDerivedClassObjectID, false));
                Assert.IsInstanceOf(typeof(ConcreteInheritanceSecondDerivedClass), LifetimeService.GetObject(ClientTransaction.Current, secondDerivedClassObjectID, false));
            }
        }
示例#4
0
        public void ConcreteInheritance_QueryOverUnionView()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var firstDerivedClass  = ConcreteInheritanceFirstDerivedClass.NewObject();
                var secondDerivedClass = ConcreteInheritanceSecondDerivedClass.NewObject();

                firstDerivedClass.BaseProperty         = "BasePropertyValue 1";
                firstDerivedClass.FirstDerivedProperty = "FirstDerivedPropertyValue 1";
                ((IConcreteInheritancePersistentMixin)firstDerivedClass).PersistentProperty = "PersistentPropertyValue 1";

                secondDerivedClass.BaseProperty          = "BasePropertyValue 2";
                secondDerivedClass.SecondDerivedProperty = "SecondDerivedPropertyValue 2";
                ((IConcreteInheritancePersistentMixin)secondDerivedClass).PersistentProperty = "PersistentPropertyValue 2";

                ClientTransaction.Current.Commit();
            }

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var query = new Query(new QueryDefinition("QueryOverUnionView", TestDomainStorageProviderDefinition,
                                                          "SELECT * FROM [ConcreteInheritanceBaseClassView]", QueryType.Collection), new QueryParameterCollection());
                var actualObjects = ClientTransaction.Current.QueryManager.GetCollection <ConcreteInheritanceBaseClass> (query);

                Assert.That(actualObjects.Count, Is.EqualTo(2));
                var actualFirstDerivedClass  = actualObjects.AsEnumerable().OfType <ConcreteInheritanceFirstDerivedClass> ().Single();
                var actualSecondDerivedClass = actualObjects.AsEnumerable().OfType <ConcreteInheritanceSecondDerivedClass> ().Single();

                Assert.That(actualFirstDerivedClass.BaseProperty, Is.EqualTo("BasePropertyValue 1"));
                Assert.That(actualFirstDerivedClass.FirstDerivedProperty, Is.EqualTo("FirstDerivedPropertyValue 1"));
                Assert.That(((IConcreteInheritancePersistentMixin)actualFirstDerivedClass).PersistentProperty, Is.EqualTo("PersistentPropertyValue 1"));

                Assert.That(actualSecondDerivedClass.BaseProperty, Is.EqualTo("BasePropertyValue 2"));
                Assert.That(actualSecondDerivedClass.SecondDerivedProperty, Is.EqualTo("SecondDerivedPropertyValue 2"));
                Assert.That(((IConcreteInheritancePersistentMixin)actualSecondDerivedClass).PersistentProperty, Is.EqualTo("PersistentPropertyValue 2"));
            }
        }