This Rule is used for the Common Scenario where the One properties Validity is based on another Properties Value. E.g. DisposalDate must be Greater Than AcquisitionDate In the above case the Rule will be on the Disposal Date. The other Prop will be the AcquisitionDate Prop and the ComparisonOperator Will be GreaterThan
Inheritance: IBusinessObjectRule
Esempio n. 1
0
        public void Test_CreateInterPropRule_WhenEqualsOperator_NameShouldUseEquals()
        {
            //---------------Set up test pack-------------------
            PropDefFake prop1 = new PropDefFake();
            PropDefFake prop2 = new PropDefFake();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            InterPropRule rule = new InterPropRule(prop1, ComparisonOperator.EqualTo, prop2);

            //---------------Test Result -----------------------
            Assert.IsNotNull(rule);
            Assert.AreEqual(prop1.PropertyName + " Is EqualTo " + prop2.PropertyName, rule.Name);
        }
Esempio n. 2
0
        public void Test_CreateInterPropRule()
        {
            //---------------Set up test pack-------------------
            PropDefFake prop1 = new PropDefFake();
            PropDefFake prop2 = new PropDefFake();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            InterPropRule rule = new InterPropRule(prop1, ComparisonOperator.GreaterThan, prop2);

            //---------------Test Result -----------------------
            Assert.IsNotNull(rule);
            Assert.AreEqual(ErrorLevel.Error, rule.ErrorLevel);
            Assert.AreEqual(prop1.PropertyName + " Is GreaterThan " + prop2.PropertyName, rule.Name);
        }
        public void Test_Construct_ShouldSetPropsAndOperator()
        {
            //---------------Set up test pack-------------------
            PropDefFake prop1 = new PropDefFake();
            PropDefFake prop2 = new PropDefFake();
            const ComparisonOperator comparisonOperator = ComparisonOperator.GreaterThan;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            InterPropRule<MyBO> rule = new InterPropRule<MyBO>(prop1, comparisonOperator, prop2);

            //---------------Test Result -----------------------
            Assert.AreSame(prop1, rule.LeftProp);
            Assert.AreSame(prop2, rule.RightProp);
            Assert.AreEqual(comparisonOperator, rule.ComparisonOp);
        }
Esempio n. 4
0
 public void Test_IsValid_WhenLeftPropNull_ShouldRetTrue()
 {
     //---------------Set up test pack-------------------
     PropDefFake propLeft = new PropDefFake();
     PropDefFake propRight = new PropDefFake();
     InterPropRule rule = new InterPropRule(propLeft, ComparisonOperator.GreaterThan, propRight);
     DateTime? prop1Value = null;
     DateTime? prop2Value = DateTime.Now;
     IBusinessObject bo = GetBOWithPropValueSet(propLeft, prop1Value, propRight, prop2Value);
     //---------------Assert Precondition----------------
     Assert.IsNull(bo.GetPropertyValue(propLeft.PropertyName));
     //---------------Execute Test ----------------------
     bool isValid = rule.IsValid(bo);
     //---------------Test Result -----------------------
     Assert.IsTrue(isValid);
 }
Esempio n. 5
0
        public void Test_IsValid_WhenGt_WhenNotGtEqual_ShouldBeFalse()
        {
            //---------------Set up test pack-------------------
            PropDefFake prop1 = new PropDefFake();
            PropDefFake prop2 = new PropDefFake();
            InterPropRule rule = new InterPropRule(prop1, ComparisonOperator.GreaterThan, prop2);
            DateTime prop1Value = DateTime.Now.AddDays(-1);
            DateTime prop2Value = DateTime.Now;
            IBusinessObject bo = GetBOWithPropValueSet(prop1, prop1Value, prop2, prop2Value);
            //---------------Assert Precondition----------------
            Assert.Less((DateTime)bo.GetPropertyValue(prop1.PropertyName), (DateTime)bo.GetPropertyValue(prop2.PropertyName));
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(bo);
            //---------------Test Result -----------------------
            Assert.IsFalse(isValid);
            string expectedMessage = string.Format("Property '{0}' with value '{1}'  should "
                                                   + "be GreaterThan property '{2}' with value '{3}'"
                                                   , prop1.PropertyName, prop1Value, prop2.PropertyName, prop2Value);

            Assert.AreEqual(expectedMessage, rule.Message);
        }
Esempio n. 6
0
 public void Test_IsValid_WhenGt_WhenEq_ShouldBeFalse()
 {
     //---------------Set up test pack-------------------
     PropDefFake prop1 = new PropDefFake();
     PropDefFake prop2 = new PropDefFake();
     InterPropRule rule = new InterPropRule(prop1, ComparisonOperator.GreaterThan, prop2);
     DateTime propValue = DateTime.Now;
     IBusinessObject bo = GetBOWithPropValueSet(prop1, propValue, prop2, propValue);
     //---------------Assert Precondition----------------
     Assert.AreEqual((DateTime)bo.GetPropertyValue(prop1.PropertyName), (DateTime)bo.GetPropertyValue(prop2.PropertyName));
     //---------------Execute Test ----------------------
     bool isValid = rule.IsValid(bo);
     //---------------Test Result -----------------------
     Assert.IsFalse(isValid);
 }
Esempio n. 7
0
 public void Test_IsValid_WhenLTPasses_ShouldBeTrue()
 {
     //---------------Set up test pack-------------------
     PropDefFake prop1 = new PropDefFake();
     PropDefFake prop2 = new PropDefFake();
     InterPropRule rule = new InterPropRule(prop1, ComparisonOperator.LessThan, prop2);
     IBusinessObject bo = GetBOWithPropValueSet(prop1, DateTime.Now.AddDays(-1), prop2, DateTime.Now);
     //---------------Assert Precondition----------------
     Assert.Less((DateTime)bo.GetPropertyValue(prop1.PropertyName), (DateTime)bo.GetPropertyValue(prop2.PropertyName));
     //---------------Execute Test ----------------------
     bool isValid = rule.IsValid(bo);
     //---------------Test Result -----------------------
     Assert.IsTrue(isValid);
 }
 public void Test_Create_WithExpressions_ShouldConstructWithPropDefs()
 {
     //---------------Set up test pack-------------------
     const string propNameLeft = "EconomicLife";
     const string propNameRight = "EngineeringLife";
     IClassDef classDef = ClassDef.ClassDefs[typeof (FakeBO)];
     IPropDef propDefLeft = classDef.PropDefcol[propNameLeft];
     IPropDef propDefRight = classDef.PropDefcol[propNameRight];
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     InterPropRule<FakeBO> rule = new InterPropRule<FakeBO>(bo => bo.EconomicLife, ComparisonOperator.EqualTo, bo => bo.EngineeringLife);
     //---------------Test Result -----------------------
     Assert.AreSame(propDefLeft, rule.LeftProp);
     Assert.AreSame(propDefRight, rule.RightProp);
 }/**/
 public void Test_Create_WithExpressions_ShouldConstruct()
 {
     //---------------Set up test pack-------------------
     const string propNameLeft = "EconomicLife";
     const string propNameRight = "EngineeringLife";
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     InterPropRule<FakeBO> rule = new InterPropRule<FakeBO>(bo => bo.EconomicLife, ComparisonOperator.EqualTo, bo => bo.EngineeringLife);
     //---------------Test Result -----------------------
     Assert.IsNotNull(rule);
     Assert.AreEqual(propNameLeft + " Is EqualTo " + propNameRight, rule.Name);
 }