public void Test_GenerateValueGreaterThan_WhenShortAndRule_LtNull_ShouldRetValidValueUsingRules() { IPropDef def = new PropDefFake { PropertyType = typeof(short) }; const short minValue = 3; const short maxValue = 20; def.AddPropRule(CreatePropRuleShort(minValue, maxValue)); var generator = CreateValidValueGenerator(def); //---------------Assert Precondition---------------- Assert.AreSame(typeof(short), def.PropertyType); Assert.IsNotEmpty(def.PropRules.OfType <PropRuleShort>().ToList()); PropRuleShort propRule = def.PropRules.OfType <PropRuleShort>().First(); Assert.AreEqual(minValue, propRule.MinValue); Assert.AreEqual(maxValue, propRule.MaxValue); //---------------Execute Test ---------------------- var value = (short)generator.GenerateValidValueGreaterThan(null); //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.GreaterOrEqual(value, minValue); Assert.LessOrEqual(value, maxValue); }
public void Test_WithNullValue_ShouldReturnEmptyErrorMessage() { var rule = new PropRuleShort("num", "TestMessage", 5, 10); var errorMessage = ""; Assert.IsTrue(rule.IsPropValueValid("Propname", null, ref errorMessage)); Assert.IsTrue(errorMessage.Length == 0); }
public void Test_WithValueGTMax_ShouldReturnErrorMessage() { var rule = new PropRuleShort("num", "TestMessage", 5, 10); var errorMessage = ""; Assert.IsFalse(rule.IsPropValueValid("Propname", 12, ref errorMessage)); Assert.IsTrue(errorMessage.Length > 0); }
public void Test_WithNegativeNumber_ShouldReturnErrorMessage() { string errorMessage = ""; var rule = new PropRuleShort("num", "TestMessage", 5, 10); Assert.IsFalse(rule.IsPropValueValid("Propname", -5, ref errorMessage)); Assert.IsTrue(errorMessage.Length > 0); }
public void Test_ValueLTMin_ShouldReturnErrorMessage() { var rule = new PropRuleShort("num", "TestMessage", 5, 10); var errorMessage = ""; //Test less than min Assert.IsFalse(rule.IsPropValueValid("Propname", 1, ref errorMessage)); Assert.IsTrue(errorMessage.Length > 0); }
public void ConstructWithoutMinOrMax_ShouldUseShortMinAndMax() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IPropRuleComparable <short> rule = new PropRuleShort("num", "TestMessage"); //---------------Test Result ----------------------- Assert.AreEqual(short.MinValue, rule.MinValue); Assert.AreEqual(short.MaxValue, rule.MaxValue); }
public void Test_MaxAndMinValueAreSetOnIComparableInterface() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IPropRuleComparable <short> rule = new PropRuleShort("num", "TestMessage", 5, 10); //---------------Test Result ----------------------- Assert.AreEqual(5, rule.MinValue); Assert.AreEqual(10, rule.MaxValue); }
public void IsPropValueValid_GivenValueOutsideShortRange_ShouldReturnFalse() { //---------------Set up test pack------------------- var rule = new PropRuleShort("num", ""); var errorMessage = ""; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var valid = rule.IsPropValueValid("num", int.MaxValue, ref errorMessage); //---------------Test Result ----------------------- Assert.IsFalse(valid); }
public void ConstructWithoutMinOrMax_ShouldUseShortMinAndMax() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IPropRuleComparable<short> rule = new PropRuleShort("num", "TestMessage"); //---------------Test Result ----------------------- Assert.AreEqual(short.MinValue, rule.MinValue); Assert.AreEqual(short.MaxValue, rule.MaxValue); }
public void Test_MaxAndMinValueAreSetOnIComparableInterface() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IPropRuleComparable<short> rule = new PropRuleShort("num", "TestMessage", 5, 10); //---------------Test Result ----------------------- Assert.AreEqual(5, rule.MinValue); Assert.AreEqual(10, rule.MaxValue); }