Ejemplo n.º 1
0
        public void TestDecimalRule()
        {
            PropRuleDecimal rule = new PropRuleDecimal("num", "TestMessage", 5.32m, 10.11111m);

            string errorMessage = "";

            //Test less than min
            Assert.IsFalse(rule.IsPropValueValid("Propname", 5.31116m, ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
            //Test valid data
            Assert.IsTrue(rule.IsPropValueValid("Propname", 6, ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);
            //test greater than max
            Assert.IsFalse(rule.IsPropValueValid("Propname", 10.1111112m, ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);

            rule = new PropRuleDecimal("num", "TestMessage", 5.32m, 10.11111m);
            errorMessage = "";

            Assert.IsTrue(rule.IsPropValueValid("Propname", null, ref errorMessage));
            Assert.IsTrue(errorMessage.Length == 0);
            errorMessage = "";
            Assert.IsFalse(rule.IsPropValueValid("Propname", -53444.33222m, ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
        }
Ejemplo n.º 2
0
        public void TestDecimalRule()
        {
            PropRuleDecimal rule = new PropRuleDecimal("num", "TestMessage", 5.32m, 10.11111m);

            string errorMessage = "";

            //Test less than min
            Assert.IsFalse(rule.IsPropValueValid("Propname", 5.31116m, ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
            //Test valid data
            Assert.IsTrue(rule.IsPropValueValid("Propname", 6, ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);
            //test greater than max
            Assert.IsFalse(rule.IsPropValueValid("Propname", 10.1111112m, ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);

            rule         = new PropRuleDecimal("num", "TestMessage", 5.32m, 10.11111m);
            errorMessage = "";

            Assert.IsTrue(rule.IsPropValueValid("Propname", null, ref errorMessage));
            Assert.IsTrue(errorMessage.Length == 0);
            errorMessage = "";
            Assert.IsFalse(rule.IsPropValueValid("Propname", -53444.33222m, ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
        }
Ejemplo n.º 3
0
        private decimal GenerateValidValue(decimal?overridingMinValue, decimal?overridingMaxValue)
        {
            PropRuleDecimal propRule = base.GetPropRule <PropRuleDecimal>();
            decimal         minValue = GetMinValue(propRule, overridingMinValue);
            decimal         maxValue = GetMaxValue(propRule, overridingMaxValue);

            return(RandomValueGen.GetRandomDecimal(minValue, maxValue));
        }
        public void Test_GenerateValueGreaterThan_WhenDecimalAndRule_LtNull_ShouldRetValidValueUsingRules()
        {
            IPropDef def = new PropDefFake {
                PropertyType = typeof(decimal)
            };

            def.AddPropRule(CreatePropRuleDecimal(3M, decimal.MaxValue - 7));
            ValidValueGeneratorDecimal generator = new ValidValueGeneratorDecimal(def);

            Assert.AreSame(typeof(decimal), def.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleDecimal>().ToList());
            PropRuleDecimal propRule = def.PropRules.OfType <PropRuleDecimal>().First();

            Assert.AreEqual(3M, propRule.MinValue);
            Assert.AreEqual(decimal.MaxValue - 7, propRule.MaxValue);
            decimal value = (decimal)generator.GenerateValidValueGreaterThan(null);

            Assert.IsNotNull(value);
            Assert.GreaterOrEqual(value, 3M);
            Assert.LessOrEqual(value, decimal.MaxValue - 7);
        }
        public void Test_GenerateValue_WhenDecimapAndRule_ShouldRetValidValue()
        {
            IPropDef def = new PropDefFake {
                PropertyType = typeof(decimal)
            };

            def.AddPropRule(CreatePropRuleDecimal(3.01M, 7.0004M));
            ValidValueGenerator generator = new ValidValueGeneratorDecimal(def);

            Assert.AreSame(typeof(decimal), def.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleDecimal>().ToList());
            PropRuleDecimal propRule = def.PropRules.OfType <PropRuleDecimal>().First();

            Assert.AreEqual(3.01M, propRule.MinValue);
            Assert.AreEqual(7.0004M, propRule.MaxValue);
            decimal value = (decimal)generator.GenerateValidValue();

            Assert.IsNotNull(value);
            Assert.GreaterOrEqual(value, 3.01M);
            Assert.LessOrEqual(value, 7.0004M);
        }
Ejemplo n.º 6
0
        public override object GenerateValidValue()
        {
            PropRuleDecimal propRule = base.GetPropRule <PropRuleDecimal>();

            return((propRule == null) ? RandomValueGen.GetRandomDecimal() : RandomValueGen.GetRandomDecimal(propRule.MinValue, propRule.MaxValue));
        }