예제 #1
0
        public void CronValidator_InvalidMinute_IsValidFalse(
            string minute,
            string hour,
            string dayOfMonth,
            string month,
            string dayOfWeek)
        {
            // Arrange
            string[] cronValues = new string[5];
            cronValues[0] = minute;
            cronValues[1] = hour;
            cronValues[2] = dayOfMonth;
            cronValues[3] = month;
            cronValues[4] = dayOfWeek;

            // Act
            _cronValidator = new CronValidator(cronValues);

            //Assert
            _cronValidator.IsValid.ShouldBeFalse();
        }
예제 #2
0
        private static void ValidateCronString(string cronString)
        {
            try
            {
                var           valueList = cronString.Split(' ');
                CronValidator cron      = new CronValidator();
                if (valueList.Length != 5)
                {
                    cron.IsValid = false;
                    throw new InvalidCastException();
                }
                else
                {
                    cron = new CronValidator(valueList);
                    if (cron.IsValid = false)
                    {
                        throw new InvalidOperationException();
                    }

                    _valueList       = valueList;
                    _minuteField     = _valueList[0];
                    _hourField       = _valueList[1];
                    _dayOfMonthField = _valueList[2];
                    _monthField      = _valueList[3];
                    _dayOfWeekField  = _valueList[4];
                }
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Invalid Cron. Please run application again");
                Console.ReadKey();
            }
            catch (InvalidCastException)
            {
                Console.WriteLine("Invalid Cron lenght. Please enter five values separated by a single space.");
                Console.ReadKey();
            }
        }