public virtual void TestClassWithSingleRelationship()
        {
            IClassDef def =
                _loader.LoadClass(
                    @"
				<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"">
					<property  name=""TestProp"" />
                    <primaryKey>
                        <prop name=""TestProp""/>
                    </primaryKey>
					<relationship 
						name=""TestRelationship"" 
						type=""single"" 
						relatedClass=""TestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO.Loaders""
					>
						<relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />
					</relationship>
				</class>
			"            );
            IRelationshipDefCol relDefCol = def.RelationshipDefCol;

            Assert.AreEqual(1, relDefCol.Count, "There should be one relationship def from the given xml definition");
            Assert.IsNotNull(relDefCol["TestRelationship"],
                             "'TestRelationship' should be the name of the relationship created");
        }
Exemple #2
0
        private static MatchList FindRelationshipsSafe <TRelationshipDef>(IRelationshipDefCol relationshipDefCol,
                                                                          MatchesConditionDelegate <TRelationshipDef> matchesConditionDelegate, List <IRelationshipDefCol> alreadyChecked)
            where TRelationshipDef : RelationshipDef
        {
            var listOfPaths = new MatchList();

            if (matchesConditionDelegate == null)
            {
                return(listOfPaths);
            }
            if (relationshipDefCol == null)
            {
                return(listOfPaths);
            }
            if (alreadyChecked.Contains(relationshipDefCol))
            {
                return(listOfPaths);
            }
            alreadyChecked.Add(relationshipDefCol);
            foreach (var relationshipDef in relationshipDefCol)
            {
                var relationshipName      = relationshipDef.RelationshipName;
                var castedRelationshipDef = relationshipDef as TRelationshipDef;
                if (castedRelationshipDef == null)
                {
                    continue;
                }
                var matchesCondition = matchesConditionDelegate(castedRelationshipDef);
                if (matchesCondition)
                {
                    listOfPaths.Add(relationshipName, null);
                }
                else
                {
                    var classDef = (ClassDef)relationshipDef.RelatedObjectClassDef;
                    if (classDef != null)
                    {
                        var results = FindRelationshipsSafe(classDef.RelationshipDefCol, matchesConditionDelegate, alreadyChecked);
                        if (results.Count > 0)
                        {
                            listOfPaths.Add(relationshipName, results);
                        }
                    }
                }
            }
            return(listOfPaths);
        }
        public void TestLoadClassDefs_InheritedClassWithNoPrimaryKey_WithRelationship()
        {
            XmlClassDefsLoader loader       = CreateXmlClassDefsLoader();
            ClassDefCol        classDefList =
                loader.LoadClassDefs(
                    @"
					<classes>
						<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClassID"" type=""Guid"" />
                            <primaryKey>
                                <prop name=""TestClassID""/>
                            </primaryKey>
						</class>
						<class name=""TestClass2"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClass2ID"" type=""Guid"" />
                            <primaryKey>
                                <prop name=""TestClass2ID""/>
                            </primaryKey>
						</class>
						<class name=""TestClassInherited"" assembly=""Habanero.Test.BO.Loaders"" >							
                            <superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" />
					        <property name=""RelatedTestClassID"" type=""Guid"" />    
                            <relationship name=""TestRelationship"" type=""single"" 
						        relatedClass=""TestClass"" relatedAssembly=""Habanero.Test.BO.Loaders"">
						        <relatedProperty property=""RelatedTestClassID"" relatedProperty=""TestClassID"" />
					        </relationship>                
						</class>
					</classes>
			"            );

            Assert.AreEqual(3, classDefList.Count);
            Assert.IsTrue(classDefList.Contains("Habanero.Test.BO.Loaders", "TestClass"), "Class 'TestClass' should have been loaded.");
            Assert.IsTrue(classDefList.Contains("Habanero.Test.BO.Loaders", "TestClass2"), "Class 'TestClass2' should have been loaded.");
            Assert.IsTrue(classDefList.Contains("Habanero.Test.BO.Loaders", "TestClassInherited"), "Class 'TestClassInherited' should have been loaded.");
            IClassDef classDefTestClass = classDefList["Habanero.Test.BO.Loaders", "TestClass"];
            IClassDef classDefInherited = classDefList["Habanero.Test.BO.Loaders", "TestClassInherited"];

            Assert.IsNotNull(classDefTestClass);
            Assert.IsNotNull(classDefInherited.SuperClassDef);
            Assert.IsNull(classDefInherited.PrimaryKeyDef);
            IRelationshipDefCol relDefCol = classDefInherited.RelationshipDefCol;

            Assert.AreEqual(1, relDefCol.Count, "There should be one relationship def from the given xml definition");
            Assert.IsNotNull(relDefCol["TestRelationship"], "'TestRelationship' should be the name of the relationship created");
        }
        public virtual void TestClassWithSuperClassWithRelationshipAndNoPK()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Remove(typeof(TestClass));
            ClassDef.ClassDefs.Remove(typeof(TestRelatedClass));
            ClassDef.ClassDefs.Add(
                new XmlClassDefsLoader(
                    @"
					<classes>
						<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClassID"" type=""Guid"" />
                            <primaryKey>
                                <prop name=""TestClassID""/>
                            </primaryKey>
						</class>
					</classes>"                    ,
                    new DtdLoader(), GetDefClassFactory()).LoadClassDefs());
            IClassDef parentDef = ClassDef.ClassDefs["Habanero.Test.BO.Loaders", "TestClass"];
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            IClassDef def = _loader.LoadClass(
                @"
				<class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"">
					<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" />
					<property name=""TestProp"" type=""Guid"" />    
					<property name=""RelatedTestClassID"" type=""Guid"" />    
                    <relationship name=""TestRelationship"" type=""single"" 
						relatedClass=""TestClass"" relatedAssembly=""Habanero.Test.BO.Loaders"">
						<relatedProperty property=""RelatedTestClassID"" relatedProperty=""TestClassID"" />
					</relationship>                
				</class>
			"            );

            //---------------Test Result -----------------------
            Assert.IsNotNull(def.SuperClassDef);
            IClassDef superClassDef = def.SuperClassDef.SuperClassClassDef;

            Assert.AreSame(parentDef, superClassDef);
            IRelationshipDefCol relDefCol = def.RelationshipDefCol;

            Assert.AreEqual(1, relDefCol.Count, "There should be one relationship def from the given xml definition");
            Assert.IsNotNull(relDefCol["TestRelationship"], "'TestRelationship' should be the name of the relationship created");
        }
Exemple #5
0
        private void AddChildIfNeeded(string childName, RelationshipCol relationshipCol)
        {
            IRelationshipDefCol relationshipDefCol = ClassDef.RelationshipDefCol;

            if (relationshipDefCol.Contains(childName))
            {
                IRelationshipDef relationshipDef = relationshipDefCol[childName];
#pragma warning disable 168
                IClassDef classDef = relationshipDef.RelatedObjectClassDef;
#pragma warning restore 168
                IMultipleRelationship relationship = (IMultipleRelationship)relationshipDef.CreateRelationship(this, this._boPropCol);
                //_mock.DynamicMock<IMultipleRelationship>();
                //(this, relationshipDef, this._boPropCol);
                //BusinessObjectCollection<BusinessObject> businessObjectCollection = new BusinessObjectCollection<BusinessObject>(classDef);
                //SetupResult.For(relationship.BusinessObjectCollection)
                //    .Return(businessObjectCollection);
                //SetupResult.For(relationship.RelationshipName)
                //    .Return(businessObjectCollection);

                //SetupResult.For(relationship.GetRelatedBusinessObjectCol<BusinessObject>())
                //    .Return(businessObjectCollection);
                relationshipCol.Add(relationship);
            }
        }
Exemple #6
0
 /// <summary>
 /// Returns a list of all relationships that match the Delegate relationship.
 /// </summary>
 /// <typeparam name="TRelationshipDef"></typeparam>
 /// <param name="relationshipDefCol"></param>
 /// <param name="matchesConditionDelegate"></param>
 /// <returns></returns>
 public static MatchList FindRelationships <TRelationshipDef>(IRelationshipDefCol relationshipDefCol,
                                                              MatchesConditionDelegate <TRelationshipDef> matchesConditionDelegate)
     where TRelationshipDef : RelationshipDef
 {
     return(FindRelationshipsSafe(relationshipDefCol, matchesConditionDelegate, new List <IRelationshipDefCol>()));
 }
Exemple #7
0
 /// <summary>
 /// Returns a list of all relationships that are marked as prevent deletion.
 /// </summary>
 /// <param name="relationshipDefCol"></param>
 /// <returns></returns>
 public static MatchList FindPreventDeleteRelationships(IRelationshipDefCol relationshipDefCol)
 {
     return(FindRelationships <MultipleRelationshipDef>(relationshipDefCol, PreventDeleteRelationshipCondition));
 }
        /// <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);
            }
        }
Exemple #9
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);
            }
        }
		///<summary>
		///</summary>
		///<param name="assemblyName"></param>
		///<param name="className"></param>
		///<param name="displayName"></param>
		///<param name="primaryKeyDef"></param>
		///<param name="propDefCol"></param>
		///<param name="keyDefCol"></param>
		///<param name="relationshipDefCol"></param>
		///<param name="uiDefCol"></param>
		///<returns></returns>
		public IClassDef CreateClassDef(string assemblyName, string className, string displayName, IPrimaryKeyDef primaryKeyDef,
									   IPropDefCol propDefCol, KeyDefCol keyDefCol, IRelationshipDefCol relationshipDefCol,
									   UIDefCol uiDefCol)
		{
			return new ClassDef(assemblyName, className, displayName, primaryKeyDef, propDefCol, keyDefCol, relationshipDefCol, uiDefCol);
		}
Exemple #11
0
 ///<summary>
 ///</summary>
 ///<param name="assemblyName"></param>
 ///<param name="className"></param>
 ///<param name="displayName"></param>
 ///<param name="primaryKeyDef"></param>
 ///<param name="propDefCol"></param>
 ///<param name="keyDefCol"></param>
 ///<param name="relationshipDefCol"></param>
 ///<param name="uiDefCol"></param>
 ///<returns></returns>
 public IClassDef CreateClassDef(string assemblyName, string className, string displayName, IPrimaryKeyDef primaryKeyDef,
                                 IPropDefCol propDefCol, KeyDefCol keyDefCol, IRelationshipDefCol relationshipDefCol,
                                 UIDefCol uiDefCol)
 {
     return(new ClassDef(assemblyName, className, displayName, primaryKeyDef, propDefCol, keyDefCol, relationshipDefCol, uiDefCol));
 }