Пример #1
0
 public void init()
 {
     PropDef propDef = new PropDef("Prop", typeof(string), PropReadWriteRule.ReadWrite, null);
     _relPropDef = new RelPropDef(propDef, "PropName");
     _propDefCol = new PropDefCol();
     _propDefCol.Add(propDef);
 }
Пример #2
0
 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();
 }
Пример #3
0
 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;
 }
Пример #4
0
 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);
 }
Пример #5
0
        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);
        }
Пример #6
0
        private static RelationshipDefCol CreateRelationshipDefCol(PropDefCol lPropDefCol)
        {
            RelationshipDefCol relDefCol = new RelationshipDefCol();

            //Define Engine Relationships
            RelKeyDef relKeyDef = new RelKeyDef();
            IPropDef propDef = lPropDefCol["CarID"];

            RelPropDef lRelPropDef = new RelPropDef(propDef, "CarID");
            relKeyDef.Add(lRelPropDef);

            RelationshipDef relDef = new SingleRelationshipDef("Car", typeof (Car), relKeyDef, false, DeleteParentAction.Prevent);
            relDefCol.Add(relDef);

            return relDefCol;
        }
Пример #7
0
        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();
        }
Пример #8
0
        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);
        }
Пример #9
0
        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;
        }
        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 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();
        }
 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);
 }
Пример #13
0
        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);
        }
        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;
        }
Пример #15
0
 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);
     }
 }
Пример #16
0
 /// <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();
 }
Пример #17
0
        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));
        }
Пример #18
0
        public void TestGetRelationship()
        {
            ClassDef parentClassDef = new ClassDef(typeof(String), null, null, null, new RelationshipDefCol());
            Assert.IsNull(parentClassDef.GetRelationship("wrongrel"));

            ClassDef childClassDef = new ClassDef(typeof(String), null, null, null, new RelationshipDefCol());
            childClassDef.SuperClassDef = new SuperClassDef(parentClassDef, ORMapping.ClassTableInheritance);
            Assert.IsNull(parentClassDef.GetRelationship("wrongrel"));

            PropDef propDef = new PropDef("prop", typeof(String), PropReadWriteRule.ReadWrite, null);
            RelPropDef relPropDef = new RelPropDef(propDef, "relProp");
            RelKeyDef relKeyDef = new RelKeyDef();
            relKeyDef.Add(relPropDef);
            RelationshipDef relDef = new SingleRelationshipDef("rel", typeof(MyRelatedBo), relKeyDef, true, DeleteParentAction.Prevent);
            childClassDef.RelationshipDefCol.Add(relDef);
            Assert.AreEqual(relDef, childClassDef.GetRelationship("rel"));

            childClassDef.RelationshipDefCol = new RelationshipDefCol();
            parentClassDef.RelationshipDefCol.Add(relDef);
            Assert.AreEqual(relDef, childClassDef.GetRelationship("rel"));
        }
Пример #19
0
        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;
 }
        /// <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 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 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);
        }
Пример #24
0
 public void CallRemove(RelPropDef relPropDef)
 {
     Remove(relPropDef);
 }
Пример #25
0
        public void TestConstructors()
        {
            PropDef propDef = new PropDef("prop", typeof(String), PropReadWriteRule.ReadWrite, null);
            PropDefCol propDefCol = new PropDefCol();
            propDefCol.Add(propDef);
            PrimaryKeyDef primaryKeyDef = new PrimaryKeyDef();
            primaryKeyDef.Add(propDef);
            KeyDef keyDef = new KeyDef();
            keyDef.Add(propDef);
            KeyDefCol keyDefCol = new KeyDefCol();
            keyDefCol.Add(keyDef);
            RelPropDef relPropDef = new RelPropDef(propDef, "relProp");
            RelKeyDef relKeyDef = new RelKeyDef();
            relKeyDef.Add(relPropDef);
            //RelationshipDef relDef = new SingleRelationshipDef("rel", new BusinessObject().GetType(), relKeyDef, true);
            RelationshipDefCol relDefCol = new RelationshipDefCol();
            //relDefCol.Add(relDef);
            UIDef uiDef = new UIDef("default", null, null);
            UIDefCol uiDefCol = new UIDefCol();
            uiDefCol.Add(uiDef);

            ClassDef classDef = new ClassDef("ass", "class", null, null, null, null, null);
            Assert.AreEqual("ass", classDef.AssemblyName);
            Assert.AreEqual("class", classDef.ClassName);
            Assert.AreEqual("class", classDef.TableName);
            Assert.IsNull(classDef.PrimaryKeyDef);
            Assert.IsNull(classDef.PropDefcol);
            Assert.IsNull(classDef.KeysCol);
            Assert.IsNull(classDef.RelationshipDefCol);
            Assert.AreEqual(0, classDef.UIDefCol.Count);

            classDef = new ClassDef("ass", "class", primaryKeyDef, propDefCol,
                                             keyDefCol, relDefCol, uiDefCol);
            Assert.AreEqual("ass", classDef.AssemblyName);
            Assert.AreEqual("class", classDef.ClassName);
            Assert.AreEqual("class", classDef.TableName);
            Assert.AreEqual(1, classDef.PrimaryKeyDef.Count);
            Assert.AreEqual(1, classDef.PropDefcol.Count);
            Assert.AreEqual(1, classDef.KeysCol.Count);
            Assert.AreEqual(0, classDef.RelationshipDefCol.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);

            classDef = new ClassDef(typeof(String), primaryKeyDef, "table", propDefCol,
                                             keyDefCol, relDefCol, uiDefCol);
            //Assert.AreEqual("db", classDef.);  ? database has no usage
            Assert.AreEqual(typeof(String), classDef.ClassType);
            Assert.AreEqual("table", classDef.TableName);
            Assert.AreEqual(1, classDef.PrimaryKeyDef.Count);
            Assert.AreEqual(1, classDef.PropDefcol.Count);
            Assert.AreEqual(1, classDef.KeysCol.Count);
            Assert.AreEqual(0, classDef.RelationshipDefCol.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);

            classDef = new ClassDef(typeof(String), primaryKeyDef, "table", propDefCol,
                                             keyDefCol, relDefCol);
            //Assert.AreEqual("db", classDef.);  ? database has no usage
            Assert.AreEqual(typeof(String), classDef.ClassType);
            Assert.AreEqual("table", classDef.TableName);
            Assert.AreEqual(1, classDef.PrimaryKeyDef.Count);
            Assert.AreEqual(1, classDef.PropDefcol.Count);
            Assert.AreEqual(1, classDef.KeysCol.Count);
            Assert.AreEqual(0, classDef.RelationshipDefCol.Count);
            Assert.AreEqual(0, classDef.UIDefCol.Count);

            classDef = new ClassDef(typeof(String), primaryKeyDef, propDefCol,
                                             keyDefCol, relDefCol, uiDefCol);
            //Assert.AreEqual("db", classDef.);  ? database has no usage
            Assert.AreEqual(typeof(String), classDef.ClassType);
            Assert.AreEqual("String", classDef.TableName);
            Assert.AreEqual(1, classDef.PrimaryKeyDef.Count);
            Assert.AreEqual(1, classDef.PropDefcol.Count);
            Assert.AreEqual(1, classDef.KeysCol.Count);
            Assert.AreEqual(0, classDef.RelationshipDefCol.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);

            classDef = new ClassDef(typeof(String), primaryKeyDef, "table", propDefCol,
                                             keyDefCol, relDefCol, uiDefCol);
            //Assert.AreEqual("db", classDef.);  ? database has no usage
            Assert.AreEqual(typeof(String), classDef.ClassType);
            Assert.AreEqual("table", classDef.TableName);
            Assert.AreEqual(1, classDef.PrimaryKeyDef.Count);
            Assert.AreEqual(1, classDef.PropDefcol.Count);
            Assert.AreEqual(1, classDef.KeysCol.Count);
            Assert.AreEqual(0, classDef.RelationshipDefCol.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);
        }
Пример #26
0
        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
        }
        ///<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;
        }
Пример #28
0
 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);
 }
 /// <summary>
 /// Create a RelPropDef based on the OwningPrropName and the RelatedPropName.
 /// </summary>
 /// <returns></returns>
 public IRelPropDef CreateRelPropDef()
 {
     var relPropDef = new RelPropDef(this.GetOwningPropName(), this.GetRelatedPropName());
     return relPropDef;
 }
Пример #30
0
        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;
        }