Generates a valid value for PropDef of type DateTime.
Inheritance: ValidValueGenerator, IValidValueGeneratorNumeric
 public void Test_GenerateValue_WhenDateTime_ShouldSet()
 {
     Type propertyType = typeof(DateTime);
     IPropDef def = new PropDefFake {
         PropertyType = propertyType
     };
     ValidValueGenerator valueGenerator = new ValidValueGeneratorDate(def);
     object value = valueGenerator.GenerateValidValue();
     Assert.IsNotNull(value);
     Assert.IsInstanceOf(typeof(DateTime), value);
     Assert.AreNotEqual(valueGenerator.GenerateValidValue(), value);
 }
 public void Test_GenerateValue_WhenDateTime_ShouldSet()
 {
     //---------------Set up test pack-------------------
     var propertyType = typeof(DateTime);
     IPropDef def = new PropDefFake {
         PropertyType = propertyType
     };
     ValidValueGenerator valueGenerator = new ValidValueGeneratorDate(def);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     var value = valueGenerator.GenerateValidValue();
     //---------------Test Result -----------------------
     Assert.IsNotNull(value);
     Assert.IsInstanceOf(typeof(DateTime), value);
     Assert.AreNotEqual(valueGenerator.GenerateValidValue(), value);
 }
 public void Test_GenerateValue_WhenDateTimeAndRule_ShouldRetValidValue()
 {
     //---------------Set up test pack-------------------
     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 Precondition----------------
     Assert.AreSame(typeof(DateTime), def.PropertyType);
     Assert.IsNotEmpty(def.PropRules.OfType<PropRuleDate>().ToList());
     var propRule = def.PropRules.OfType<PropRuleDate>().First();
     Assert.AreEqual(min, propRule.MinValue);
     Assert.AreEqual(max, propRule.MaxValue.Date);
     //---------------Execute Test ----------------------
     var value = (DateTime)generator.GenerateValidValue();
     //---------------Test Result -----------------------
     Assert.IsNotNull(value);
     Assert.GreaterOrEqual(value, min);
     Assert.LessOrEqual(value, max);
 }
 public void Test_GenerateValueGreaterThan_WhenDateTimeAndNoRule_ShouldRetValidValue()
 {
     //---------------Set up test pack-------------------
     IPropDef def = new PropDefFake {
         PropertyType = typeof(DateTime)
     };
     var generator = new ValidValueGeneratorDate(def);
     var overridingMinValue = RandomValueGen.GetAbsoluteMax<DateTime>().AddDays(-9.0);
     //---------------Assert Precondition----------------
     Assert.AreSame(typeof(DateTime), def.PropertyType);
     Assert.IsEmpty(def.PropRules.OfType<PropRuleDate>().ToList());
     //---------------Execute Test ----------------------
     var value = (DateTime)generator.GenerateValidValueGreaterThan(overridingMinValue);
     //---------------Test Result -----------------------
     Assert.IsNotNull(value);
     Assert.GreaterOrEqual(value, overridingMinValue);
 }
 public void Test_GenerateValueLessThan_WhenDateTimeAndRule_WhenRuleMoreRestrictive_ShouldRetValidValue()
 {
     //---------------Set up test pack-------------------
     IPropDef def = new PropDefFake {
         PropertyType = typeof(DateTime)
     };
     var min = DateTime.Now;
     var max = DateTime.Today.AddDays(5.0);
     var overridingMaxValue = RandomValueGen.GetAbsoluteMax<DateTime>().AddDays(-5.0);
     def.AddPropRule(CreatePropRuleDate(min, max));
     var generator = new ValidValueGeneratorDate(def);
     //---------------Assert Precondition----------------
     Assert.AreSame(typeof(DateTime), def.PropertyType);
     Assert.IsNotEmpty(def.PropRules.OfType<PropRuleDate>().ToList());
     var propRule = def.PropRules.OfType<PropRuleDate>().First();
     Assert.AreEqual(min, propRule.MinValue);
     Assert.AreEqual(max.AddDays(1.0).AddMilliseconds(-1.0), propRule.MaxValue);
     //---------------Execute Test ----------------------
     var value = (DateTime)generator.GenerateValidValueLessThan(overridingMaxValue);
     //---------------Test Result -----------------------
     Assert.IsNotNull(value);
     Assert.GreaterOrEqual(value, min);
     Assert.LessOrEqual(value, max);
     Assert.LessOrEqual(value, overridingMaxValue);
 }
 public void Test_GenerateValueLessThan_WhenDateTimeAndNoRule_ShouldRetValidValue()
 {
     // Redmine #1745
     // Changed from using DateTime.MinValue as Sql Server can't handle this
     // Sql Server min date is 1/1/1753
     //---------------Set up test pack-------------------
     var expectedAbsoluteMin = new DateTime(1753, 1, 1);
     IPropDef def = new PropDefFake {
         PropertyType = typeof(DateTime)
     };
     var generator = new ValidValueGeneratorDate(def);
     var overridingMaxValue = expectedAbsoluteMin.AddDays(7.0);
     //---------------Assert Precondition----------------
     Assert.AreSame(typeof(DateTime), def.PropertyType);
     Assert.IsEmpty(def.PropRules.OfType<PropRuleDate>().ToList());
     //---------------Execute Test ----------------------
     var value = (DateTime)generator.GenerateValidValueLessThan(overridingMaxValue);
     //---------------Test Result -----------------------
     Assert.IsNotNull(value);
     Assert.GreaterOrEqual(value, expectedAbsoluteMin);
     Assert.LessOrEqual(value, overridingMaxValue);
 }
 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);
 }