示例#1
0
        protected static PropDefCol CreateBOPropDef()
        {
            PropDefCol lPropDefCol = new PropDefCol();
            PropDef    propDef     = new PropDef("Surname", typeof(String), PropReadWriteRule.ReadWrite, null);

            propDef.AddPropRule(new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
            lPropDefCol.Add(propDef);

            propDef = new PropDef("FirstName", typeof(String), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("DateOfBirth", typeof(DateTime), PropReadWriteRule.WriteOnce, null);
            lPropDefCol.Add(propDef);

            //Create concurrency control properties
            propDef = new PropDef("DateLastUpdated", typeof(DateTime), PropReadWriteRule.ReadWrite, DateTime.Now);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("UserLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("MachineLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("VersionNumber", typeof(int), PropReadWriteRule.ReadWrite, 1);
            lPropDefCol.Add(propDef);

            propDef = new PropDef(PK1_PROP1_NAME, typeof(string), PropReadWriteRule.ReadWrite, "PK1_Prop1", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef(PK1_PROP2_NAME, typeof(string), PropReadWriteRule.ReadWrite, "PK1_Prop2", null);
            lPropDefCol.Add(propDef);

            return(lPropDefCol);
        }
示例#2
0
 public void Test_ValidateProp_WhenPropNotValid_IsValidFalse()
 {
     //---------------Set up test pack-------------------
     //Test compulsory with no default set
     PropDef lPropDefWithRules = new PropDef("PropNameWithRules", "System", "String",
                                             PropReadWriteRule.ReadWrite, null, null, true, false);
     lPropDefWithRules.AddPropRule(new PropRuleString(lPropDefWithRules.PropertyName, "", -1, -1, null));
     IBOProp lBOProp = lPropDefWithRules.CreateBOProp(true);
     //---------------Assert Precondition----------------
     Assert.IsTrue(lBOProp.IsValid);
     Assert.AreEqual("", lBOProp.InvalidReason);
     //---------------Execute Test ----------------------
     lBOProp.Validate();
     //---------------Test Result -----------------------
     Assert.IsFalse(lBOProp.IsValid);
     StringAssert.Contains("'Prop Name With Rules' is a compulsory field and has no value.", lBOProp.InvalidReason);
 }
示例#3
0
        public void init()
        {
            mBOPropCol = new BOPropCol();
            mPropDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null);
            mBOPropCol.Add(mPropDef.CreateBOProp(false));

            mPropDef = new PropDef("Prop2", typeof(string), PropReadWriteRule.ReadWrite, null);
            mPropDef.AddPropRule(new PropRuleString(mPropDef.PropertyName, "Test Message", 1, 10, null));
            mBOPropCol.Add(mPropDef.CreateBOProp(false));

            BOPropCol anotherPropCol = new BOPropCol();
            PropDef anotherPropDef =
                new PropDef("TestAddPropCol", typeof(string), PropReadWriteRule.ReadWrite, null);
            anotherPropCol.Add(anotherPropDef.CreateBOProp(false));

            mBOPropCol.Add(anotherPropCol);
        }
示例#4
0
        public void init()
        {
            mBOPropCol = new BOPropCol();
            mPropDef   = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadWrite, null);
            mBOPropCol.Add(mPropDef.CreateBOProp(false));

            mPropDef = new PropDef("Prop2", typeof(string), PropReadWriteRule.ReadWrite, null);
            mPropDef.AddPropRule(new PropRuleString(mPropDef.PropertyName, "Test Message", 1, 10, null));
            mBOPropCol.Add(mPropDef.CreateBOProp(false));

            BOPropCol anotherPropCol = new BOPropCol();
            PropDef   anotherPropDef =
                new PropDef("TestAddPropCol", typeof(string), PropReadWriteRule.ReadWrite, null);

            anotherPropCol.Add(anotherPropDef.CreateBOProp(false));

            mBOPropCol.Add(anotherPropCol);
        }
示例#5
0
        private static PropDefCol CreateBOPropDef()
        {
            PropDefCol lPropDefCol = new PropDefCol();
            PropDef    propDef     =
                new PropDef("Surname", "System", "String", PropReadWriteRule.ReadWrite, "Surname_field", null, true, false);

            propDef.AddPropRule(new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
            lPropDefCol.Add(propDef);

            propDef = new PropDef("FirstName", typeof(String), PropReadWriteRule.ReadWrite, "FirstName_field", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("DateOfBirth", typeof(DateTime), PropReadWriteRule.WriteOnce, null);
            lPropDefCol.Add(propDef);

            //Create concurrency control properties
            propDef = new PropDef("DateLastUpdated", typeof(DateTime), PropReadWriteRule.ReadWrite, DateTime.Now);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("UserLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("MachineLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("VersionNumber", typeof(int), PropReadWriteRule.ReadWrite, 1);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("PK2Prop1", typeof(string), PropReadWriteRule.ReadWrite, "PK2_Prop1", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("PK2Prop2", typeof(string), PropReadWriteRule.ReadWrite, "PK2_Prop2", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("PK3Prop", typeof(string), PropReadWriteRule.WriteNew, "PK3_Prop", null);
            lPropDefCol.Add(propDef);

            lPropDefCol.Add("ContactPersonID", typeof(Guid), PropReadWriteRule.WriteOnce, null);

            return(lPropDefCol);
        }
示例#6
0
        public void TestDirtyXml()
        {
            mProp = mBOPropCol["Prop2"];
            mProp.InitialiseProp("Prop2-Orig");
            mProp.Value = "Prop2-New";
            Assert.IsTrue(mProp.IsDirty);

            mProp = mBOPropCol["PropName"];
            mProp.InitialiseProp("Propn-Orig");
            mProp.Value = "PropName-new";
            Assert.IsTrue(mProp.IsDirty);

            mPropDef = new PropDef("Prop3", typeof(string), PropReadWriteRule.ReadOnly, null);
            mPropDef.AddPropRule(new PropRuleString(mPropDef.PropertyName, "Test", 1, 40, null));
            mBOPropCol.Add(mPropDef.CreateBOProp(false));
            mProp = mBOPropCol["Prop3"];
            mProp.InitialiseProp("Prop3-new");
            Assert.IsFalse(mProp.IsDirty);
            const string dirtyXml = "<Properties><Prop2><PreviousValue>Prop2-Orig</PreviousValue><NewValue>Prop2-New</NewValue></Prop2><PropName><PreviousValue>Propn-Orig</PreviousValue><NewValue>PropName-new</NewValue></PropName></Properties>";

            Assert.AreEqual(dirtyXml, mBOPropCol.DirtyXml);
        }
        protected static PropDefCol CreateBOPropDef()
        {
            PropDefCol lPropDefCol = new PropDefCol();
            PropDef propDef = new PropDef("Surname", typeof (String), PropReadWriteRule.ReadWrite, null);
            propDef.AddPropRule( new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
            lPropDefCol.Add(propDef);

            propDef = new PropDef("FirstName", typeof (String), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("DateOfBirth", typeof (DateTime), PropReadWriteRule.WriteOnce, null);
            lPropDefCol.Add(propDef);

            //Create concurrency control properties
            propDef = new PropDef("DateLastUpdated", typeof (DateTime), PropReadWriteRule.ReadWrite, DateTime.Now);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("UserLastUpdated", typeof (string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("MachineLastUpdated", typeof (string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("VersionNumber", typeof (int), PropReadWriteRule.ReadWrite, 1);
            lPropDefCol.Add(propDef);

            propDef = new PropDef(PK1_PROP1_NAME, typeof (string), PropReadWriteRule.ReadWrite, "PK1_Prop1", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef(PK1_PROP2_NAME, typeof (string), PropReadWriteRule.ReadWrite, "PK1_Prop2", null);
            lPropDefCol.Add(propDef);

            return lPropDefCol;
        }
示例#8
0
        private static PropDefCol CreateBOPropDef()
        {
            PropDefCol lPropDefCol = new PropDefCol();
            PropDef propDef =
                new PropDef("Surname", "System", "String", PropReadWriteRule.ReadWrite, "Surname_field", null, true, false);
            propDef.AddPropRule(new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
            lPropDefCol.Add(propDef);

            propDef = new PropDef("FirstName", typeof(String), PropReadWriteRule.ReadWrite, "FirstName_field", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("DateOfBirth", typeof (DateTime), PropReadWriteRule.WriteOnce, null);
            lPropDefCol.Add(propDef);

            //Create concurrency control properties
            propDef = new PropDef("DateLastUpdated", typeof(DateTime), PropReadWriteRule.ReadWrite, DateTime.Now);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("UserLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("MachineLastUpdated", typeof(string), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("VersionNumber", typeof(int), PropReadWriteRule.ReadWrite, 1);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("PK2Prop1", typeof(string), PropReadWriteRule.ReadWrite, "PK2_Prop1", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("PK2Prop2", typeof(string), PropReadWriteRule.ReadWrite, "PK2_Prop2", null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("PK3Prop", typeof (string), PropReadWriteRule.WriteNew, "PK3_Prop", null);
            lPropDefCol.Add(propDef);

            lPropDefCol.Add("ContactPersonID", typeof (Guid), PropReadWriteRule.WriteOnce, null);

            return lPropDefCol;
        }
示例#9
0
 public void TestPropBrokenRuleRestore()
 {
     //Test compulsory with no default set
     PropDef lPropDefWithRules = new PropDef("PropNameWithRules", typeof(string),
                                             PropReadWriteRule.ReadWrite, null);
     lPropDefWithRules.AddPropRule( new PropRuleString(lPropDefWithRules.PropertyName, "", 50, 51, null));
     IBOProp lBOProp = lPropDefWithRules.CreateBOProp(true);
     Assert.IsTrue(lBOProp.IsValid);
     try
     {
         lBOProp.Value = "New Value";
     }
     catch (InvalidPropertyValueException)
     {
         //do nothing
     }
     Assert.IsFalse(lBOProp.IsValid);
     lBOProp.RestorePropValue();
     Assert.IsTrue(lBOProp.IsValid);
 }
示例#10
0
 public void Test_RestoreValidPropToInvalidState()
 {
     //---------------Set up test pack-------------------
                 //Test compulsory with no default set
     PropDef lPropDefWithRules = new PropDef("PropNameWithRules", "System", "String",
                                             PropReadWriteRule.ReadWrite, null, null, true, false);
     lPropDefWithRules.AddPropRule(new PropRuleString(lPropDefWithRules.PropertyName, "", -1, -1, null));
     IBOProp lBOProp = lPropDefWithRules.CreateBOProp(true);
     //Do validate
     lBOProp.Validate(); 
     lBOProp.Value = "New Value";
     //---------------Assert Precondition----------------
     Assert.IsTrue(lBOProp.IsValid);
     Assert.IsFalse(lBOProp.InvalidReason.Length > 0);
     //---------------Execute Test ----------------------
     lBOProp.RestorePropValue();
     //---------------Test Result -----------------------
     Assert.IsFalse(lBOProp.IsValid);
     Assert.IsTrue(lBOProp.InvalidReason.Length > 0);
 }
示例#11
0
        public void Test_AddPropRule_Null()
        {
            //---------------Set up test pack-------------------
            IPropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, propDef.PropRules.Count);

            //---------------Execute Test ----------------------

            try
            {
                propDef.AddPropRule(null);
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (HabaneroApplicationException ex)
            {
                StringAssert.Contains("You cannot add a null property rule to a property def", ex.Message);
            }
        }
示例#12
0
        public void Test_IsValueValid_TwoPropRule_InValidValue_FirstRulePass_FirstRuleFail()
        {
            //---------------Set up test pack-------------------
            PropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);
            propDef.AddPropRule(new PropRuleString("StringRule", "Rule 1", 1, 3, ""));
            propDef.AddPropRule(new PropRuleString("StringRule", "Rule 2", 3, 10, ""));

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propDef.PropRules.Count);

            //---------------Execute Test ----------------------
            string errMsg = "";
            bool valid = propDef.IsValueValid("Long String", ref errMsg);

            //---------------Test Result -----------------------
            Assert.IsFalse(valid);
            StringAssert.Contains("'Long String' for property 'Prop Name' is not valid for the rule 'StringRule'", errMsg);
            StringAssert.Contains("Rule 1", errMsg);
        }
示例#13
0
        public void Test_IsValueValid_TwoPropRule_ValidValue()
        {
            //---------------Set up test pack-------------------
            PropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);
            propDef.AddPropRule(new PropRuleString("StringRule", "Rule 1", 1, 3, ""));
            propDef.AddPropRule(new PropRuleString("StringRule", "Rule 2", 3, 10, ""));

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propDef.PropRules.Count);

            //---------------Execute Test ----------------------
            string errMsg = "";
            bool valid = propDef.IsValueValid("ABC", ref errMsg);

            //---------------Test Result -----------------------
            Assert.IsTrue(valid);
            Assert.AreEqual("", errMsg);
        }
示例#14
0
        public void Test_AddTwoPropRules()
        {
            //---------------Set up test pack-------------------
            IPropDef propDef = new PropDef("PropName", typeof(string), PropReadWriteRule.ReadOnly, null);

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, propDef.PropRules.Count);

            //---------------Execute Test ----------------------
            PropRuleString rule = new PropRuleString("StringRule", "My Message", 1, 3, "");
            propDef.AddPropRule(rule);
            propDef.AddPropRule(new PropRuleString("StringRule", "My Message", 1, 3, ""));

            //---------------Test Result -----------------------
            Assert.AreEqual(2, propDef.PropRules.Count);
        }
        /// <summary>
        /// Will attempt to map a PropertyInfo to an IPropDef.
        /// If it cannot be mapped then will return null.
        /// </summary>
        /// <returns></returns>
        public IPropDef MapProperty()
        {
            if (MustMapProperty)
            {
                var propertyType = this.PropertyWrapper.UnderlyingPropertyType;

                string displayName = "";
                if (this.PropertyWrapper.HasDisplayNameAttribute)
                {
                    displayName = this.PropertyWrapper.GetAttribute<AutoMapDisplayNameAttribute>().DisplayName;
                }
                var propDef = new PropDef(this.PropertyWrapper.Name, propertyType, PropReadWriteRule.ReadWrite, null, null, false, false, int.MaxValue, displayName, "")
                                  {
                                      Compulsory = this.PropertyWrapper.HasCompulsoryAttribute
                                  };
                if (this.PropertyWrapper.HasDefaultAttribute)
                {
                    propDef.DefaultValueString =
                        this.PropertyWrapper.GetAttribute<AutoMapDefaultAttribute>().DefaultValue;
                }
                if (this.PropertyWrapper.HasReadWriteRuleAttribute)
                {
                    propDef.ReadWriteRule =
                        this.PropertyWrapper.GetAttribute<AutoMapReadWriteRuleAttribute>().ReadWriteRule;
                }
                if (this.PropertyWrapper.HasIntPropRuleAttribute)
                {
                    var intPropRule = CreateIntPropRule();
                    propDef.AddPropRule(intPropRule);
                }else if (this.PropertyWrapper.HasShortPropRuleAttribute)
                {
                    var shortPropRule = CreateShortPropRule();
                    propDef.AddPropRule(shortPropRule);
                } else if (this.PropertyWrapper.HasDateTimeRuleAttribute)
                {
                    var propRuleDate = CreateDateTimePropRule();
                    propDef.AddPropRule(propRuleDate);
                } else if (this.PropertyWrapper.HasDateTimeStringRuleAttribute)
                {
                    var propRuleDate = CreateDateTimeStringPropRule();
                    propDef.AddPropRule(propRuleDate);
                } 

                if (this.PropertyWrapper.HasStringLengthRuleAttribute)
                {
                    var stringPropRule = CreateStringLengthPropRule();
                    propDef.AddPropRule(stringPropRule);
                } else if (this.PropertyWrapper.HasStringPatternMatchRuleAttribute)
                {
                    var stringPropRule = CreatePatternMatchPropRule();
                    propDef.AddPropRule(stringPropRule);
                } 

                if (this.PropertyWrapper.HasKeepValuePrivateAttribute)
                {
                    propDef.KeepValuePrivate = true;
                }
                if (this.PropertyWrapper.HasAttribute<AutoMapFieldNameAttribute>())
                {
                    var autoMapFieldNameAttribute = this.PropertyWrapper.GetAttribute<AutoMapFieldNameAttribute>();
                    propDef.DatabaseFieldName = autoMapFieldNameAttribute.FieldName;
                }
                propDef.AutoIncrementing = this.PropertyWrapper.HasAutoIncrementingAttribute;
                return propDef;
            }
            return null;
        }
        /// <summary>
        /// Will attempt to map a PropertyInfo to an IPropDef.
        /// If it cannot be mapped then will return null.
        /// </summary>
        /// <returns></returns>
        public IPropDef MapProperty()
        {
            if (MustMapProperty)
            {
                var propertyType = this.PropertyWrapper.UnderlyingPropertyType;

                string displayName = "";
                if (this.PropertyWrapper.HasDisplayNameAttribute)
                {
                    displayName = this.PropertyWrapper.GetAttribute <AutoMapDisplayNameAttribute>().DisplayName;
                }
                var propDef = new PropDef(this.PropertyWrapper.Name, propertyType, PropReadWriteRule.ReadWrite, null, null, false, false, int.MaxValue, displayName, "")
                {
                    Compulsory = this.PropertyWrapper.HasCompulsoryAttribute
                };
                if (this.PropertyWrapper.HasDefaultAttribute)
                {
                    propDef.DefaultValueString =
                        this.PropertyWrapper.GetAttribute <AutoMapDefaultAttribute>().DefaultValue;
                }
                if (this.PropertyWrapper.HasReadWriteRuleAttribute)
                {
                    propDef.ReadWriteRule =
                        this.PropertyWrapper.GetAttribute <AutoMapReadWriteRuleAttribute>().ReadWriteRule;
                }
                if (this.PropertyWrapper.HasIntPropRuleAttribute)
                {
                    var intPropRule = CreateIntPropRule();
                    propDef.AddPropRule(intPropRule);
                }
                else if (this.PropertyWrapper.HasShortPropRuleAttribute)
                {
                    var shortPropRule = CreateShortPropRule();
                    propDef.AddPropRule(shortPropRule);
                }
                else if (this.PropertyWrapper.HasDateTimeRuleAttribute)
                {
                    var propRuleDate = CreateDateTimePropRule();
                    propDef.AddPropRule(propRuleDate);
                }
                else if (this.PropertyWrapper.HasDateTimeStringRuleAttribute)
                {
                    var propRuleDate = CreateDateTimeStringPropRule();
                    propDef.AddPropRule(propRuleDate);
                }

                if (this.PropertyWrapper.HasStringLengthRuleAttribute)
                {
                    var stringPropRule = CreateStringLengthPropRule();
                    propDef.AddPropRule(stringPropRule);
                }
                else if (this.PropertyWrapper.HasStringPatternMatchRuleAttribute)
                {
                    var stringPropRule = CreatePatternMatchPropRule();
                    propDef.AddPropRule(stringPropRule);
                }

                if (this.PropertyWrapper.HasKeepValuePrivateAttribute)
                {
                    propDef.KeepValuePrivate = true;
                }
                if (this.PropertyWrapper.HasAttribute <AutoMapFieldNameAttribute>())
                {
                    var autoMapFieldNameAttribute = this.PropertyWrapper.GetAttribute <AutoMapFieldNameAttribute>();
                    propDef.DatabaseFieldName = autoMapFieldNameAttribute.FieldName;
                }
                propDef.AutoIncrementing = this.PropertyWrapper.HasAutoIncrementingAttribute;
                return(propDef);
            }
            return(null);
        }
        protected static PropDefCol CreateBOPropDef()
        {
            PropDefCol lPropDefCol = new PropDefCol();
            PropDef propDef = new PropDef("Surname", typeof(String), PropReadWriteRule.ReadWrite, null);
            propDef.AddPropRule(new PropRuleString("ContactPerson-" + propDef.PropertyName, "", 2, 50, null));
            lPropDefCol.Add(propDef);

            propDef = new PropDef("FirstName", typeof(String), PropReadWriteRule.ReadWrite, null);
            lPropDefCol.Add(propDef);

            propDef = new PropDef("DateOfBirth", typeof(DateTime), PropReadWriteRule.WriteOnce, null);
            lPropDefCol.Add(propDef);

            return lPropDefCol;
        }
示例#18
0
        public void TestDirtyXml()
        {
            mProp = mBOPropCol["Prop2"];
            mProp.InitialiseProp("Prop2-Orig");
            mProp.Value = "Prop2-New";
            Assert.IsTrue(mProp.IsDirty);

            mProp = mBOPropCol["PropName"];
            mProp.InitialiseProp("Propn-Orig");
            mProp.Value = "PropName-new";
            Assert.IsTrue(mProp.IsDirty);

            mPropDef = new PropDef("Prop3", typeof(string), PropReadWriteRule.ReadOnly, null);
            mPropDef.AddPropRule( new PropRuleString(mPropDef.PropertyName, "Test", 1, 40, null));
            mBOPropCol.Add(mPropDef.CreateBOProp(false));
            mProp = mBOPropCol["Prop3"];
            mProp.InitialiseProp("Prop3-new");
            Assert.IsFalse(mProp.IsDirty);
            const string dirtyXml = "<Properties><Prop2><PreviousValue>Prop2-Orig</PreviousValue><NewValue>Prop2-New</NewValue></Prop2><PropName><PreviousValue>Propn-Orig</PreviousValue><NewValue>PropName-new</NewValue></PropName></Properties>";
            Assert.AreEqual(dirtyXml, mBOPropCol.DirtyXml);
        }