public void TestColIsInstantiatedButNotLoaded() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); OrganisationTestBO.LoadDefaultClassDef(); IClassDef contactPersonClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse(); RelKeyDef keyDef = new RelKeyDef(); keyDef.Add(new RelPropDef(contactPersonClassDef.PropDefcol["OrganisationID"], "OrganisationID")); MultipleRelationshipDef def = new MultipleRelationshipDef (TestUtil.GetRandomString(), typeof(ContactPersonTestBO), keyDef, false, "", DeleteParentAction.DoNothing); OrganisationTestBO organisation = new OrganisationTestBO(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IMultipleRelationship rel = (IMultipleRelationship) def.CreateRelationship(organisation, organisation.Props); //---------------Test Result ----------------------- IBusinessObjectCollection collection = rel.BusinessObjectCollection; Assert.IsNotNull(collection); Assert.AreEqual(0, collection.Count); Assert.AreSame(contactPersonClassDef, collection.ClassDef); Assert.IsNotNull(collection.SelectQuery.Criteria); Assert.IsNotNull(collection.SelectQuery.Criteria.Field); Assert.AreEqual("OrganisationID", collection.SelectQuery.Criteria.Field.PropertyName); Assert.IsNotNull(collection.SelectQuery.Criteria.Field.Source); Assert.AreEqual("ContactPersonTestBO", collection.SelectQuery.Criteria.Field.Source.Name); Assert.AreEqual(organisation.OrganisationID.Value, collection.SelectQuery.Criteria.FieldValue); Assert.IsInstanceOf(typeof(ContactPersonTestBO), collection.CreateBusinessObject()); }
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); }
private static IRelationshipDef CreateReverseRelDef(IRelationshipDef rel, IClassDef classDef) { IRelationshipDef newReverseRelDef; if (rel.IsManyToOne) { newReverseRelDef = new MultipleRelationshipDef(rel.ReverseRelationshipName , classDef.ClassType, new RelKeyDef(), true, "" , DeleteParentAction.Prevent); }else { newReverseRelDef = new SingleRelationshipDef(rel.ReverseRelationshipName , classDef.ClassType, new RelKeyDef(), true , DeleteParentAction.DoNothing); } newReverseRelDef.ReverseRelationshipName = rel.RelationshipName; return newReverseRelDef; }
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; }
public static IClassDef LoadDefaultClassDef_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); MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef("ContactPeople", "Habanero.Test.BO", "ContactPersonTestBO", relKeyDef, true, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Composition, 0); itsClassDef.RelationshipDefCol.Add(relationshipDef); ClassDef.ClassDefs.Add(itsClassDef); return itsClassDef; }
public void TestFromIRelationship_MultipleProps() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); RelKeyDef relKeyDef = new RelKeyDef(); const string propValue1 = "bob1"; PropDef boPropDef1 = new PropDef("Prop1", typeof(String), PropReadWriteRule.ReadWrite, propValue1); relKeyDef.Add(new RelPropDef(boPropDef1, "RelatedProp1")); const string propValue2 = "bob2"; PropDef boPropDef2 = new PropDef("Prop2", typeof(String), PropReadWriteRule.ReadWrite, propValue2); relKeyDef.Add(new RelPropDef(boPropDef2, "RelatedProp2")); RelationshipDef reldef = new MultipleRelationshipDef("bob", "Habanero.Test", "MyBO", relKeyDef, false, "", DeleteParentAction.DoNothing); ContactPersonTestBO.LoadDefaultClassDef(); ContactPersonTestBO cp = new ContactPersonTestBO(); BOPropCol col = new BOPropCol(); col.Add(boPropDef1.CreateBOProp(true)); col.Add(boPropDef2.CreateBOProp(true)); IRelationship relationship = reldef.CreateRelationship(cp, col); //---------------Assert PreConditions--------------- //---------------Execute Test ---------------------- Criteria criteria = Criteria.FromRelationship(relationship); //---------------Test Result ----------------------- string expectedString = string.Format("(RelatedProp1 = '{0}') AND (RelatedProp2 = '{1}')", propValue1, propValue2); StringAssert.AreEqualIgnoringCase(expectedString, criteria.ToString()); //---------------Tear Down ------------------------- }
public void Test_CreateMultipleRelationshipDef_Composition() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef(TestUtil.GetRandomString(), TestUtil.GetRandomString(), TestUtil.GetRandomString(), new RelKeyDef(), false, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Composition, 10000); //---------------Test Result ----------------------- Assert.AreEqual(RelationshipType.Composition, relationshipDef.RelationshipType); }
public void Test_IsCompulsory_AlwaysTrueForMultiple() { //---------------Set up test pack------------------- MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef(TestUtil.GetRandomString(), TestUtil.GetRandomString(), TestUtil.GetRandomString(), new RelKeyDef(), false, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Composition, 10000); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var isCompulsory = relationshipDef.IsCompulsory; //---------------Test Result ----------------------- Assert.IsFalse(isCompulsory); }
/// <summary> /// Map the relationship including the Relationship props. /// </summary> /// <returns></returns> public IRelationshipDef MapOneToMany() { var propertyType = this.PropertyWrapper.PropertyType; if(!MustBeMapped()) return null; var singleReverseRelPropInfos = this.PropertyWrapper.GetSingleReverseRelPropInfos(); if (singleReverseRelPropInfos.Count > 1) { throw new InvalidDefinitionException("The Relationship '" + this.PropertyWrapper.Name + "' could not be automapped since there are multiple Single relationships on class '" + this.PropertyWrapper.RelatedClassType + "' that reference the BusinessObject Class '" + this.PropertyWrapper.DeclaringClassName + "'. Please map using ClassDef.XML or Attributes"); } var relationshipAttribute = this.PropertyWrapper.GetAttribute<AutoMapOneToManyAttribute>(); MultipleRelationshipDef relDef; if (propertyType.IsGenericType) { var relatedClassType = this.PropertyWrapper.RelatedClassType.UnderlyingType; relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, relatedClassType, new RelKeyDef(), true, "", DeleteParentAction.Prevent); }else { string className = StringUtilities.Singularize(this.PropertyWrapper.Name); relDef = new MultipleRelationshipDef(this.PropertyWrapper.Name, this.PropertyWrapper.AssemblyQualifiedName, className , new RelKeyDef(), true, "", DeleteParentAction.Prevent); } if(relationshipAttribute != null) { relDef.RelationshipType = relationshipAttribute.RelationshipType; DeleteParentAction deleteParentAction = relationshipAttribute.DeleteParentAction; relDef.DeleteParentAction = deleteParentAction; } relDef.ReverseRelationshipName = GetReverseRelationshipName(); var relPropDef = CreateRelPropDef(); relDef.RelKeyDef.Add(relPropDef); return relDef; }
public void Test_CheckCanAdd_NullObject() { //---------------Set up test pack------------------- MultipleRelationshipDef relDef = new MultipleRelationshipDef ("rel", typeof (MyRelatedBo), new RelKeyDef(), true, "", DeleteParentAction.Prevent); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- try { relDef.CheckCanAddChild(null); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("could not be added since the business object is null", ex.Message); } //---------------Test Result ----------------------- }
public void TestOwningBOHasForeignKey_Multiple() { //---------------Set up test pack------------------- MultipleRelationshipDef relDef = new MultipleRelationshipDef ("rel", typeof (MyRelatedBo), new RelKeyDef(), true, "", DeleteParentAction.Prevent); //---------------Execute Test ---------------------- relDef.OwningBOHasForeignKey = true; //---------------Test Result ----------------------- Assert.IsFalse(relDef.OwningBOHasForeignKey); //---------------Tear Down ------------------------- }
public void TestConstruct_WithTimeout_ShouldSetUpTimeout() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- const int expectedTimout = 10000; MultipleRelationshipDef relDef = new MultipleRelationshipDef ("rel", "", "", new RelKeyDef(), true, "", DeleteParentAction.Prevent, InsertParentAction.DoNothing, RelationshipType.Association, expectedTimout); //---------------Test Result ----------------------- Assert.AreEqual(expectedTimout, relDef.TimeOut); }
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)); }
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; 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; }