public void DefaultEndDateSetToTheEndOfTheCurrentDay()
        {
            DateTime validDate            = DateTime.Today.GetEndOfDay();
            DateTime invalidDate          = validDate.AddSeconds(1);
            var      fakeObjectToValidate = new FakeObjectToValidate {
                NullableDateTime = invalidDate
            };

            IValidationRule <FakeObjectToValidate> rule = new DateMustBeInRangeRule <FakeObjectToValidate>(
                f => f.NullableDateTime, "Nullable DateTime");

            Assert.IsFalse(rule.IsValid(fakeObjectToValidate));
            fakeObjectToValidate.NullableDateTime = validDate;
            Assert.IsTrue(rule.IsValid(fakeObjectToValidate), "The DateTime {0} {1} was supposed to validate to true.",
                          validDate.ToShortDateString(), validDate.ToShortTimeString());
        }
        public void IsValidReturnsFalseWhenGivenNullObject()
        {
            IValidationRule <FakeObjectToValidate> rule = new DateMustBeInRangeRule <FakeObjectToValidate>
                                                              (f => f.NullableDateTime, "Null Date");

            bool isValid = rule.IsValid(null);

            Assert.IsFalse(isValid, "Null object returned true.");
        }
        public void IsValidReturnsFalseWhenNullDateGivenAndIsNullDateValidIsFalse()
        {
            IValidationRule <FakeObjectToValidate> rule = new DateMustBeInRangeRule <FakeObjectToValidate>
                                                              (f => f.NullableDateTime, "Null Date", false);

            bool isValid = rule.IsValid(new FakeObjectToValidate());

            Assert.IsFalse(isValid, "IsValid returned true for null datetime object.");
        }
        public void IsValidReturnsTrueForDateThatMatchesMaximumDate()
        {
            var maximumDate = new DateTime(2002, 1, 1);
            IValidationRule <FakeObjectToValidate> rule = new DateMustBeInRangeRule <FakeObjectToValidate>
                                                              (f => f.NullableDateTime, "Null Date", new DateTime(2001, 1, 1), maximumDate);

            bool isValid = rule.IsValid(new FakeObjectToValidate {
                NullableDateTime = maximumDate
            });

            Assert.IsTrue(isValid, "IsValid returned false for date that matched maximum date.");
        }
        public void IsValidReturnsFalseForDateThatComesBeforeMinimumDate()
        {
            var minimumDate = new DateTime(2001, 1, 1);
            IValidationRule <FakeObjectToValidate> rule = new DateMustBeInRangeRule <FakeObjectToValidate>
                                                              (f => f.NullableDateTime, "Null Date", minimumDate, new DateTime(2002, 1, 1));

            bool isValid = rule.IsValid(new FakeObjectToValidate {
                NullableDateTime = minimumDate.AddDays(-1)
            });

            Assert.IsFalse(isValid, "IsValid returned true for date that came one day before minimum date.");
        }
        public void IsValidReturnsTrueForDateMatchingMinimumAndMaximumDate()
        {
            var date = new DateTime(2001, 1, 1);

            IValidationRule <FakeObjectToValidate> rule = new DateMustBeInRangeRule <FakeObjectToValidate>
                                                              (f => f.NullableDateTime, "Null Date", date, date);

            bool isValid = rule.IsValid(new FakeObjectToValidate {
                NullableDateTime = date
            });

            Assert.IsTrue(isValid, "IsValid returned false for date that match both minimum and maximum dates.");
        }