public void Test_GenerateValue_WhenInt_ShouldRetInt() { IPropDef def = new PropDefFake { PropertyType = typeof(int) }; ValidValueGenerator valueGenerator = new ValidValueGeneratorInt(def); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- object value = valueGenerator.GenerateValidValue(); //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.IsInstanceOf(typeof(int), value); Assert.AreNotEqual(valueGenerator.GenerateValidValue(), value); }
public void Test_GenerateValueGreaterThan_WhenIntAndNoRule_ShouldRetValidValue() { IPropDef def = new PropDefFake { PropertyType = typeof(int) }; ValidValueGeneratorInt generator = new ValidValueGeneratorInt(def); //---------------Assert Precondition---------------- Assert.AreSame(typeof(int), def.PropertyType); Assert.IsEmpty(def.PropRules.OfType<PropRuleInteger>().ToList()); //---------------Execute Test ---------------------- int value = (int)generator.GenerateValidValueGreaterThan(int.MaxValue - 5); //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.GreaterOrEqual(value, int.MaxValue - 5); }
public void Test_GenerateValue_WhenIntAndRule_ShouldRetValidValue() { //---------------Set up test pack------------------- IPropDef def = new PropDefFake { PropertyType = typeof(int) }; def.AddPropRule(CreatePropRuleInt(3, 7)); ValidValueGenerator 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(3, propRule.MinValue); Assert.AreEqual(7, propRule.MaxValue); int value = (int)generator.GenerateValidValue(); //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.GreaterOrEqual(value, 3); Assert.LessOrEqual(value, 7); }
public void Test_GenerateValueGreaterThan_WhenIntAndRule_LtNull_ShouldRetValidValueUsingRules() { IPropDef def = new PropDefFake { PropertyType = typeof(int) }; const int minValue = 3; const int maxValue = 20; 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.GenerateValidValueGreaterThan(null); //---------------Test Result ----------------------- Assert.IsNotNull(value); Assert.GreaterOrEqual(value, minValue); Assert.LessOrEqual(value,maxValue); }