public void ShouldHaveRule_WithMinAndMax_WhenMaxNotMatch_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            IPropDef  propDef        = new PropDefFake();
            const int actualMaxInt   = 22;
            const int expectedMaxInt = 25;
            const int minInt         = 1;

            propDef.AddPropRule(GetPropRuleInt(minInt, actualMaxInt));
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            var propRule = propDef.PropRules[0] as IPropRuleComparable <int>;

            Assert.IsNotNull(propRule);
            Assert.AreEqual(actualMaxInt, propRule.MaxValue);
            Assert.AreEqual(minInt, propRule.MinValue);
            //---------------Execute Test ----------------------
            try
            {
                tester.ShouldHaveRule <PropRuleInteger, int>(minInt, expectedMaxInt);
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                var expected = string.Format("The Property '{0}' for class '{1}'",
                                             propDef.PropertyName, propDef.ClassName);
                StringAssert.Contains(expected, ex.Message);
                StringAssert.Contains("MaxValue Should Be '" + expectedMaxInt, ex.Message);
            }
        }
        public void Test_ShouldHavePropRuleDate_WhenSpecifyMinAndMaxString_WhenMaxDoesNotMatch_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            IPropDef propDef = new PropDefFake();
            var      minDate = "";
            var      maxDate = "Tomorrow";

            propDef.AddPropRule(GetPropRuleDate(minDate, maxDate));
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            Assert.IsInstanceOf <PropRuleDate>(propDef.PropRules[0]);
            //---------------Execute Test ----------------------
            try
            {
                tester.ShouldHaveRuleDate(minDate, "Today");
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                var expected = string.Format("The Property '{0}' for class '{1}'",
                                             propDef.PropertyName, propDef.ClassName);
                StringAssert.Contains(expected, ex.Message);
                StringAssert.Contains("MaxValue Should Be ", ex.Message);
            }
        }
        public void Test_ShouldHavPropRuleDate_WhenNotHas_ShouldAssertFalse()
        {
            //---------------Set up test pack-------------------
            IPropDef propDef = new PropDefFake();

            propDef.AddPropRule(MockRepository.GenerateMock <IPropRule>());
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            Assert.IsNotInstanceOf <PropRuleDate>(propDef.PropRules[0]);
            //---------------Execute Test ----------------------
            try
            {
                tester.ShouldHaveRule <PropRuleDate>();
                Assert.Fail("Expected to throw an AssertionException");
            }
            //---------------Test Result -----------------------
            catch (AssertionException ex)
            {
                var expected = string.Format("The Property '{0}' for class '{1}' should have a rule of type ",
                                             propDef.PropertyName, propDef.ClassName);
                StringAssert.Contains(expected, ex.Message);
            }
        }
Example #4
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);
        }
        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);
        }
        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);
        }
Example #7
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_ShouldHaveRule_WhenHas_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            var propDef = new PropDefFake();

            propDef.AddPropRule(MockRepository.GenerateMock <IPropRule>());
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            //---------------Execute Test ----------------------
            tester.ShouldHaveRule();
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
Example #9
0
        public void Test_Add_ShouldSetPropDefsClassDef()
        {
            //---------------Set up test pack-------------------
            PropDef    propDef          = new PropDefFake();
            PropDefCol col              = new PropDefCol();
            var        expectedClassDef = MockRepository.GenerateStub <IClassDef>();

            col.ClassDef = expectedClassDef;
            //---------------Assert Preconditions---------------
            Assert.IsNull(propDef.ClassDef);
            //---------------Execute Test ----------------------
            col.Add(propDef);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedClassDef, propDef.ClassDef);
        }
        public void Test_ShouldHavePropRuleDate_WhenHas_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            var propDef = new PropDefFake();

            propDef.AddPropRule(GetPropRuleDate());
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            Assert.IsInstanceOf <PropRuleDate>(propDef.PropRules[0]);
            //---------------Execute Test ----------------------
            tester.ShouldHaveRule <PropRuleDate>();
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
        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);
        }
Example #12
0
        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 rule = new InterPropRule(prop1, comparisonOperator, prop2);

            //---------------Test Result -----------------------
            Assert.AreSame(prop1, rule.LeftProp);
            Assert.AreSame(prop2, rule.RightProp);
            Assert.AreEqual(comparisonOperator, rule.ComparisonOp);
        }
Example #13
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);
        }
Example #14
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);
        }
Example #15
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);
        }
        public void Test_ShouldHavePropRuleDate_WhenSpecifyMinAndMaxDate_WhenRuleMatches_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            var propDef = new PropDefFake();
            var minDate = DateTime.Today;
            var maxDate = DateTime.Today.AddDays(3);

            propDef.AddPropRule(GetPropRuleDate(minDate, maxDate));
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            Assert.IsInstanceOf <PropRuleDate>(propDef.PropRules[0]);
            //---------------Execute Test ----------------------

            var expectedMaxDate = maxDate.AddDays(1).AddMilliseconds(-1);//Rule automatically moves it to the last millisecond of the Day.

            tester.ShouldHaveRule <PropRuleDate, DateTime>(minDate, expectedMaxDate);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
        public void Test_ShouldHavePropRuleDate_WhenSpecifyMinAndMaxString_WhenRuleMatches_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            var propDef = new PropDefFake();
            var minDate = "Today";
            var maxDate = "Tomorrow";

            propDef.AddPropRule(GetPropRuleDate(minDate, maxDate));
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            Assert.IsInstanceOf <PropRuleDate>(propDef.PropRules[0]);
            //---------------Execute Test ----------------------

            var expectedMaxDate = maxDate;

            tester.ShouldHaveRuleDate(minDate, expectedMaxDate);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
        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");
        }
Example #19
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);
        }
        public void ShouldHaveRule_WithMinandMax_WhenHas_WhenMinAndMaxMatchRule_ShouldAssertTrue()
        {
            //---------------Set up test pack-------------------
            IPropDef  propDef = new PropDefFake();
            const int minInt  = 22;
            const int maxInt  = 999;

            propDef.AddPropRule(GetPropRuleInt(minInt, maxInt));
            var tester = new PropDefTester(propDef);

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propDef.PropRules.Count);
            Assert.IsInstanceOf <PropRuleInteger>(propDef.PropRules[0]);
            var propRule = propDef.PropRules[0] as IPropRuleComparable <int>;

            Assert.IsNotNull(propRule);
            Assert.AreEqual(minInt, propRule.MinValue);
            Assert.AreEqual(maxInt, propRule.MaxValue);
            //---------------Execute Test ----------------------
            tester.ShouldHaveRule <PropRuleInteger, int>(minInt, maxInt);
            //---------------Test Result -----------------------
            Assert.IsTrue(true, "If it has got here then passed");
        }
        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);
        }
Example #22
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);
 }
Example #23
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);
        }
Example #24
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);
 }
Example #25
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);
 }