public void TestPropRuleInteger_NullValues() { //---------------Execute Test ---------------------- IPropRule rule = _loader.LoadRule(typeof(int).Name, @"<rule name=""Test Rule"" message=""Test Message""> <add key=""min"" value=""""/> <add key=""max"" value="""" /></rule> "); //---------------Test Result ----------------------- Assert.AreEqual(Int32.MinValue, rule.Parameters["min"]); Assert.AreEqual(Int32.MaxValue, rule.Parameters["max"]); }
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"]); }
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 TestPropRuleDecimal_UsingComparableInterface_MaxValue_ActualValueGT() { XmlRuleLoader loader = new XmlRuleLoader(new DtdLoader(), GetDefClassFactory()); IPropRule rule = loader.LoadRule(typeof(Decimal).Name, @"<rule name=""TestDecimal"" > <add key=""min"" value=""12.22"" /> <add key=""max"" value=""15.51"" /> </rule>"); //-----------------Assert Preconditions --------------------------- Assert.AreEqual(12.22D, ((IPropRuleComparable <decimal>)rule).MinValue); Assert.AreEqual(15.51D, ((IPropRuleComparable <decimal>)rule).MaxValue); //---------------Execute ------------------------------------------ string errorMessage = ""; bool isValid = rule.IsPropValueValid("Propname", new Decimal(15.56), ref errorMessage); //--------------Verify Result ------------------------------------- Assert.IsFalse(isValid); Assert.IsFalse(string.IsNullOrEmpty(errorMessage)); }
public void TestPropRuleSingle_MaxValue_ActualValueLT() { XmlRuleLoader loader = new XmlRuleLoader(new DtdLoader(), GetDefClassFactory()); IPropRule rule = loader.LoadRule(typeof(Single).Name, @"<rule name=""TestSingle"" > <add key=""min"" value=""12.22"" /> <add key=""max"" value=""15.51"" /> </rule> "); //-----------------Assert Preconditions --------------------------- Assert.AreEqual(12.22f, ((PropRuleSingle)rule).MinValue); Assert.AreEqual(15.51f, ((PropRuleSingle)rule).MaxValue); //---------------Execute ------------------------------------------ string errorMessage = ""; bool isValid = rule.IsPropValueValid("Propname", 13.1f, ref errorMessage); //--------------Verify Result ------------------------------------- Assert.IsTrue(isValid); Assert.IsTrue(string.IsNullOrEmpty(errorMessage)); }
public void TestPropRuleDate_MaxValue_Today() { XmlRuleLoader loader = new XmlRuleLoader(new DtdLoader(), GetDefClassFactory()); IPropRule rule = loader.LoadRule(typeof(DateTime).Name, @"<rule name=""TestDate"" > <add key=""min"" value=""01 Feb 2004"" /> <add key=""max"" value=""Today"" /> </rule> "); //-----------------Assert Preconditions --------------------------- Assert.AreEqual(new DateTime(2004, 02, 01), ((PropRuleDate)rule).MinValue); Assert.AreEqual(DateTime.Today.AddDays(1).AddMilliseconds(-1), ((PropRuleDate)rule).MaxValue); //---------------Execute ------------------------------------------ string errorMessage = ""; bool isValid = rule.IsPropValueValid("Propname", DateTime.Today.AddDays(-1), ref errorMessage); //--------------Verify Result ------------------------------------- Assert.IsTrue(isValid); Assert.IsTrue(string.IsNullOrEmpty(errorMessage)); }
public void TestNoKeyAttribute() { try { _loader.LoadRule(typeof(int).Name, @" <rule name=""TestRule"" message=""Test Message""> <add value=""1"" /> </rule>"); Assert.Fail("Expected to throw an InvalidXmlDefinitionException"); } //---------------Test Result ----------------------- catch (InvalidXmlDefinitionException ex) { StringAssert.Contains("An 'add' attribute in the class definitions was missing the required 'key' attribute, which specifies the name of the rule to check", ex.Message); } }