示例#1
0
        private RangeChecker <DateTime> BuildRangeChecker()
        {
            var generator     = new RelativeDateTimeGenerator();
            var nowDateTime   = DateTime.Now;
            var lowerDateTime =
                this.lowerBoundType != RangeBoundaryType.Ignore
                    ? generator.GenerateBoundDateTime(lowerBound, lowerUnit, nowDateTime)
                    : default(DateTime);
            var upperDateTime =
                this.upperBoundType != RangeBoundaryType.Ignore
                    ? generator.GenerateBoundDateTime(upperBound, upperUnit, nowDateTime)
                    : default(DateTime);
            var rangeChecker = new RangeChecker <DateTime>(lowerDateTime, lowerBoundType, upperDateTime, upperBoundType);

            return(rangeChecker);
        }
示例#2
0
        /// <summary>
        /// <para>Initializes a new instance of the <see cref="RelativeDateTimeValidator"/>.</para>
        /// </summary>
        /// <param name="negated">True if the validator must negate the result of the validation.</param>
        /// <param name="messageTemplate">The message template to use when logging results.</param>
        /// <param name="lowerBound">The lower bound.</param>
        /// <param name="lowerUnit">The lower bound unit of time.</param>
        /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
        /// <param name="upperBound">The upper bound</param>
        /// <param name="upperUnit">The upper bound unit of time.</param>
        /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
        public RelativeDateTimeValidator(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType,
                                         int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType,
                                         string messageTemplate, bool negated)
            : base(messageTemplate, null, negated)
        {
            ValidatorArgumentsValidatorHelper.ValidateRelativeDatimeValidator(lowerBound, lowerUnit, lowerBoundType, upperBound, upperUnit, upperBoundType);

            this.lowerBound = lowerBound;
            this.lowerUnit  = lowerUnit;
            this.upperBound = upperBound;
            this.upperUnit  = upperUnit;

            generator = new RelativeDateTimeGenerator();
            DateTime nowDateTime   = DateTime.Now;
            DateTime lowerDateTime = generator.GenerateBoundDateTime(lowerBound, lowerUnit, nowDateTime);
            DateTime upperDateTime = generator.GenerateBoundDateTime(upperBound, upperUnit, nowDateTime);

            this.rangeChecker = new RangeChecker <DateTime>(lowerDateTime, lowerBoundType, upperDateTime, upperBoundType);
        }
 public void SetUp()
 {
     generator = new RelativeDateTimeGenerator();
     dateTime = DateTime.Now;
 }