Example #1
0
        public void Test_GenerateValue_WhenIntAndRule_ShouldRetValidValue()
        {
            //---------------Set up test pack-------------------

            IPropDef def = new PropDefFake {
                PropertyType = typeof(long)
            };

            def.AddPropRule(CreatePropRuleLong(3, 7));
            ValidValueGenerator generator = new ValidValueGeneratorLong(def);

            //---------------Assert Precondition----------------
            Assert.AreSame(typeof(long), def.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleLong>().ToList());
            PropRuleLong propRule = def.PropRules.OfType <PropRuleLong>().First();

            Assert.AreEqual(3, propRule.MinValue);
            Assert.AreEqual(7, propRule.MaxValue);
            //---------------Execute Test ----------------------
            var value = (long)generator.GenerateValidValue();

            //---------------Test Result -----------------------
            Assert.IsNotNull(value);
            Assert.GreaterOrEqual(value, 3);
            Assert.LessOrEqual(value, 7);
        }
Example #2
0
        public void Test_GenerateValueLessThan_WhenIntAndRule_WhenRuleMoreRestrictive_ShouldRetValidValue()
        {
            IPropDef def = new PropDefFake {
                PropertyType = typeof(long)
            };
            const int minValue      = 3;
            const int maxValue      = 5;
            const int lessThanValue = int.MaxValue - 77;

            def.AddPropRule(CreatePropRuleLong(minValue, maxValue));
            ValidValueGeneratorLong generator = new ValidValueGeneratorLong(def);

            //---------------Assert Precondition----------------
            Assert.AreSame(typeof(long), def.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleLong>().ToList());
            PropRuleLong propRule = def.PropRules.OfType <PropRuleLong>().First();

            Assert.AreEqual(minValue, propRule.MinValue);
            Assert.AreEqual(maxValue, propRule.MaxValue);
            //---------------Execute Test ----------------------
            long value = (long)generator.GenerateValidValueLessThan(lessThanValue);

            //---------------Test Result -----------------------
            Assert.IsNotNull(value);
            Assert.GreaterOrEqual(value, minValue);
            Assert.LessOrEqual(value, lessThanValue);
            Assert.LessOrEqual(value, maxValue);
        }
        private long GenerateValidValue(long?overridingMinValue, long?overridingMaxValue)
        {
            PropRuleLong propRule = base.GetPropRule <PropRuleLong>();
            long         minValue = GetMinValue(propRule, overridingMinValue);
            long         maxValue = GetMaxValue(propRule, overridingMaxValue);

            return(RandomValueGen.GetRandomLong(minValue, maxValue));
        }
Example #4
0
        public void Test_IsPropValueValid_ShouldBeTrue_WhenValueIsEqualToMax()
        {
            //---------------Set up test pack-------------------
            PropRuleLong rule = new PropRuleLong("num", "TestMessage", 10, 200);
            string errorMessage = "";
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool valid = rule.IsPropValueValid("Propname", 200, ref errorMessage);
            //---------------Test Result -----------------------
            Assert.IsTrue(valid);
            Assert.IsFalse(errorMessage.Length > 0);
        }
Example #5
0
        public void Test_IsPropValueValid_ShouldBeFalse_WhenValueIsGreaterThanMax()
        {
            //---------------Set up test pack-------------------
            PropRuleLong rule         = new PropRuleLong("num", "TestMessage", 10, 200);
            string       errorMessage = "";
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool valid = rule.IsPropValueValid("Propname", 201, ref errorMessage);

            //---------------Test Result -----------------------
            Assert.IsFalse(valid);
            Assert.IsTrue(errorMessage.Length > 0);
        }
Example #6
0
        public void Test_PropRuledateMax_ViaInterface()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            const Int64 minValue = Int64.MinValue;
            const Int64 maxValue = Int64.MaxValue;
            IPropRuleComparable <System.Int64> rule =
                new PropRuleLong("fdsafasd", "Test", minValue, maxValue);

            //---------------Test Result -----------------------
            Assert.AreEqual(minValue, rule.MinValue);
            Assert.AreEqual(maxValue, rule.MaxValue);
        }
Example #7
0
        public void IsPropValueValid_ShouldPassForNumberGreaterThanMaxInt()
        {
            //---------------Set up test pack-------------------
            var rule         = new PropRuleLong("num", "TestMessage", 0, long.MaxValue);
            var errorMessage = "";
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            long value = int.MaxValue;

            value += 1;
            var valid = rule.IsPropValueValid("Propname", value, ref errorMessage);

            //---------------Test Result -----------------------
            Assert.IsTrue(valid);
            Assert.IsTrue(errorMessage.Length == 0);
        }
Example #8
0
        public void Test_PropRuledateMax_ViaInterface()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            const Int64 minValue = Int64.MinValue;
            const Int64 maxValue = Int64.MaxValue;
            IPropRuleComparable<System.Int64> rule =
                new PropRuleLong("fdsafasd", "Test", minValue, maxValue);
            //---------------Test Result -----------------------
            Assert.AreEqual(minValue, rule.MinValue);
            Assert.AreEqual(maxValue, rule.MaxValue);
        }
Example #9
0
        public void IsPropValueValid_ShouldPassForNumberGreaterThanMaxInt()
        {
            //---------------Set up test pack-------------------
            var rule = new PropRuleLong("num", "TestMessage", 0, long.MaxValue);
            var errorMessage = "";
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            long value = int.MaxValue;
            value += 1;
            var valid = rule.IsPropValueValid("Propname", value, ref errorMessage);
            //---------------Test Result -----------------------
            Assert.IsTrue(valid);
            Assert.IsTrue(errorMessage.Length == 0);
        }