public void Test_Create_WhenReflectiveProp_WithTwoRelationshipLevels_ShouldCreateReflectivePropMapper()
        {
            //---------------Set up test pack-------------------
            const string propName           = "MyName";
            var          propNameWithDashes = string.Format("-{0}-", propName);

            MyBO.LoadClassDefWithRelationship();
            MyRelatedBo.LoadClassDef();
            var bo          = new MyBO();
            var myRelatedBo = new MyRelatedBo();

            bo.MyRelationship = myRelatedBo;
            bo.MyRelationship.MyRelationship = new MyBO();
            var propertyPath = "MyRelationship.MyRelationship." + propNameWithDashes;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(ReflectionUtilities.GetPropertyInfo(bo.MyRelationship.MyRelationship.GetType(), propName));
            //---------------Execute Test ----------------------
            IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propertyPath);

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <ReflectionPropertyMapper>(propMapper);
            Assert.AreEqual(propName, propMapper.PropertyName);
            Assert.AreSame(bo.MyRelationship.MyRelationship, propMapper.BusinessObject);
        }
示例#2
0
        private void ApplyRowCellValueToBOProperty(DataRow row, UIGridColumn uiProperty, IBusinessObject changedBo)
        {
            string columnName = uiProperty.PropertyName;

            if (!uiProperty.Editable)
            {
                return;
            }
            IBOPropertyMapper boPropertyMapper = BOPropMapperFactory.CreateMapper(changedBo, columnName);

            boPropertyMapper.SetPropertyValue(row[columnName]);
            row.SetColumnError(columnName, boPropertyMapper.InvalidReason);
        }
        public void Test_Create_WhenRelatedProp_ShouldCreateBOPropMapper()
        {
            //---------------Set up test pack-------------------
            const string propName = "Organisation.Name";
            var          bo       = new ContactPersonTestBO();

            //---------------Assert Precondition----------------
            Assert.IsTrue(bo.Relationships.Contains("Organisation"));
            //---------------Execute Test ----------------------
            IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propName);

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <BOPropertyMapper>(propMapper);
            Assert.AreEqual(propName, propMapper.PropertyName);
            Assert.AreSame(bo, propMapper.BusinessObject);
        }
        public void Test_Create_WhenReflectiveProp_WhenNotDefinedWithDash_ShouldCreateReflectivePropMapper()
        {
            //---------------Set up test pack-------------------
            const string propName = "ReflectiveProp";
            var          bo       = new ContactPersonTestBO();
            //---------------Assert Precondition----------------
            var propertyInfo = ReflectionUtilities.GetPropertyInfo(bo.GetType(), propName);

            Assert.IsNotNull(propertyInfo);
            //---------------Execute Test ----------------------
            IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propName);

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <ReflectionPropertyMapper>(propMapper);
            Assert.AreEqual(propName, propMapper.PropertyName);
            Assert.AreSame(bo, propMapper.BusinessObject);
        }
        public void Test_Create_WhenRelatedReflectiveProp_WithNullRelationship_ShouldCreateBOPropMapper()
        {
            //---------------Set up test pack-------------------
            const string propName = "Organisation.-Name-";
            var          bo       = new ContactPersonTestBO();

            bo.Organisation = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(bo.Relationships.Contains("Organisation"));
            //---------------Execute Test ----------------------
            IBOPropertyMapper propMapper = BOPropMapperFactory.CreateMapper(bo, propName);

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <NullBOPropertyMapper>(propMapper);
            Assert.AreEqual(propName, propMapper.PropertyName);
            Assert.AreSame(bo, propMapper.BusinessObject);
            Assert.AreEqual("The 'Organisation' relationship of the 'ContactPersonTestBO' returned null, therefore the '-Name-' property could not be accessed.", propMapper.InvalidReason);
        }