Exemplo n.º 1
0
        public void EveryWeekday()
        {
            // Arrange
            var sunday   = new DateTime(2018, 02, 18);
            var saturday = new DateTime(2018, 02, 17);

            var monday = new DateTime(2018, 02, 19);

            var calculator = new TimeCalculator();
            var run        = new DayUnit(calculator);

            // Act
            run.Weekday();
            var calculated = calculator.Calculate(sunday);

            // Assert
            var expected = new DateTime(2018, 02, 19);

            Assert.AreEqual(expected, calculated);

            // Act
            calculated = calculator.Calculate(saturday);

            // Assert
            Assert.AreEqual(expected, calculated);

            // Act
            calculated = calculator.Calculate(monday);

            // Assert
            Assert.AreEqual(expected, calculated);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new schedule for the given job.
        /// </summary>
        /// <param name="job">Job to be scheduled</param>
        /// <param name="specifier">Scheduling of this schedule</param>
        /// <returns>A schedule for the given job</returns>
        public Schedule(Action job, Action <RunSpecifier> specifier)
        {
            _job = job ?? throw new ArgumentNullException(nameof(job));

            if (specifier == null)
            {
                throw new ArgumentNullException(nameof(specifier));
            }

            _lock        = new object();
            _task        = null;
            _calculator  = new TimeCalculator();
            _tokenSource = null;

            specifier(new RunSpecifier(_calculator));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Changes the scheduling of this schedule.
        /// You must not call this method if the schedule is running.
        /// </summary>
        /// <param name="specifier">Scheduling of this schedule</param>
        public void SetScheduling(Action <RunSpecifier> specifier)
        {
            lock (_lock)
            {
                if (specifier == null)
                {
                    throw new ArgumentNullException(nameof(specifier));
                }

                if (_Running())
                {
                    throw new InvalidOperationException("You cannot change the scheduling of a running schedule.");
                }

                NextRun     = null;
                _calculator = new TimeCalculator();
                specifier(new RunSpecifier(_calculator));
            }
        }
Exemplo n.º 4
0
 internal PeriodOnceSet(TimeCalculator calculator) => _calculator = calculator;
Exemplo n.º 5
0
 internal DayUnit(TimeCalculator calculator) => _calculator = calculator;
Exemplo n.º 6
0
 internal OnceSet(TimeCalculator calculator) => _calculator = calculator;
Exemplo n.º 7
0
 internal RunSpecifier(TimeCalculator calculator) => _calculator = calculator;
Exemplo n.º 8
0
 internal MonthUnit(TimeCalculator calculator) => _calculator = calculator;