Ejemplo n.º 1
0
        public void TestSingleTableInheritanceDiscriminatorWithSpaces()
        {
            ISuperClassDef def = itsLoader.LoadSuperClassDesc(
                @"<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" orMapping=""SingleTableInheritance"" discriminator=""prop name"" />");

            Assert.AreEqual("prop name", def.Discriminator);
        }
Ejemplo n.º 2
0
        public void Test_Map_When2LayersOfInheritance_ShouldCreateDiscriminatorOnSuperSuperTypeOnly()
        {
            //---------------Set up test pack-------------------
            Type superSuperClass = typeof(FakeBOSuperClass);
            Type superClass      = typeof(FakeBOSubClass);
            Type subClass        = typeof(FakeBOSubSubClass);

            //---------------Assert Precondition----------------
            Assert.AreSame(superClass, subClass.BaseType);
            Assert.AreSame(superSuperClass, superClass.BaseType);
            Assert.IsTrue(superSuperClass.ToTypeWrapper().IsBusinessObject);
            //---------------Execute Test ----------------------
            var inheritanceDef = subClass.MapInheritance();
            //---------------Test Result -----------------------
            var superClassClassDef = inheritanceDef.SuperClassClassDef;

            Assert.AreEqual("FakeBOSuperClassType", inheritanceDef.Discriminator);
            ISuperClassDef superClassInheritanceDef = superClassClassDef.SuperClassDef;

            Assert.AreEqual("FakeBOSuperClassType", superClassInheritanceDef.Discriminator);
            var superSuperClassClassDef = superClassInheritanceDef.SuperClassClassDef;

            superClassClassDef.PropDefcol.ShouldHaveCount(0,
                                                          "No Properties Should be created for SuperClass since ID and Discriminator will be on SuperSuperClass");
            superSuperClassClassDef.PropDefcol.ShouldHaveCount(2, "Discriminator and ID Prop should be created");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new SuperClassDef object using the data that
        /// has been loaded for the object
        /// </summary>
        /// <returns>Returns a SuperClassDef object</returns>
        protected override object Create()
        {
            ISuperClassDef superClassDef = _defClassFactory.CreateSuperClassDef(_assemblyName, _className, _orMapping, _id, _discriminator);

            superClassDef.TypeParameter = _typeParameter;
            return(superClassDef);
        }
Ejemplo n.º 4
0
        ///<summary>
        /// Returns the <see cref="ClassDef"/> for the super class defined in the specified <see cref="SuperClassDef"/>.
        ///</summary>
        ///<param name="superClassDef">The <see cref="SuperClassDef"/> for which to find its Super class <see cref="ClassDef"/>.</param>
        ///<param name="classDefCol">The <see cref="ClassDefCol"/> to use to search for the super class <see cref="ClassDef"/>.</param>
        ///<returns>Returns the <see cref="ClassDef"/> for the super class defined in the specified <see cref="SuperClassDef"/>.</returns>
        ///<exception cref="InvalidXmlDefinitionException"></exception>
        public static ClassDef GetSuperClassClassDef(ISuperClassDef superClassDef, ClassDefCol classDefCol)
        {
            ClassDef superClassClassDef = null;
            string   assemblyName       = superClassDef.AssemblyName;
            string   className          = superClassDef.ClassName;

            if (assemblyName != null && className != null)
            {
                if (!string.IsNullOrEmpty(superClassDef.TypeParameter))
                {
                    className = className + "_" + superClassDef.TypeParameter;
                }
                if (classDefCol.Contains(assemblyName, className))
                {
                    superClassClassDef = (ClassDef)classDefCol[assemblyName, className];
                }
                if (superClassClassDef == null)
                {
                    throw new InvalidXmlDefinitionException(String.Format(
                                                                "The class definition for the super class with the type " +
                                                                "'{0}' was not found. Check that the class definition " +
                                                                "exists or that spelling and capitalisation are correct. " +
                                                                "There are {1} class definitions currently loaded."
                                                                , assemblyName + "." + className, classDefCol.Count));
                }
            }
            return(superClassClassDef);
        }
Ejemplo n.º 5
0
        public void TestClassTableInheritanceWithDiscriminatorIsValid()
        {
            ISuperClassDef def =
                itsLoader.LoadSuperClassDesc(
                    @"<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" discriminator=""abc"" />");

            Assert.AreEqual(ORMapping.ClassTableInheritance, def.ORMapping);
            Assert.AreEqual("abc", def.Discriminator);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Load the super-class data
        /// </summary>
        private void LoadSuperClassDesc(string xmlDef)
        {
            if (xmlDef == null)
            {
                return;
            }
            XmlSuperClassLoader superClassLoader = new XmlSuperClassLoader(DtdLoader, _defClassFactory);

            _superClassDef = superClassLoader.LoadSuperClassDesc(xmlDef);
        }
Ejemplo n.º 7
0
        public void TestConcreteTableInheritance()
        {
            ISuperClassDef def =
                itsLoader.LoadSuperClassDesc(
                    @"<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" orMapping=""ConcreteTableInheritance"" />");

            Assert.AreEqual(ORMapping.ConcreteTableInheritance, def.ORMapping);
            Assert.IsNull(def.ID);
            Assert.IsNull(def.Discriminator);
        }
Ejemplo n.º 8
0
        public void TestClassTableInheritanceWithID()
        {
            ISuperClassDef def =
                itsLoader.LoadSuperClassDesc(
                    @"<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" id=""propname"" />");

            Assert.AreEqual(ORMapping.ClassTableInheritance, def.ORMapping);
            Assert.AreEqual("propname", def.ID);
            Assert.IsNull(def.Discriminator);
        }
Ejemplo n.º 9
0
        public void TestSimpleProperty()
        {
            ISuperClassDef def =
                itsLoader.LoadSuperClassDesc(
                    @"<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" />");

            Assert.AreEqual(ORMapping.ClassTableInheritance, def.ORMapping);
            Assert.AreEqual("Habanero.Test.BO.Loaders", def.AssemblyName);
            Assert.AreEqual("TestClass", def.ClassName);
            Assert.IsNull(def.Discriminator);
        }
Ejemplo n.º 10
0
        public void TestSuperClassDefProperty()
        {
            //---------------Set up test pack-------------------
            IClassDef shapeClassDef  = Shape.GetClassDef();
            IClassDef circleClassDef = Circle.GetClassDef();
            //---------------Execute Test ----------------------
            ISuperClassDef superClassDef = circleClassDef.SuperClassDef;

            //---------------Test Result -----------------------
            Assert.AreSame(shapeClassDef, superClassDef.SuperClassClassDef,
                           "SuperClassDef.ClassDef property on ClassDef should return the SuperClass's ClassDef");
        }
Ejemplo n.º 11
0
        public void Test_TypeParameter()
        {
            //---------------Set up test pack-------------------
            const string superClassXml = @"<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" typeParameter=""TypeParam1"" />";

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            ISuperClassDef def = itsLoader.LoadSuperClassDesc(superClassXml);

            //---------------Test Result -----------------------
            Assert.AreEqual("TypeParam1", def.TypeParameter);
            //---------------Tear Down -------------------------
        }
Ejemplo n.º 12
0
        public void Test_Inheritance_SuperClassDef_Exists()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            ISuperClassDef superClassDef = ClassDef.Get <Car>().SuperClassDef;

            //---------------Test Result -----------------------
            Assert.IsNotNull(superClassDef);
        }
Ejemplo n.º 13
0
        private static void CreateDiscriminatorProp(ISuperClassDef inheritanceClassDef)
        {
            IClassDef superClassClassDef = inheritanceClassDef.SuperClassClassDef;
            IPropDef  foundPropDef       = superClassClassDef.GetPropDef(inheritanceClassDef.Discriminator, false);

            if (foundPropDef != null)
            {
                return;
            }

            IPropDef propDef = new PropDef(inheritanceClassDef.Discriminator, typeof(String),
                                           PropReadWriteRule.WriteNew, null);

            superClassClassDef.PropDefcol.Add(propDef);
        }
Ejemplo n.º 14
0
        public void Test_Inheritance_SuperClassDef_PropertiesCorrect()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            ISuperClassDef superClassDef = ClassDef.Get <Car>().SuperClassDef;

            //---------------Test Result -----------------------
            Assert.AreEqual("TestProject.BO", superClassDef.AssemblyName);
            Assert.AreEqual("Vehicle", superClassDef.ClassName);
            Assert.AreEqual("VehicleType", superClassDef.Discriminator);
        }
Ejemplo n.º 15
0
        public void Test_Inheritance_SuperClassDef_RelatedClassIsCorrect()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------

            IClassDef      classDef      = ClassDef.Get <Car>();
            ISuperClassDef superClassDef = classDef.SuperClassDef;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IClassDef relatedClassDef = ClassDef.ClassDefs[superClassDef.AssemblyName, superClassDef.ClassName];

            //---------------Test Result -----------------------
            Assert.IsNotNull(relatedClassDef);
            IPropDef propDef = relatedClassDef.PropDefcol[superClassDef.Discriminator];

            Assert.IsNotNull(propDef, "The discriminator must be a property on the parent class");
        }
Ejemplo n.º 16
0
        private static void AddDiscriminatorFields(ISelectQuery selectQuery, IClassDef classDef, ref Criteria criteria)
        {
            ClassDefCol classDefsToSearch = ((ClassDef)classDef).AllChildren;

            classDefsToSearch.Add((ClassDef)classDef);
            List <Criteria> discriminatorCriteriaList = new List <Criteria>();
            string          discriminator             = null;

            foreach (ClassDef thisClassDef in classDefsToSearch)
            {
                if (!thisClassDef.IsUsingSingleTableInheritance())
                {
                    continue;
                }
                ISuperClassDef superClassDef = thisClassDef.SuperClassDef;
                discriminator = superClassDef.Discriminator;
                if (String.IsNullOrEmpty(discriminator))
                {
                    continue;
                }
                if (!selectQuery.Fields.ContainsKey(discriminator))
                {
                    selectQuery.Fields.Add(discriminator,
                                           new QueryField(discriminator, discriminator, new Source(((ClassDef)classDef).GetBaseClassOfSingleTableHierarchy().ClassNameExcludingTypeParameter, classDef.GetTableName())));
                }
                discriminatorCriteriaList.Add(new Criteria(discriminator, Criteria.ComparisonOp.Equals, thisClassDef.ClassName));
            }

            if (discriminatorCriteriaList.Count > 0)
            {
                if (!((ClassDef)classDef).IsUsingSingleTableInheritance())
                {
                    criteria = new Criteria(discriminator, Criteria.ComparisonOp.Is, "null");
                }
                foreach (Criteria discCriteria in discriminatorCriteriaList)
                {
                    if (criteria == null)
                    {
                        criteria = discCriteria; continue;
                    }
                    criteria = new Criteria(criteria, Criteria.LogicalOp.Or, discCriteria);
                }
            }
        }
Ejemplo n.º 17
0
        private static void createSuperClassDMXml(XmlElement classDMElement, IClassDef DMClass)
        {
            ISuperClassDef superClassDef = DMClass.SuperClassDef;

            if (superClassDef == null)
            {
                return;
            }
            //if (!inheritanceRelationship.HasSuperClass) return;
            IClassDef superClassClassDef = superClassDef.SuperClassClassDef;

            if (superClassClassDef == null)
            {
                return;
            }
            XmlElement SuperClassDMElement = XmlUtilities.createXmlElement(classDMElement, "superClass");

            XmlUtilities.setXmlAttribute(SuperClassDMElement, "class", superClassClassDef.ClassName);
            XmlUtilities.setXmlAttribute(SuperClassDMElement, "assembly", superClassClassDef.AssemblyName);
            XmlUtilities.setXmlAttribute(SuperClassDMElement, "orMapping", superClassDef.ORMapping,
                                         ORMapping.ClassTableInheritance);
            switch (superClassDef.ORMapping)
            {
            case ORMapping.ClassTableInheritance:
                XmlUtilities.setXmlAttribute(SuperClassDMElement, "discriminator", superClassDef.Discriminator, "");
                XmlUtilities.setXmlAttribute(SuperClassDMElement, "id", superClassDef.ID, "");
                break;

            case ORMapping.SingleTableInheritance:
                XmlUtilities.setXmlAttribute(SuperClassDMElement, "discriminator", superClassDef.Discriminator, "");
                break;

            case ORMapping.ConcreteTableInheritance:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private static void CreateDiscriminatorProp(ISuperClassDef inheritanceClassDef)
        {
            IClassDef superClassClassDef = inheritanceClassDef.SuperClassClassDef;
            IPropDef foundPropDef = superClassClassDef.GetPropDef(inheritanceClassDef.Discriminator, false);
            if (foundPropDef != null) return;

            IPropDef propDef = new PropDef(inheritanceClassDef.Discriminator, typeof (String),
                                           PropReadWriteRule.WriteNew, null);
            superClassClassDef.PropDefcol.Add(propDef);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Loads all relevant data from the reader
        /// </summary>
        protected override void LoadFromReader()
        {
            try
            {
                _superClassDef      = null;
                _relationshipDefCol = _defClassFactory.CreateRelationshipDefCol();
                _keyDefCol          = _defClassFactory.CreateKeyDefCol();
                _uiDefCol           = _defClassFactory.CreateUIDefCol();
                _propDefCol         = _defClassFactory.CreatePropDefCol();
                _reader.Read();
                LoadClassInfo();
                LoadTableName();
                LoadDisplayName();
                LoadTypeParameter();
                LoadClassID();
                LoadModuleName();
                _reader.Read();



                List <string> keyDefXmls          = new List <string>();
                List <string> propDefXmls         = new List <string>();
                List <string> relationshipDefXmls = new List <string>();
                List <string> uiDefXmls           = new List <string>();
                string        superclassDescXML   = null;
                string        primaryKeDefXML     = null;
                while (_reader.Name != "class")
                {
                    switch (_reader.Name)
                    {
                    case "superClass":
                        superclassDescXML = _reader.ReadOuterXml();
                        break;

                    case "property":
                        propDefXmls.Add(_reader.ReadOuterXml());
                        break;

                    case "key":
                        keyDefXmls.Add(_reader.ReadOuterXml());
                        break;

                    case "primaryKey":
                        primaryKeDefXML = _reader.ReadOuterXml();
                        break;

                    case "relationship":
                        relationshipDefXmls.Add(_reader.ReadOuterXml());
                        break;

                    case "ui":
                        uiDefXmls.Add(_reader.ReadOuterXml());
                        break;

                    default:
                        throw new InvalidXmlDefinitionException("The element '" +
                                                                _reader.Name + "' is not a recognised class " +
                                                                "definition element.  Ensure that you have the correct " +
                                                                "spelling and capitalisation, or see the documentation " +
                                                                "for available options.");
                    }
                }

                LoadSuperClassDesc(superclassDescXML);
                LoadPropDefs(propDefXmls);
                LoadKeyDefs(keyDefXmls);
                LoadPrimaryKeyDef(primaryKeDefXML);
                _classDef = CreateClassDef();
                LoadRelationshipDefs(relationshipDefXmls);
                _classDef.RelationshipDefCol = _relationshipDefCol;
                LoadUIDefs(uiDefXmls);
                _classDef.UIDefCol = _uiDefCol;
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException(string.Format("The Class Definition for {0} - {1} could not be loaded ", _className, _displayName), ex);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Loads all relevant data from the reader
        /// </summary>
        protected override void LoadFromReader()
        {
            try
            {
                _superClassDef = null;
                _relationshipDefCol = _defClassFactory.CreateRelationshipDefCol();
                _keyDefCol = _defClassFactory.CreateKeyDefCol();
                _uiDefCol = _defClassFactory.CreateUIDefCol();
                _propDefCol = _defClassFactory.CreatePropDefCol();
                _reader.Read();
                LoadClassInfo();
                LoadTableName();
                LoadDisplayName();
                LoadTypeParameter();
                LoadClassID();
                LoadModuleName();
                _reader.Read();

                
                
                List<string> keyDefXmls = new List<string>();
                List<string> propDefXmls = new List<string>();
                List<string> relationshipDefXmls = new List<string>();
                List<string> uiDefXmls = new List<string>();
                string superclassDescXML = null;
                string primaryKeDefXML = null;
                while (_reader.Name != "class")
                {
                    switch (_reader.Name)
                    {
                        case "superClass":
                            superclassDescXML = _reader.ReadOuterXml();
                            break;
                        case "property":
                            propDefXmls.Add(_reader.ReadOuterXml());
                            break;
                        case "key":
                            keyDefXmls.Add(_reader.ReadOuterXml());
                            break;
                        case "primaryKey":
                            primaryKeDefXML = _reader.ReadOuterXml();
                            break;
                        case "relationship":
                            relationshipDefXmls.Add(_reader.ReadOuterXml());
                            break;
                        case "ui":
                            uiDefXmls.Add(_reader.ReadOuterXml());
                            break;
                        default:
                            throw new InvalidXmlDefinitionException("The element '" +
                                    _reader.Name + "' is not a recognised class " +
                                    "definition element.  Ensure that you have the correct " +
                                    "spelling and capitalisation, or see the documentation " +
                                    "for available options.");
                    }
                }

                LoadSuperClassDesc(superclassDescXML);
                LoadPropDefs(propDefXmls);
                LoadKeyDefs(keyDefXmls);
                LoadPrimaryKeyDef(primaryKeDefXML);
                _classDef = CreateClassDef();
                LoadRelationshipDefs(relationshipDefXmls);
                _classDef.RelationshipDefCol = _relationshipDefCol;
                LoadUIDefs(uiDefXmls);
                _classDef.UIDefCol = _uiDefCol;
            }
            catch (Exception ex)
            {
                throw new InvalidXmlDefinitionException(string.Format("The Class Definition for {0} - {1} could not be loaded ", _className ,_displayName ), ex);
            }
        }
Ejemplo n.º 21
0
 ///<summary>
 /// Returns the <see cref="ClassDef"/> for the super class defined in the specified <see cref="SuperClassDef"/>.
 ///</summary>
 ///<param name="superClassDef">The <see cref="SuperClassDef"/> for which to find its Super class <see cref="ClassDef"/>.</param>
 ///<param name="classDefCol">The <see cref="ClassDefCol"/> to use to search for the super class <see cref="ClassDef"/>.</param>
 ///<returns>Returns the <see cref="ClassDef"/> for the super class defined in the specified <see cref="SuperClassDef"/>.</returns>
 ///<exception cref="InvalidXmlDefinitionException"></exception>
 public static ClassDef GetSuperClassClassDef(ISuperClassDef superClassDef, ClassDefCol classDefCol)
 {
     ClassDef superClassClassDef = null;
     string assemblyName = superClassDef.AssemblyName;
     string className = superClassDef.ClassName;
     if (assemblyName != null && className != null)
     {
         if (!string.IsNullOrEmpty(superClassDef.TypeParameter)) className = className + "_" + superClassDef.TypeParameter;
         if (classDefCol.Contains(assemblyName, className))
         {
             superClassClassDef = (ClassDef) classDefCol[assemblyName, className];
         }
         if (superClassClassDef == null)
         {
             throw new InvalidXmlDefinitionException(String.Format(
                                                         "The class definition for the super class with the type " +
                                                         "'{0}' was not found. Check that the class definition " +
                                                         "exists or that spelling and capitalisation are correct. " +
                                                         "There are {1} class definitions currently loaded."
                                                         , assemblyName + "." + className, classDefCol.Count));
         }
     }
     return superClassClassDef;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Load the super-class data
 /// </summary>
 private void LoadSuperClassDesc(string xmlDef)
 {
     if (xmlDef == null) return;
     XmlSuperClassLoader superClassLoader = new XmlSuperClassLoader(DtdLoader, _defClassFactory);
     _superClassDef = superClassLoader.LoadSuperClassDesc(xmlDef);
 }