Exemplo n.º 1
0
        public void TestDateRule()
        {
            //	PropDef lPropDef = new PropDef("Surname", typeof(string),PropReadWriteRule.ReadWrite);
            PropRuleDate rule =
                new PropRuleDate("BirthDate", "Test", new DateTime(1900, 01, 01), new DateTime(2010, 12, 31));

            string errorMessage = "";

            //Test less than max length
            Assert.IsFalse(rule.IsPropValueValid("Propname", new DateTime(1891, 01, 14), ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
            //Test valid data
            Assert.IsTrue(rule.IsPropValueValid("Propname", new DateTime(1991, 01, 14), ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);
            //test greater than max length
            Assert.IsFalse(rule.IsPropValueValid("Propname", new DateTime(2091, 01, 14), ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);


            rule = new PropRuleDate("BirthDate", "Test");
            errorMessage = "";

            Assert.IsTrue(rule.IsPropValueValid("Propname", null, ref errorMessage));
            Assert.IsTrue(errorMessage.Length == 0);
            errorMessage = "";

            //Test valid data
            Assert.IsTrue(rule.IsPropValueValid("Propname", new DateTime(1991, 01, 14), ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);

            //Test valid data
            Assert.IsFalse(rule.IsPropValueValid("Propname","should be false", ref errorMessage),"Should get data type mismatch test");
            Assert.IsTrue(errorMessage.Length > 0);
            StringAssert.Contains("It is not a type of DateTime", errorMessage);
        }
Exemplo n.º 2
0
        public void TestDateRule()
        {
            //	PropDef lPropDef = new PropDef("Surname", typeof(string),PropReadWriteRule.ReadWrite);
            PropRuleDate rule =
                new PropRuleDate("BirthDate", "Test", new DateTime(1900, 01, 01), new DateTime(2010, 12, 31));

            string errorMessage = "";

            //Test less than max length
            Assert.IsFalse(rule.IsPropValueValid("Propname", new DateTime(1891, 01, 14), ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
            //Test valid data
            Assert.IsTrue(rule.IsPropValueValid("Propname", new DateTime(1991, 01, 14), ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);
            //test greater than max length
            Assert.IsFalse(rule.IsPropValueValid("Propname", new DateTime(2091, 01, 14), ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);


            rule         = new PropRuleDate("BirthDate", "Test");
            errorMessage = "";

            Assert.IsTrue(rule.IsPropValueValid("Propname", null, ref errorMessage));
            Assert.IsTrue(errorMessage.Length == 0);
            errorMessage = "";

            //Test valid data
            Assert.IsTrue(rule.IsPropValueValid("Propname", new DateTime(1991, 01, 14), ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);

            //Test valid data
            Assert.IsFalse(rule.IsPropValueValid("Propname", "should be false", ref errorMessage), "Should get data type mismatch test");
            Assert.IsTrue(errorMessage.Length > 0);
            StringAssert.Contains("It is not a type of DateTime", errorMessage);
        }
Exemplo n.º 3
0
        private DateTime GenerateValidValue(DateTime?overridingMinValue, DateTime?overridingMaxValue)
        {
            PropRuleDate propRule    = base.GetPropRule <PropRuleDate>();
            DateTime     intMinValue = GetMinValue(propRule, overridingMinValue);
            DateTime     intMaxValue = GetMaxValue(propRule, overridingMaxValue);

            return(RandomValueGen.GetRandomDate(intMinValue, intMaxValue));
        }
Exemplo n.º 4
0
        public void Test_WhenMaxBlank_ShouldUseDateTimeMaxValue()
        {
            //---------------Set up test pack-------------------
            //---------------Execute Test ----------------------
            PropRuleDate rule = new PropRuleDate("MyRule", "MyMessage");

            //---------------Test Result -----------------------
            Assert.AreEqual(DateTime.MaxValue, rule.MaxValue);
        }
        private static IPropRule GetPropRuleDate(string minDate, string maxDate)
        {
            var propRuleDate = new PropRuleDate("", "")
            {
                Parameters =
                    new Dictionary <string, object> {
                    { "min", minDate }, { "max", maxDate }
                }
            };

            return(propRuleDate);
        }
        private static PropRuleDate GetPropRuleDate()
        {
            var propRuleDate = new PropRuleDate("", "")
            {
                Parameters =
                    new Dictionary <string, object> {
                    { "min", "Today" }, { "max", "Tomorrow" }
                }
            };

            return(propRuleDate);
        }
        public void TestPropRuleDate_BlankValues()
        {
            //---------------Execute Test ----------------------
            PropRuleDate rule = (PropRuleDate)_loader.LoadRule(typeof(DateTime).Name,
                                                               @"<rule name=""TestDate""  >
                            <add key=""min"" value="""" />
                            <add key=""max"" value="""" />
                        </rule>                          
");

            //---------------Test Result -----------------------
            Assert.AreEqual(DateTime.MinValue, rule.MinValue);
            Assert.AreEqual(DateTime.MaxValue, rule.MaxValue);
        }
Exemplo n.º 8
0
        public void Test_MaxValue_WhenDateTimeMaxValueLess1Minute_ShouldNotRaiseError()
        {
            //---------------Set up test pack-------------------
            PropRuleDate rule        = new PropRuleDate("MyRule", "MyMessage");
            var          maxDateTime = DateTime.MaxValue.AddMilliseconds(-1);

            rule.Parameters["max"] = maxDateTime;
            //---------------Assert Precondition----------------
            Assert.AreEqual(maxDateTime, rule.Parameters["max"]);
            //---------------Execute Test ----------------------
            var actualMaxValue = rule.MaxValue;

            //---------------Test Result -----------------------
            Assert.AreEqual(maxDateTime, actualMaxValue);
        }
Exemplo n.º 9
0
        public void Test_PropRuledateMax_ViaInterface()
        {
            //---------------Set up test pack-------------------

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

            //---------------Execute Test ----------------------
            var minValue = new DateTime(1900, 01, 01);
            var maxValue = new DateTime(2010, 12, 31);
            IPropRuleComparable <DateTime> rule =
                new PropRuleDate("BirthDate", "Test", minValue, maxValue);

            //---------------Test Result -----------------------
            Assert.AreEqual(minValue, rule.MinValue);
            Assert.AreEqual(maxValue.AddDays(1).AddMilliseconds(-1), rule.MaxValue);
        }
Exemplo n.º 10
0
        public void Test_LoadRule_WhenMaxYesterday_ShouldUseStringMaxValueExpression()
        {
            //---------------Set up test pack-------------------
            XmlRuleLoader loader = new XmlRuleLoader(new DtdLoader(), GetDefClassFactory());

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

            //---------------Execute Test ----------------------
            PropRuleDate rule = (PropRuleDate)loader.LoadRule(typeof(DateTime).Name,
                                                              @"<rule name=""TestDate""  >
                            <add key=""min"" value=""yesterday"" />
                            <add key=""max"" value=""yesterday"" />
                        </rule>                          
                ");

            //---------------Test Result -----------------------
            Assert.AreEqual("yesterday", rule.Parameters["max"]);
            Assert.AreEqual("yesterday", rule.Parameters["min"]);
        }
Exemplo n.º 11
0
        public void Test_MaxAndMinValue_WhenTomorrow_ShouldRetTomorrow()
        {
            //---------------Set up test pack-------------------
            XmlRuleLoader loader = new XmlRuleLoader(new DtdLoader(), GetDefClassFactory());
            PropRuleDate  rule   = (PropRuleDate)loader.LoadRule(typeof(DateTime).Name,
                                                                 @"<rule name=""TestDate""  >
                            <add key=""min"" value=""tomorrow"" />
                            <add key=""max"" value=""tomorrow"" />
                        </rule>                          
                ");
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DateTime maxDateTime = rule.MaxValue;
            DateTime minDateTime = rule.MinValue;

            //---------------Test Result -----------------------
            Assert.AreEqual(DateTimeToday.Value.AddDays(2).AddMilliseconds(-1), maxDateTime);
            Assert.AreEqual(DateTimeToday.Value.AddDays(1), minDateTime);
        }
        public void Test_GenerateValue_WhenDateTimeAndRule_ShouldRetValidValue()
        {
            IPropDef def = new PropDefFake {
                PropertyType = typeof(DateTime)
            };
            var min = RandomValueGen.GetAbsoluteMin <DateTime>().AddDays(5555.0);
            var max = RandomValueGen.GetAbsoluteMin <DateTime>().AddDays(5565.0);

            def.AddPropRule(CreatePropRuleDate(min, max));
            ValidValueGenerator generator = new ValidValueGeneratorDate(def);

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

            Assert.AreEqual(min, propRule.MinValue);
            Assert.AreEqual(max.AddDays(1.0).AddMilliseconds(-1.0), propRule.MaxValue);
            var value = (DateTime)generator.GenerateValidValue();

            Assert.IsNotNull(value);
            Assert.GreaterOrEqual(value, min);
            Assert.LessOrEqual(value, max);
        }
Exemplo n.º 13
0
        public void Test_PropRuledateMax_ViaInterface()
        {
            //---------------Set up test pack-------------------
            
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var minValue = new DateTime(1900, 01, 01);
            var maxValue = new DateTime(2010, 12, 31);
            IPropRuleComparable<DateTime> rule =
               new PropRuleDate("BirthDate", "Test", minValue, maxValue);
            //---------------Test Result -----------------------
            Assert.AreEqual(minValue, rule.MinValue);
            Assert.AreEqual(maxValue.AddDays(1).AddMilliseconds(-1), rule.MaxValue);
        }
Exemplo n.º 14
0
 public void Test_MaxValue_WhenDateTimeMaxValueLess1Minute_ShouldNotRaiseError()
 {
     //---------------Set up test pack-------------------
     PropRuleDate rule = new PropRuleDate("MyRule", "MyMessage");
     var maxDateTime = DateTime.MaxValue.AddMilliseconds(-1);
     rule.Parameters["max"] = maxDateTime;
     //---------------Assert Precondition----------------
     Assert.AreEqual(maxDateTime, rule.Parameters["max"]);
     //---------------Execute Test ----------------------
     var actualMaxValue = rule.MaxValue;
     //---------------Test Result -----------------------
     Assert.AreEqual(maxDateTime, actualMaxValue);
 }
Exemplo n.º 15
0
 public void Test_WhenMaxBlank_ShouldUseDateTimeMaxValue()
 {
     //---------------Set up test pack-------------------
     //---------------Execute Test ----------------------
     PropRuleDate rule = new PropRuleDate("MyRule", "MyMessage");
     //---------------Test Result -----------------------
     Assert.AreEqual(DateTime.MaxValue, rule.MaxValue);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Generates a valid value taking into account only the <see cref="IPropRule"/>s. I.e. any <see cref="InterPropRule"/>s
        /// will not be taken into account. The <see cref="IValidValueGeneratorNumeric"/>'s methods are used
        /// by the BOTestFactory to create valid values taking into account InterPropRules
        /// </summary>
        /// <returns></returns>
        public override object GenerateValidValue()
        {
            PropRuleDate propRule = base.GetPropRule <PropRuleDate>();

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