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); }