Exemplo n.º 1
0
        /// <summary>
        /// Returns a lookup-list for all the business objects stored under
        /// the class definition held in this instance.  An option is included to ignore the default
        /// timeout, which causes use of a cached version within the timeout
        /// period.
        /// </summary>
        /// <param name="ignoreTimeout">Whether to ignore the timeout and reload from the database regardless of when the lookup list was last loaded.</param>
        /// <returns>Returns a collection of string-value pairs</returns>
        public Dictionary <string, string> GetLookupList(bool ignoreTimeout)
        {
            if (!ignoreTimeout && CacheHasNotTimedOut())
            {
                _lastCallTime = DateTime.Now;
                return(DisplayValueDictionary);
            }
            var classDef      = LookupBoClassDef;
            var primaryKeyDef = ClassDefHelper.GetPrimaryKeyDef(classDef, ClassDef.ClassDefs);

            if (primaryKeyDef.Count > 1)
            {
                throw new HabaneroDeveloperException
                          ("There is an application setup error. Please contact your system administrator",
                          "The lookup list cannot contain business objects '" + classDef.ClassNameFull
                          + "' with a composite primary key.");
            }

            IBusinessObjectCollection col = GetBusinessObjectCollection();

            DisplayValueDictionary = CreateDisplayValueDictionary(col, OrderCriteria == null);
            FillKeyValueDictionary();
            _lastCallTime = DateTime.Now;
            return(DisplayValueDictionary);
        }
Exemplo n.º 2
0
        public void Test_GetSuperClassClassDef_WithTypeParameter()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ClassDefCol classDefCol = new ClassDefCol();
            ClassDef    classDef1   = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);

            classDef1.TypeParameter = "TypeParam1";
            classDefCol.Add(classDef1);
            ClassDef classDef2 = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);

            classDef2.TypeParameter = "TypeParam2";
            classDefCol.Add(classDef2);
            SuperClassDef superClassDef = new SuperClassDef(classDef2.AssemblyName, classDef2.ClassNameExcludingTypeParameter, ORMapping.ClassTableInheritance, null, null);

            superClassDef.TypeParameter = classDef2.TypeParameter;
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, ClassDef.ClassDefs.Count);
            Assert.AreEqual(2, classDefCol.Count);
            //---------------Execute Test ----------------------
            IClassDef def = ClassDefHelper.GetSuperClassClassDef(superClassDef, classDefCol);

            //---------------Test Result -----------------------
            Assert.IsNotNull(def);
            Assert.AreSame(classDef2, def);
        }
Exemplo n.º 3
0
        public void Test_GetPrimaryKeyDef_ClassWithPKFromSuperClass()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef parentDef = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass(
                @"	<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" >
							<property  name=""TestClassID"" type=""Guid"" />
                            <primaryKey>
                                <prop name=""TestClassID""/>
                            </primaryKey>
						</class>"                        );
            IClassDef def = new XmlClassLoader(new DtdLoader(), new DefClassFactory()).LoadClass(
                @"
				<class name=""TestRelatedClass"" assembly=""Habanero.Test.BO.Loaders"">
					<superClass class=""TestClass"" assembly=""Habanero.Test.BO.Loaders"" />
					<property  name=""TestProp"" type=""Guid"" />                    
				</class>
			"            );
            ClassDefCol classDefCol = new ClassDefCol();

            classDefCol.Add(parentDef);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(parentDef.PrimaryKeyDef);
            Assert.IsNotNull(def.SuperClassDef);
            Assert.IsNull(def.PrimaryKeyDef);
            //---------------Execute Test ----------------------
            IPrimaryKeyDef primaryKeyDef = ClassDefHelper.GetPrimaryKeyDef(def, classDefCol);

            //---------------Test Result -----------------------
            Assert.IsNotNull(primaryKeyDef);
            Assert.AreSame(parentDef.PrimaryKeyDef, primaryKeyDef);
        }
Exemplo n.º 4
0
        public void Test_GetSuperClassClassDef_NotFound()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ClassDef classDef = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);

            ClassDef.ClassDefs.Add(classDef);
            SuperClassDef superClassDef = new SuperClassDef(classDef.AssemblyName, classDef.ClassName, ORMapping.ClassTableInheritance, null, null);
            ClassDefCol   classDefCol   = new ClassDefCol();

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

            //---------------Execute Test ----------------------
            try
            {
                ClassDefHelper.GetSuperClassClassDef(superClassDef, classDefCol);
                //---------------Test Result -----------------------
                Assert.Fail("Expected to throw an InvalidXmlDefinitionException");
            }
            catch (InvalidXmlDefinitionException ex)
            {
                StringAssert.Contains("The class definition for the super class with the type " +
                                      "'Habanero.Test.BO.UnknownClass' was not found. Check that the class definition " +
                                      "exists or that spelling and capitalisation are correct. " +
                                      "There are 0 class definitions currently loaded.", ex.Message);
            }
        }
Exemplo n.º 5
0
        ///<summary>
        /// For a given value e.g. a Guid Identifier '{......}' this will build up a primary key object that can be used to
        /// load the business object from the Data store (see Business Object loader GetBusinessObjectByValue)
        /// This can only be used for business objects that have a single property for the primary key
        /// (i.e. non composite primary keys)
        ///</summary>
        ///<param name="classDef">The Class definition of the Business Object to load</param>
        ///<param name="idValue">The value of the primary key of the business object</param>
        ///<returns>the BOPrimaryKey if this can be constructed else returns null</returns>
        public static BOPrimaryKey CreateWithValue(ClassDef classDef, object idValue)
        {
            var primaryKeyDef = (PrimaryKeyDef)ClassDefHelper.GetPrimaryKeyDef(classDef, ClassDef.ClassDefs);

            if (primaryKeyDef.IsCompositeKey)
            {
                return(null);
            }

            var boPropCol    = classDef.CreateBOPropertyCol(true);
            var boPrimaryKey = primaryKeyDef.CreateBOKey(boPropCol) as BOPrimaryKey;

            if (boPrimaryKey != null)
            {
                boPrimaryKey[0].Value = idValue;
            }
            return(boPrimaryKey);
        }
Exemplo n.º 6
0
        public void Test_GetSuperClassClassDef()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ClassDefCol classDefCol = new ClassDefCol();
            ClassDef    classDef    = new ClassDef("Habanero.Test.BO", "UnknownClass", null, null, null, null, null);

            classDefCol.Add(classDef);
            SuperClassDef superClassDef = new SuperClassDef(classDef.AssemblyName, classDef.ClassName, ORMapping.ClassTableInheritance, null, null);

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, ClassDef.ClassDefs.Count);
            Assert.AreEqual(1, classDefCol.Count);
            //---------------Execute Test ----------------------
            IClassDef def = ClassDefHelper.GetSuperClassClassDef(superClassDef, classDefCol);

            //---------------Test Result -----------------------
            Assert.IsNotNull(def);
            Assert.AreSame(classDef, def);
        }