Exemplo n.º 1
0
        /// <summary>
        /// Loads the relationship data
        /// </summary>
        private void LoadRelationshipDefs(IEnumerable <string> xmlDefs)
        {
/*            var loadedRelationships = from relDefXml in xmlDefs
 *                                    let relationshipLoader = new XmlRelationshipLoader(DtdLoader, _defClassFactory, _className)
 *                                    select relationshipLoader.LoadRelationship(relDefXml, _propDefCol)
 *                                    into loadedRelationship where loadedRelationship != null select loadedRelationship;
 *          foreach (var loadedRelationship in loadedRelationships)
 *          {
 *              loadedRelationship.OwningClassDef = this._classDef;
 *              _relationshipDefCol.Add(loadedRelationship);
 *          }*/

            foreach (string relDefXml in xmlDefs)
            {
                XmlRelationshipLoader relationshipLoader = new XmlRelationshipLoader(DtdLoader, _defClassFactory, _className);
                var loadedRelationship = relationshipLoader.LoadRelationship(relDefXml, _propDefCol);
                if (loadedRelationship == null)
                {
                    continue;
                }
                loadedRelationship.OwningClassDef = this._classDef;
                _relationshipDefCol.Add(loadedRelationship);
            }
        }
 protected void Initialise() {
     _loader = new XmlRelationshipLoader(new DtdLoader(), GetDefClassFactory(), "TestClass");
     _propDefs = GetDefClassFactory().CreatePropDefCol();
     _propDefs.Add(GetDefClassFactory().CreatePropDef("TestProp", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false));
 }
        public void TestRelationshipType_Invalid() 
        {
            //---------------Set up test pack-------------------
            string className = TestUtil.GetRandomString();
            XmlRelationshipLoader loader = new XmlRelationshipLoader(new DtdLoader(), GetDefClassFactory(), className);
            const string singleRelationshipStringComposition = @"
					<relationship 
						name=""TestRelationship"" 
						type=""single"" 
                        relationshipType=""Bob""
                        relatedClass=""Habanero.Test.BO.Loaders.TestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO""
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />
					</relationship>";
            //---------------Execute Test ----------------------
            try
            {
                loader.LoadRelationship(singleRelationshipStringComposition, _propDefs);
                Assert.Fail("An error should have been raised as there is no relationship type of Bob");
            //---------------Test Result -----------------------
            } catch (InvalidXmlDefinitionException ex)
            {
                StringAssert.Contains(string.Format("'TestRelationship' on class '{0}'", className), ex.Message);
                StringAssert.Contains("invalid value ('Bob')", ex.Message);
            } 
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads the relationship data
        /// </summary>
        private void LoadRelationshipDefs(IEnumerable<string> xmlDefs)
        {
/*            var loadedRelationships = from relDefXml in xmlDefs
                                      let relationshipLoader = new XmlRelationshipLoader(DtdLoader, _defClassFactory, _className)
                                      select relationshipLoader.LoadRelationship(relDefXml, _propDefCol)
                                      into loadedRelationship where loadedRelationship != null select loadedRelationship;
            foreach (var loadedRelationship in loadedRelationships)
            {
                loadedRelationship.OwningClassDef = this._classDef;
                _relationshipDefCol.Add(loadedRelationship);
            }*/

            foreach (string relDefXml in xmlDefs)
            {
                XmlRelationshipLoader relationshipLoader = new XmlRelationshipLoader(DtdLoader, _defClassFactory, _className);
                var loadedRelationship = relationshipLoader.LoadRelationship(relDefXml, _propDefCol);
                if(loadedRelationship == null) continue;
                loadedRelationship.OwningClassDef = this._classDef;
                _relationshipDefCol.Add(loadedRelationship);
            }
        }
Exemplo n.º 5
0
        public void Test_LoadInheritedRelationship_UsingInheritedRelatedProps()
        {
            DefClassFactory defClassFactory = new DefClassFactory();
            XmlRelationshipLoader loader = new XmlRelationshipLoader(new DtdLoader(), defClassFactory, "TestClass");
            IPropDefCol propDefs = defClassFactory.CreatePropDefCol();
            propDefs.Add(defClassFactory.CreatePropDef("TestProp", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false));

            RelationshipDef relDef =
                (RelationshipDef) loader.LoadRelationship(
                                      @"<relationship 
						name=""TestRelationship"" 
						type=""single"" 
						relatedClass=""Habanero.Test.BO.Loaders.NonExistantTestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO"" 
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />

					</relationship>",
                                      propDefs);
            Type classType = relDef.RelatedObjectClassType;
        }
Exemplo n.º 6
0
        public void TestWithUnknownRelatedType()
        {
            //---------------Set up test pack-------------------
            DefClassFactory defClassFactory = new DefClassFactory();
            XmlRelationshipLoader loader = new XmlRelationshipLoader(new DtdLoader(), defClassFactory, "TestClass");
            IPropDefCol propDefs = defClassFactory.CreatePropDefCol();
            propDefs.Add(defClassFactory.CreatePropDef("TestProp", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false));

            RelationshipDef relDef =
                (RelationshipDef) loader.LoadRelationship(
                                      @"<relationship 
						name=""TestRelationship"" 
						type=""single"" 
						relatedClass=""Habanero.Test.BO.Loaders.NonExistantTestRelatedClass"" 
						relatedAssembly=""Habanero.Test.BO"" 
                    >
						    <relatedProperty property=""TestProp"" relatedProperty=""TestRelatedProp"" />

					</relationship>",
                                      propDefs);

            //---------------Execute Test ----------------------
            try
            {

                Type classType = relDef.RelatedObjectClassType;

                Assert.Fail("Expected to throw an UnknownTypeNameException");
            }
                //---------------Test Result -----------------------
            catch (UnknownTypeNameException ex)
            {
                StringAssert.Contains("Unable to load the related object type while attempting to load a relationship definition", ex.Message);
            }
        }