Habanero.Test.BO.AddressTestBO.LoadDefaultClassDef C# (CSharp) Method

LoadDefaultClassDef() public static method

public static LoadDefaultClassDef ( ) : IClassDef
return IClassDef
        public static IClassDef LoadDefaultClassDef()
        {
            XmlClassLoader itsLoader = new XmlClassLoader(new DtdLoader(), new DefClassFactory());
            IClassDef itsClassDef =
                itsLoader.LoadClass(
                    @"
				<class name=""AddressTestBO"" assembly=""Habanero.Test.BO"" table=""contact_person_address"">
					<property name=""AddressID"" type=""Guid"" />
                    <property name=""ContactPersonID"" type=""Guid"" />
					<property name=""OrganisationID"" type=""Guid""  />
                    <property name=""AddressLine1""  />
					<property name=""AddressLine2""  />
					<property name=""AddressLine3""  />
					<property name=""AddressLine4""  />
					<primaryKey>
						<prop name=""AddressID"" />
					</primaryKey>
                    <relationship name=""ContactPersonTestBO"" type=""single"" relatedClass=""ContactPersonTestBO"" relatedAssembly=""Habanero.Test.BO"" reverseRelationship=""Addresses"">
						<relatedProperty property=""ContactPersonID"" relatedProperty=""ContactPersonID"" />
					</relationship>
                    <ui>
						<grid>
							<column heading=""AddressLine1"" property=""AddressLine1"" type=""DataGridViewTextBoxColumn"" />
							<column heading=""AddressLine2"" property=""AddressLine2"" type=""DataGridViewTextBoxColumn"" />
							<column heading=""AddressLine3"" property=""AddressLine3"" type=""DataGridViewTextBoxColumn"" />
							<column heading=""AddressLine4"" property=""AddressLine4"" type=""DataGridViewTextBoxColumn"" />
						</grid>
					</ui>
			    </class>
			");
            ClassDef.ClassDefs.Add(itsClassDef);
            return itsClassDef;

        }

Usage Example

        public void Test_BusinessObject_WhenSet_HavingExistingNonSingleRelationshipOnRelatedBO_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO.LoadDefaultClassDef();
            IClassDef            contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO  contactPersonTestBO   = new ContactPersonTestBO();
            const string         innerRelationshipName = "ContactPersonTestBO";
            const string         outerRelationshipName = "Addresses";
            const string         relationshipName      = outerRelationshipName + "." + innerRelationshipName;
            BORelationshipMapper boRelationshipMapper  = new BORelationshipMapper(relationshipName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boRelationshipMapper.BusinessObject);
            Assert.IsNull(boRelationshipMapper.Relationship);
            //---------------Execute Test ----------------------
            try
            {
                boRelationshipMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw a HabaneroDeveloperException");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on '"
                                      + contactPersonClassDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.", ex.Message);
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on the BusinessObject '"
                                      + contactPersonClassDef.ClassNameFull + "' is not a Single Relationship therefore cannot be traversed.", ex.DeveloperMessage);
                Assert.IsNull(boRelationshipMapper.BusinessObject);
                Assert.IsNull(boRelationshipMapper.Relationship);
            }
        }
All Usage Examples Of Habanero.Test.BO.AddressTestBO::LoadDefaultClassDef