public void Test_GenerateValueLessThan_WhenIntAndRule_WhenRuleMoreRestrictive_ShouldRetValidValue() { IPropDef def = new PropDefFake { PropertyType = typeof(int) }; const int minValue = 3; const int maxValue = 5; const int lessThanValue = int.MaxValue - 77; def.AddPropRule(CreatePropRuleInt(minValue, maxValue)); ValidValueGeneratorInt generator = new ValidValueGeneratorInt(def); //---------------Assert Precondition---------------- Assert.AreSame(typeof(int), def.PropertyType); Assert.IsNotEmpty(def.PropRules.OfType <PropRuleInteger>().ToList()); PropRuleInteger propRule = def.PropRules.OfType <PropRuleInteger>().First(); Assert.AreEqual(minValue, propRule.MinValue); Assert.AreEqual(maxValue, propRule.MaxValue); //---------------Execute Test ---------------------- int value = (int)generator.GenerateValidValueLessThan(lessThanValue); //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.GreaterOrEqual(value, minValue); Assert.LessOrEqual(value, lessThanValue); Assert.LessOrEqual(value, maxValue); }
public void Test_GenerateValueLessThan_WhenIntAndNoRule_ShouldRetValidValue() { IPropDef def = new PropDefFake { PropertyType = typeof(int) }; ValidValueGeneratorInt generator = new ValidValueGeneratorInt(def); const int lessThanValue = int.MinValue + 10; //---------------Assert Precondition---------------- Assert.AreSame(typeof(int), def.PropertyType); Assert.IsEmpty(def.PropRules.OfType <PropRuleInteger>().ToList()); //---------------Execute Test ---------------------- int value = (int)generator.GenerateValidValueLessThan(lessThanValue); //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.GreaterOrEqual(value, int.MinValue); Assert.LessOrEqual(value, lessThanValue); }