protected static RelationshipDefCol CreateRelationshipDefCol(PropDefCol lPropDefCol) { RelationshipDefCol relDefCol = new RelationshipDefCol(); //Define Driver Relationships RelKeyDef relKeyDef = new RelKeyDef(); IPropDef propDef = lPropDefCol[PK1_PROP1_NAME]; RelPropDef lRelPropDef = new RelPropDef(propDef, "DriverFK1"); relKeyDef.Add(lRelPropDef); propDef = lPropDefCol[PK1_PROP2_NAME]; lRelPropDef = new RelPropDef(propDef, "DriverFK2"); relKeyDef.Add(lRelPropDef); RelationshipDef relDef = new MultipleRelationshipDef("Driver", typeof(Car), relKeyDef, true, "", DeleteParentAction.DereferenceRelated); relDefCol.Add(relDef); return(relDefCol); }
private static RelationshipDefCol CreateRelationshipDefCol(IPropDefCol lPropDefCol) { RelationshipDefCol relDefCol = new RelationshipDefCol(); //Define Owner Relationships RelKeyDef relKeyDef; IPropDef propDef; RelPropDef lRelPropDef; relKeyDef = new RelKeyDef(); propDef = lPropDefCol["ContactPersonID"]; lRelPropDef = new RelPropDef(propDef, "OwnerId"); relKeyDef.Add(lRelPropDef); //RelationshipDef relDef1 = new MultipleRelationshipDef("Owner", typeof(Car), // relKeyDef, false, "", // DeleteParentAction.DereferenceRelated); RelationshipDef relDef2 = new MultipleRelationshipDef("Cars", typeof(Car), relKeyDef, false, "Engine.EngineNo", DeleteParentAction.DereferenceRelated); //relDefCol.Add(relDef1); relDefCol.Add(relDef2); relKeyDef = new RelKeyDef(); // propDef = lPropDefCol["ContactPersonID"]; lRelPropDef = new RelPropDef(propDef, "ContactPersonID"); relKeyDef.Add(lRelPropDef); RelationshipDef relDef3 = new MultipleRelationshipDef("Addresses", typeof(Address), relKeyDef, false, "", DeleteParentAction.DeleteRelated); relDefCol.Add(relDef3); return(relDefCol); }
public static IClassDef LoadDefaultClassDef_PreventAddChild() { XmlClassLoader itsLoader = CreateXmlClassLoader(); IClassDef itsClassDef = itsLoader.LoadClass( @" <class name=""OrganisationTestBO"" assembly=""Habanero.Test.BO"" table=""organisation""> <property name=""OrganisationID"" type=""Guid"" /> <property name=""Name"" /> <primaryKey> <prop name=""OrganisationID"" /> </primaryKey> </class> " ); RelPropDef relPropDef = new RelPropDef(itsClassDef.PropDefcol["OrganisationID"], "OrganisationID"); RelKeyDef relKeyDef = new RelKeyDef(); relKeyDef.Add(relPropDef); MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef("ContactPeople", "Habanero.Test.BO", "ContactPersonTestBO", relKeyDef, true, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Composition, 0); relationshipDef.ReverseRelationshipName = "Organisation"; itsClassDef.RelationshipDefCol.Add(relationshipDef); ClassDef.ClassDefs.Add(itsClassDef); return(itsClassDef); }
public void Test_CreateMultipleRelationshipDef_Association() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); ClassDef.ClassDefs.Clear(); OrganisationTestBO.LoadDefaultClassDef(); ContactPersonTestBO.LoadDefaultClassDef(); RelPropDef relPropDef = new RelPropDef(ClassDef.Get <OrganisationTestBO>().PropDefcol["OrganisationID"], "OrganisationID"); RelKeyDef relKeyDef = new RelKeyDef(); relKeyDef.Add(relPropDef); const int expectedTimeout = 550; MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef("ContactPeople", "Habanero.Test.BO", "ContactPersonTestBO", relKeyDef, true, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Association, expectedTimeout); OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation(); //---------------Assert Precondition---------------- Assert.AreEqual(expectedTimeout, relationshipDef.TimeOut); //---------------Execute Test ---------------------- MultipleRelationship <ContactPersonTestBO> relationship = (MultipleRelationship <ContactPersonTestBO>)relationshipDef.CreateRelationship(organisation, organisation.Props); //---------------Test Result ----------------------- Assert.AreEqual(expectedTimeout, relationship.TimeOut); Assert.AreEqual(InsertParentAction.InsertRelationship, relationship.RelationshipDef.InsertParentAction); }
public static IClassDef LoadDefaultClassDef_SingleRel_NoReverseRelationship() { XmlClassLoader itsLoader = CreateXmlClassLoader(); IClassDef itsClassDef = itsLoader.LoadClass( @" <class name=""OrganisationTestBO"" assembly=""Habanero.Test.BO"" table=""organisation""> <property name=""OrganisationID"" type=""Guid"" /> <property name=""Name"" /> <primaryKey> <prop name=""OrganisationID"" /> </primaryKey> </class> " ); RelPropDef relPropDef = new RelPropDef(itsClassDef.PropDefcol["OrganisationID"], "OrganisationID"); RelKeyDef relKeyDef = new RelKeyDef(); relKeyDef.Add(relPropDef); IRelationshipDef relationshipDef = new SingleRelationshipDef("ContactPerson", "Habanero.Test.BO", "ContactPersonTestBO", relKeyDef, true, DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Aggregation); relationshipDef.OwningBOHasForeignKey = false; itsClassDef.RelationshipDefCol.Add(relationshipDef); ClassDef.ClassDefs.Add(itsClassDef); return(itsClassDef); }
/// <summary> /// Create a new Relationship Prop Def. /// </summary> /// <returns></returns> public IRelPropDef CreateRelPropDef() { var ownerPropName = GetOwningPropName(this.PropertyWrapper.DeclaringType); var relatedPropName = GetRelatedPropName(); IRelPropDef relPropDef = new RelPropDef(ownerPropName, relatedPropName); return(relPropDef); }
public void init() { PropDef propDef = new PropDef("Prop", typeof(string), PropReadWriteRule.ReadWrite, null); _relPropDef = new RelPropDef(propDef, "PropName"); _propDefCol = new PropDefCol(); _propDefCol.Add(propDef); }
public void SetUp() { PropDef propDef = new PropDef("Prop", typeof(string), PropReadWriteRule.ReadWrite, null); mRelPropDef = new RelPropDef(propDef, "PropName"); mPropDefCol = new PropDefCol(); mPropDefCol.Add(propDef); BORegistry.DataAccessor = new DataAccessorInMemory(); }
/// <summary> /// Maps the <see cref="PropertyInfo"/> to a Many to One relationship /// </summary> /// <returns></returns> public IRelationshipDef MapManyToOne() { if (this.PropertyWrapper.DeclaringType == (Type)null) { return(null); } if (!MustBeMapped()) { return(null); } var relatedObjectType = this.PropertyWrapper.PropertyType; if (this.PropertyWrapper.HasAttribute <AutoMapManyToOneAttribute>()) { var manyToOneAttribute = this.PropertyWrapper.GetAttribute <AutoMapManyToOneAttribute>(); var specifiedType = manyToOneAttribute.RelatedObjectClassType; if (specifiedType != null) { relatedObjectType = specifiedType.ToTypeWrapper(); } } if (!relatedObjectType.IsBusinessObject) { throw new InvalidDefinitionException(string.Format( "The specified RelatedObjectClassType '{0}' on '{1}.{2}' must be a Business Object", relatedObjectType, this.PropertyWrapper.DeclaringClassName, this.PropertyWrapper.Name)); } if (!relatedObjectType.IsOfType(this.PropertyWrapper.UnderlyingPropertyType)) { throw new InvalidDefinitionException(string.Format( "The specified RelatedObjectClassType '{0}' on '{1}.{2}' must be assignment compatible with the actual property type '{3}'", relatedObjectType, this.PropertyWrapper.DeclaringClassName, this.PropertyWrapper.Name, this.PropertyWrapper.UnderlyingPropertyType)); } var relDef = new SingleRelationshipDef(this.PropertyWrapper.Name, relatedObjectType.UnderlyingType, new RelKeyDef(), true, DeleteParentAction.DoNothing); SetRelationshipType(relDef); if (this.PropertyWrapper.HasCompulsoryAttribute) { relDef.SetAsCompulsory(); } relDef.OwningBOHasForeignKey = true; SetReverseRelationshipName(relDef); var ownerPropName = GetOwningPropName(); var relatedPropName = GetRelatedPropName(relatedObjectType); IRelPropDef relPropDef = new RelPropDef(ownerPropName, relatedPropName); relDef.RelKeyDef.Add(relPropDef); return(relDef); }
public void TestRemove() { PropDef propDef = new PropDef("prop", typeof(string), PropReadWriteRule.ReadWrite, null); RelPropDef relPropDef = new RelPropDef(propDef, "prop"); RelKeyDefDefInheritor relKeyDef = new RelKeyDefDefInheritor(); relKeyDef.CallRemove(relPropDef); relKeyDef.Add(relPropDef); Assert.AreEqual(1, relKeyDef.Count); relKeyDef.CallRemove(relPropDef); Assert.AreEqual(0, relKeyDef.Count); }
public void AddPreventDeleteRelationship() { RelKeyDef relKeyDef = new RelKeyDef(); RelPropDef lRelPropDef = new RelPropDef(ClassDef.PropDefcol["ContactPersonID"], "ContactPersonID"); relKeyDef.Add(lRelPropDef); RelationshipDef relDef = new MultipleRelationshipDef("AddressesNoDelete", typeof(Address), relKeyDef, false, "", DeleteParentAction.Prevent); ClassDef.RelationshipDefCol = new RelationshipDefCol(); ClassDef.RelationshipDefCol.Add(relDef); Relationships.Add(new MultipleRelationship <Address>(this, relDef, Props)); }
private static MockBO GetMockBO(out RelationshipDef mRelationshipDef, out RelKeyDef mRelKeyDef) { MockBO _mMockBO = new MockBO(); IPropDefCol mPropDefCol = _mMockBO.PropDefCol; mRelKeyDef = new RelKeyDef(); IPropDef propDef = mPropDefCol["MockBOProp1"]; RelPropDef lRelPropDef = new RelPropDef(propDef, "MockBOID"); mRelKeyDef.Add(lRelPropDef); mRelationshipDef = new SingleRelationshipDef("Relation1", typeof(MockBO), mRelKeyDef, false, DeleteParentAction.Prevent); return(_mMockBO); }
public void TestAddNullException() { //---------------Execute Test ---------------------- try { RelPropDef relPropDef = new RelPropDef((string)null, ""); Assert.Fail("Expected to throw an HabaneroArgumentException"); } //---------------Test Result ----------------------- catch (HabaneroArgumentException ex) { StringAssert.Contains("The argument 'ownerClassPropDefName' is not valid. ownerClassPropDefName cannot be null", ex.Message); } }
public void Test_OwnerPropDef_ShouldReturnIPropDef() { //---------------Set up test pack------------------- PropDef propDef = new PropDef("Prop", typeof(string), PropReadWriteRule.ReadWrite, null); var relPropDef = new RelPropDef(propDef, "PropName"); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var ownerPropDef = relPropDef.OwnerPropDef; //---------------Test Result ----------------------- Assert.IsNotNull(ownerPropDef); Assert.AreSame(propDef, ownerPropDef); }
public void TestCreateRelPropNotNull() { PropDef propDef = new PropDef("Prop1", typeof(string), PropReadWriteRule.ReadWrite, "1"); RelPropDef relPropDef = new RelPropDef(propDef, "PropName1"); PropDefCol propDefCol = new PropDefCol(); propDefCol.Add(propDef); IBOPropCol propCol = propDefCol.CreateBOPropertyCol(true); IRelProp relProp = relPropDef.CreateRelProp(propCol); Assert.AreEqual(relPropDef.OwnerPropertyName, relProp.OwnerPropertyName); Assert.AreEqual(relPropDef.RelatedClassPropName, relProp.RelatedClassPropName); Assert.IsFalse(relProp.IsNull); }
public void Test_Contains_WhenNotHas_ShouldReturnFalse() { //---------------Set up test pack------------------- var relKeyDef = new RelKeyDef(); const string ownerClassPropDefName = "fdafads"; IRelPropDef relPropDef = new RelPropDef(ownerClassPropDefName, "fdafasd"); relKeyDef.Add(relPropDef); //---------------Assert Precondition---------------- Assert.AreEqual(1, relKeyDef.Count); //---------------Execute Test ---------------------- var contains = relKeyDef.Contains("SomeOtherName"); //---------------Test Result ----------------------- Assert.IsFalse(contains); }
public static ClassDef CreateClassDefWithShapeRelationship() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDef lKeyDef = new KeyDef(); lKeyDef.IgnoreIfNull = true; lKeyDef.Add(lPropDefCol["PK2Prop1"]); lKeyDef.Add(lPropDefCol["PK2Prop2"]); KeyDefCol keysCol = new KeyDefCol(); keysCol.Add(lKeyDef); lKeyDef = new KeyDef(); lKeyDef.IgnoreIfNull = false; lKeyDef.Add(lPropDefCol["PK3Prop"]); keysCol.Add(lKeyDef); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["ContactPersonID"]); //Releationships RelationshipDefCol relDefs = new RelationshipDefCol(); RelKeyDef relKeyDef = new RelKeyDef(); IPropDef propDef = lPropDefCol["ContactPersonID"]; RelPropDef lRelPropDef = new RelPropDef(propDef, "OwnerId"); relKeyDef.Add(lRelPropDef); RelationshipDef relDef = new MultipleRelationshipDef("Shapes", typeof(Shape), relKeyDef, false, "", DeleteParentAction.DereferenceRelated); //relDefCol.Add(relDef1); relDefs.Add(relDef); ClassDef lClassDef = new ClassDef(typeof(ContactPerson), primaryKey, "contact_person", lPropDefCol, keysCol, relDefs); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private static RelationshipDefCol CreateRelationshipDefCol(IPropDefCol lPropDefCol) { RelationshipDefCol relDefCol = new RelationshipDefCol(); //Define Owner Relationships RelKeyDef relKeyDef = new RelKeyDef(); IPropDef propDef = lPropDefCol["OwnerId"]; RelPropDef lRelPropDef = new RelPropDef(propDef, "ContactPersonID"); relKeyDef.Add(lRelPropDef); RelationshipDef relDef = new SingleRelationshipDef("Owner", typeof(ContactPerson), relKeyDef, false, DeleteParentAction.Prevent); relDefCol.Add(relDef); //Define Driver Relationships relKeyDef = new RelKeyDef(); propDef = lPropDefCol["DriverFK1"]; lRelPropDef = new RelPropDef(propDef, "PK1Prop1"); relKeyDef.Add(lRelPropDef); propDef = lPropDefCol["DriverFK2"]; lRelPropDef = new RelPropDef(propDef, "PK1Prop2"); relKeyDef.Add(lRelPropDef); relDef = new SingleRelationshipDef("Driver", typeof(ContactPersonCompositeKey), relKeyDef, true, DeleteParentAction.Prevent); relDefCol.Add(relDef); //Define Engine Relationships relKeyDef = new RelKeyDef(); propDef = lPropDefCol["CarID"]; lRelPropDef = new RelPropDef(propDef, "CarID"); relKeyDef.Add(lRelPropDef); relDef = new SingleRelationshipDef("Engine", typeof(Engine), relKeyDef, false, DeleteParentAction.DereferenceRelated) { OwningBOHasForeignKey = false }; relDefCol.Add(relDef); return(relDefCol); }
private static RelationshipDefCol CreateRelationshipDefCol(IPropDefCol lPropDefCol) { RelationshipDefCol relDefCol = new RelationshipDefCol(); //Define Relationships RelKeyDef relKeyDef = new RelKeyDef(); IPropDef propDef = lPropDefCol["ContactPersonID"]; RelPropDef relPropDef = new RelPropDef(propDef, "ContactPersonID"); relKeyDef.Add(relPropDef); RelationshipDef relDef = new SingleRelationshipDef("ContactPerson", typeof(ContactPerson), relKeyDef, false, DeleteParentAction.Prevent); relDefCol.Add(relDef); return(relDefCol); }
public void init() { this.SetupDBConnection(); mMockBo = new MockBO(); mPropDefCol = mMockBo.PropDefCol; mRelKeyDef = new RelKeyDef(); IPropDef propDef = mPropDefCol["MockBOProp1"]; RelPropDef lRelPropDef = new RelPropDef(propDef, "MockBOID"); mRelKeyDef.Add(lRelPropDef); mRelationshipDef = new SingleRelationshipDef ("Relation1", typeof(MockBO), mRelKeyDef, false, DeleteParentAction.Prevent); //DatabaseConnection.CurrentConnection.ConnectionString = MyDBConnection.GetConnectionString(); }
public void Setup() { ClassDef.ClassDefs.Clear(); mRelKeyDef = new RelKeyDef(); mPropDefCol = new PropDefCol(); PropDef propDef = new PropDef("Prop", typeof(string), PropReadWriteRule.ReadWrite, "1"); mPropDefCol.Add(propDef); RelPropDef lRelPropDef = new RelPropDef(propDef, "PropName"); mRelKeyDef.Add(lRelPropDef); propDef = new PropDef("Prop2", typeof(string), PropReadWriteRule.ReadWrite, "2"); mPropDefCol.Add(propDef); lRelPropDef = new RelPropDef(propDef, "PropName2"); mRelKeyDef.Add(lRelPropDef); }
public void TestFieldDefaultLabelFromRelatedClassDef() { ClassDef.ClassDefs.Clear(); ClassDef classDef = CreateTestClassDef(""); ClassDef classDef2 = CreateTestClassDef("2"); ClassDef.ClassDefs.Add(classDef2); RelKeyDef relKeyDef = new RelKeyDef(); RelPropDef relPropDef = new RelPropDef(classDef.PropDefcol["TestProperty"], "TestProperty2"); relKeyDef.Add(relPropDef); SingleRelationshipDef def = new SingleRelationshipDef("TestRel", classDef2.AssemblyName, classDef2.ClassName, relKeyDef, false, DeleteParentAction.Prevent); classDef.RelationshipDefCol.Add(def); UIFormField uiFormField = new UIFormField(null, "TestRel.TestProperty2", typeof(TextBox), null, null, true, null, null, LayoutStyle.Label); Assert.AreEqual("Tested Property2:", uiFormField.GetLabel(classDef)); }
public void init() { BORegistry.DataAccessor = new DataAccessorInMemory(); _fakeBO = new MockBO(); _propDefCol = _fakeBO.PropDefCol; _RelKeyDef = new RelKeyDef(); IPropDef propDef = _propDefCol["MockBOID"]; RelPropDef relPropDef = new RelPropDef(propDef, "MockBOProp1"); _RelKeyDef.Add(relPropDef); _multipleRelationshipDef = new MultipleRelationshipDef("Relation1", typeof(MockBO), _RelKeyDef, false, "", DeleteParentAction.DeleteRelated); _singleRelationshipDef = new SingleRelationshipDef("Single", typeof(MockBO), _RelKeyDef, false, DeleteParentAction.DeleteRelated); }
public void TestFieldDefaultLabelFromRelatedClassDef() { ClassDef.ClassDefs.Clear(); ClassDef classDef = CreateTestClassDef(""); ClassDef classDef2 = CreateTestClassDef("2"); ClassDef.ClassDefs.Add(classDef2); RelKeyDef relKeyDef = new RelKeyDef(); RelPropDef relPropDef = new RelPropDef(classDef.PropDefcol["TestProperty"], "TestProperty2"); relKeyDef.Add(relPropDef); SingleRelationshipDef def = new SingleRelationshipDef("TestRel", classDef2.AssemblyName, classDef2.ClassName, relKeyDef, false, DeleteParentAction.Prevent); classDef.RelationshipDefCol.Add(def); UIGridColumn uiGridColumn; uiGridColumn = new UIGridColumn(null, "TestRel.TestProperty2", typeof(DataGridViewTextBoxColumn), false, 100, PropAlignment.left, null); #pragma warning disable 612,618 Assert.AreEqual("Tested Property2", uiGridColumn.GetHeading(classDef)); #pragma warning restore 612,618 }
public void Test_IsCompulsory_WhenPropCompButNotOwningBoHasFK_ShouldRetFalse() { //---------------Set up test pack------------------- FakeSingleRelationshipDef relationshipDef = new FakeSingleRelationshipDef(); var relKeyDef = new RelKeyDef(); var propDef = new PropDefFake { Compulsory = true }; var relPropDef = new RelPropDef(propDef, "SomeThing"); relKeyDef.Add(relPropDef); relationshipDef.SetRelKeyDef(relKeyDef); relationshipDef.OwningBOHasForeignKey = false; //---------------Assert Precondition---------------- Assert.IsTrue(propDef.Compulsory); Assert.IsFalse(relationshipDef.OwningBOHasForeignKey); //---------------Execute Test ---------------------- bool isCompulsory = relationshipDef.IsCompulsory; //---------------Test Result ----------------------- Assert.IsFalse(isCompulsory, "Rel Should not be compulsory"); }
public void init() { _mockBo = new MockBO(); _propDefCol = _mockBo.PropDefCol; _RelKeyDef = new RelKeyDef(); IPropDef propDef = _propDefCol["MockBOID"]; RelPropDef relPropDef = new RelPropDef(propDef, "MockBOProp1"); _RelKeyDef.Add(relPropDef); _multipleRelationshipDef = new MultipleRelationshipDef("Relation1", typeof(MockBO), _RelKeyDef, false, "", DeleteParentAction.DeleteRelated); _singleRelationshipDef = new SingleRelationshipDef("Single", typeof(MockBO), _RelKeyDef, false, DeleteParentAction.DeleteRelated); DatabaseConnection.CurrentConnection.ConnectionString = MyDBConnection.GetConnectionString(); }
///<summary> /// Creates a Reverse Relationship when required. ///</summary> ///<param name="classDefCol"></param> ///<param name="classDef"></param> ///<param name="relationship"></param> ///<returns></returns> public static IRelationshipDef CreateReverseRelationship(ClassDefCol classDefCol, IClassDef classDef, IRelationshipDef relationship) { IRelationshipDef rel = relationship; if (!ContainsRelatedClass(relationship, classDefCol)) { return(null); } IClassDef relatedClassDef = RelatedObjectClassDef(classDefCol, relationship); bool foundReverseRelationship = relatedClassDef.RelationshipDefCol.Any( def => def.RelationshipName == rel.ReverseRelationshipName); if (foundReverseRelationship) { return(null); } IRelationshipDef newReverseRelDef = CreateReverseRelDef(rel, classDef); relatedClassDef.RelationshipDefCol.Add(newReverseRelDef); IRelPropDef relPropDef = relationship.RelKeyDef.FirstOrDefault(); if (relPropDef != null) { var reverseRelPropDef = new RelPropDef(relPropDef.RelatedClassPropName, relPropDef.OwnerPropertyName); newReverseRelDef.RelKeyDef.Add(reverseRelPropDef); bool hasPropDef = relatedClassDef.PropDefColIncludingInheritance.Any( propDef => propDef.PropertyName == reverseRelPropDef.OwnerPropertyName); if (!hasPropDef) { var fkPropDef = new PropDef(reverseRelPropDef.OwnerPropertyName, typeof(Guid), PropReadWriteRule.ReadWrite, null); relatedClassDef.PropDefcol.Add(fkPropDef); } } return(newReverseRelDef); }
public void Test_IsCompulsory_WhenNotHasCompulsoryFKProps_ShouldReturnFalse() { FakeSingleRelationshipDef singleRelationshipDef = new FakeSingleRelationshipDef(); var relKeyDef = new RelKeyDef(); var propDef = new PropDefFake { Compulsory = false }; var relPropDef = new RelPropDef(propDef, "SomeThing"); relKeyDef.Add(relPropDef); singleRelationshipDef.SetRelKeyDef(relKeyDef); singleRelationshipDef.OwningBOHasForeignKey = true; IRelationshipDef relationshipDef = singleRelationshipDef; //---------------Assert Precondition---------------- Assert.IsFalse(propDef.Compulsory); Assert.IsTrue(singleRelationshipDef.OwningBOHasForeignKey); //---------------Execute Test ---------------------- bool isCompulsory = relationshipDef.IsCompulsory; //---------------Test Result ----------------------- Assert.IsFalse(isCompulsory); }
private static ClassDef CreateClassDef(long number, bool hasSingleRelationship, bool hasMultipleRelationship, bool hasMultipleRelationshipWithPreventDelete) { const string assemblyName = "Habanero.Test.BO"; const string className = "TestBO"; const string idPropName = "MyBoID"; const string fkPropertyName = "MyParentBoID"; string suffix = number.ToString(); PropDefCol propDefCol = new PropDefCol(); PrimaryKeyDef primaryKeyDef = new PrimaryKeyDef(); primaryKeyDef.IsGuidObjectID = false; RelationshipDefCol relationshipDefCol = new RelationshipDefCol(); PropDef idPropDef = new PropDef(idPropName, typeof(string), PropReadWriteRule.ReadWrite, ""); propDefCol.Add(idPropDef); primaryKeyDef.Add(idPropDef); //propDef = new PropDef("MyProp", typeof(string), PropReadWriteRule.ReadWrite, "" ); //propDefCol.Add(propDef); PropDef propDef = new PropDef(fkPropertyName, typeof(string), PropReadWriteRule.ReadWrite, ""); propDefCol.Add(propDef); if (hasSingleRelationship) { string relatedClassSuffix = (number - 1).ToString(); RelKeyDef relKeyDef = new RelKeyDef(); RelPropDef relPropDef = new RelPropDef(propDef, idPropName); relKeyDef.Add(relPropDef); SingleRelationshipDef singleRelationshipDef = new SingleRelationshipDef( "MyParent", assemblyName, className + relatedClassSuffix, relKeyDef, false, DeleteParentAction.Prevent); relationshipDefCol.Add(singleRelationshipDef); } if (hasMultipleRelationship) { string relatedClassSuffix = (number + 1).ToString(); RelKeyDef relKeyDef = new RelKeyDef(); RelPropDef relPropDef = new RelPropDef(idPropDef, fkPropertyName); relKeyDef.Add(relPropDef); MultipleRelationshipDef multipleRelationshipDef = new MultipleRelationshipDef("MyBO" + relatedClassSuffix, assemblyName, className + relatedClassSuffix, relKeyDef, false, "", DeleteParentAction.DeleteRelated); relationshipDefCol.Add(multipleRelationshipDef); } if (hasMultipleRelationshipWithPreventDelete) { string relatedClassSuffix = (number + 1).ToString(); RelKeyDef relKeyDef = new RelKeyDef(); RelPropDef relPropDef = new RelPropDef(idPropDef, fkPropertyName); relKeyDef.Add(relPropDef); MultipleRelationshipDef multipleRelationshipDef = new MultipleRelationshipDef("MyPreventBO" + relatedClassSuffix, assemblyName, className + relatedClassSuffix, relKeyDef, false, "", DeleteParentAction.Prevent); relationshipDefCol.Add(multipleRelationshipDef); } ClassDef classDef = new ClassDef(assemblyName, className + suffix, primaryKeyDef, propDefCol, new KeyDefCol(), relationshipDefCol, new UIDefCol()); return(classDef); }
/// <summary> /// Constructor to initialise a new property /// </summary> /// <param name="mRelPropDef">The relationship property definition</param> /// <param name="lBoProp">The property</param> internal RelProp(RelPropDef mRelPropDef, IBOProp lBoProp) { this._relPropDef = mRelPropDef; _boProp = lBoProp; lBoProp.Updated += (sender, e) => FirePropValueUpdatedEvent(); }