public void Insert3TimesShouldSortThem()
        {
            var dataProvider = new DataProviderMockFactory().Create();
            var timeStringConverter = new TimeStringConverterMockFactory().Create();
            var objectUnderTest = new ConfigProviderWrapper(dataProvider, timeStringConverter)
            {
                Now = new System.DateTime(2015, 09, 14, 09, 30, 01),
            };
            var methodName = "Insert3Times";
            var expected = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 14, 09, 33, 01),
                ServiceName = methodName,
            };
            var expectedLess1min = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 14, 09, 32, 01),
                ServiceName = methodName,
            };

            var expectedPlus24h = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 15, 09, 33, 01),
                ServiceName = methodName,
            };

            objectUnderTest.InsertExecutionTimes(new[] { expectedPlus24h, expectedLess1min, expected});

            var actual = objectUnderTest.ExecutionTimes.ElementAt(1);

            Assert.AreEqual(expected, actual, string.Format("Mismatched time: expected:{0}, actual:{1}", expected.ScheduledTime, actual.ScheduledTime));
        }
        public void CheckResetServiceExecutionTimesStays()
        {
            var dataProvider = new DataProviderMockFactory().Create();
            var timeStringConverter = new TimeStringConverterMockFactory().Create();
            var serviceProviderExecutionDateTime = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 15, 09, 29, 01),
                ServiceName = "ServiceProvider.ResetServiceExecutionTimes",
            };
            var serviceExecutionDateTime = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 15, 09, 29, 01),
                ServiceName = "Service.WorkerMethod",
            };
            var expected = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 15, 09, 29, 01),
                ServiceName = "ConfigProvider.ResetServiceExecutionTimes",
            };
            var objectUnderTest = new ConfigProviderWrapper(dataProvider, timeStringConverter)
            {
                Now = new System.DateTime(2015, 09, 14, 09, 34, 01),
                ExecutionTimes = new List<ExecutionDateTime>(new[] { serviceProviderExecutionDateTime, serviceExecutionDateTime, expected }),
            };

            objectUnderTest.RemoveServiceExecutionTimes();

            var actual = objectUnderTest.ExecutionTimes.Single();

            Assert.AreEqual(expected, actual);
        }
 public ExecutionDateTime Convert(DataSourceDateTime sourceTime)
 {
     var parsedDateTime = _dateTimeNow ();
     parsedDateTime = ParseTime (sourceTime.ScheduledTime, sourceTime.DayOfWeek);
     var scheduled = new ExecutionDateTime ()
     {
         IsOnce = sourceTime.IsOnce,
         IsStop = sourceTime.IsStop,
         IsWholeDay = sourceTime.IsWholeDay,
         Remove = sourceTime.Remove,
         ScheduledTime = parsedDateTime,
         ServiceName = sourceTime.ServiceName,
     };
     return scheduled;
 }
예제 #4
0
        public static void ExecutionDateTimeMatch(int expectedHour, int expectedMinute, int expectedDay, int expectedMonth, int expectedYear, bool expectedStop, bool expectedOnce, ExecutionDateTime actual)
        {
            var sb = new StringBuilder();

            if (expectedHour != actual.ScheduledTime.Hour)
            {
                sb.AppendFormat("hour expected:{0} actual:{1}, ", expectedHour, actual.ScheduledTime.Hour);
            }

            if (expectedMinute != actual.ScheduledTime.Minute)
            {
                sb.AppendFormat("minute expected:{0} actual:{1}, ", expectedMinute, actual.ScheduledTime.Minute);
            }

            if (expectedDay != actual.ScheduledTime.Day)
            {
                sb.AppendFormat("day expected:{0} actual:{1}, ", expectedDay, actual.ScheduledTime.Day);
            }

            if (expectedMonth != actual.ScheduledTime.Month)
            {
                sb.AppendFormat("month expected:{0} actual:{1}, ", expectedMonth, actual.ScheduledTime.Month);
            }

            if (expectedYear != actual.ScheduledTime.Year)
            {
                sb.AppendFormat("year expected:{0} actual:{1}, ", expectedYear, actual.ScheduledTime.Year);
            }

            if (expectedStop != actual.IsStop)
            {
                sb.AppendFormat("isStop expected:{0} actual:{1}, ", expectedStop, actual.IsStop);
            }

            if (expectedOnce != actual.IsOnce)
            {
                sb.AppendFormat("once expected:{0} actual:{1}, ", expectedOnce, actual.IsOnce);
            }

            if (sb.Length > 0)
            {
                sb.Insert(0, "Mismatched ");
                sb.Replace(',', '.', sb.Length - 2, 1);
                var message = sb.ToString();
                throw new AssertionException(message);
            }
        }
        public void Insert2IdenticalTimes()
        {
            var dataProvider = new DataProviderMockFactory().Create();
            var timeStringConverter = new TimeStringConverterMockFactory().Create();
            var objectUnderTest = new ConfigProviderWrapper(dataProvider, timeStringConverter);
            var expected = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 14, 09, 34, 01),
                ServiceName = "Insert2IdenticalTimes",
            };
            var unexpected = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 14, 09, 34, 01),
                ServiceName = "Insert2IdenticalTimes"
            };

            objectUnderTest.InsertExecutionTimes(new[] { expected, unexpected });

            var actual = objectUnderTest.ExecutionTimes.Where(x => x.ServiceName == expected.ServiceName).Single();

            Assert.AreEqual(expected, actual);
        }
        public void Insert2SameTimesOneStopper()
        {
            var dataProvider = new DataProviderMockFactory().Create();
            var timeStringConverter = new TimeStringConverterMockFactory().Create();
            var objectUnderTest = new ConfigProviderWrapper(dataProvider, timeStringConverter);
            var expected = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 14, 09, 34, 01),
                ServiceName = "Insert2IdenticalTimes",
            };
            var expectedWithStop = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 14, 09, 34, 01),
                ServiceName = "Insert2IdenticalTimes",
                IsStop = true,
            };

            objectUnderTest.InsertExecutionTimes(new[] { expected, expectedWithStop });

            var actual = objectUnderTest.ExecutionTimes.Where(x => x.ServiceName == expected.ServiceName).Single();

            Assert.AreEqual(expectedWithStop, actual, "Expected time with Stop flag missing");
        }
 public void SetNextExecutionTimeReturn(ExecutionDateTime time)
 {
     _configProviderMock.GetNextExecutionTime().Returns(time);
 }
예제 #8
0
        //22:00 till 08:00  every hour = 9 runs (excluding limits)
        //08:00 till 22:00 every 5 min = 168 runs (including limits)
        protected IEnumerable<ExecutionDateTime> CreateResetServiceAndConfigExecutionTimes()
        {
            var configTimes = new List<ExecutionDateTime>();
            var offset = new TimeSpan(0, (3 - _dateTimeNow().Minute % 5) + 1, 0);  // linked to current Datetime, but the minutes are 04, 09, 14....
            for(var i = 0; i < 177; ++i)
            {
                var time = _dateTimeNow().Add(offset);
                var executionDateTime = new ExecutionDateTime()
                {
                    IsOnce = false,
                    IsStop = false,
                    IsWholeDay = false,
                    ScheduledTime = time,
                    ServiceName = "ConfigProvider.ResetServiceExecutionTimes",
                };

                configTimes.Add(executionDateTime);

                if (time.TimeOfDay.TotalMinutes < 421 || time.TimeOfDay.TotalMinutes > 1319)
                {
                    offset = offset.Add(new TimeSpan(1,0,0));
                }
                else
                {
                    offset = offset.Add(new TimeSpan(0, 5, 0));
                }
            }
            var nextCreateConfigTimesExecutionDateTime = new ExecutionDateTime()
            {
                IsOnce = false,
                IsStop = false,
                IsWholeDay = false,
                ScheduledTime = _dateTimeNow().Add(offset),
                ServiceName = "ConfigProvider.ResetConfigExecutionTimes",
            };
            return configTimes;
        }
예제 #9
0
 protected void RemoveServiceExecutionTimes(ExecutionDateTime wholeDayStopper)
 {
     _executionTimes.RemoveAll(
         x => x.ServiceName.Equals(wholeDayStopper.ServiceName)&&
              x.ScheduledTime.Date.Equals(wholeDayStopper.ScheduledTime.Date));
 }
        public void CheckServiceExecutionTimesRemoved()
        {
            var dataProvider = new DataProviderMockFactory().Create();
            var timeStringConverter = new TimeStringConverterMockFactory().Create();
            var serviceExecutionDateTime = new ExecutionDateTime()
            {
                ScheduledTime = new System.DateTime(2015, 09, 15, 09, 29, 01),
                ServiceName = "ServiceProvider.ResetServiceExecutionTimes",
            };
            var objectUnderTest = new ConfigProviderWrapper(dataProvider, timeStringConverter)
            {
                Now = new System.DateTime(2015, 09, 14, 09, 34, 01),
                ExecutionTimes = new List<ExecutionDateTime>(new[] { serviceExecutionDateTime }),
            };

            objectUnderTest.RemoveServiceExecutionTimes();

            var actual = objectUnderTest.ExecutionTimes.Count;

            Assert.AreEqual(0, actual);
        }