public void UnitTestDoWork_With_Now_In_The_Scheduled_Time()
        {
            MockRepository mockRepository = new MockRepository();
            const string StorageAccountName = "storageAccountName";
            const string TableName1 = "tableName1";
            const string TableName2 = "tableName2";

            // Set start time to 1 hour before now.
            TimeSpan dailyStartTime = (DateTime.Now - DateTime.Today).Subtract(this.oneHour);

            // Set end time to 1 hour after now.
            TimeSpan dailyEndTime = (DateTime.Now - DateTime.Today).Add(this.oneHour);
            const int PollingIntervalInMinutes = 60;

            // Arrange
            ITableService mockTableService = mockRepository.StrictMock<ITableService>();
            mockTableService
                .Expect(ts => ts.DeleteTable(string.Empty))
                .IgnoreArguments()
                .Repeat.Twice()
                .Return(true);

            // Act
            mockRepository.ReplayAll();
            TableDeleteForecastWorker tableDeleteForecastWorker = new TableDeleteForecastWorker(
                mockTableService,
                StorageAccountName,
                new[] { TableName1, TableName2 },
                new[] { new ScheduleDay { DayOfWeek = DateTime.Now.DayOfWeek, EndTime = dailyEndTime, StartTime = dailyStartTime } },
                PollingIntervalInMinutes);
            tableDeleteForecastWorker.DoWork();

            // Assert
            mockRepository.VerifyAll();
        }
        public void UnitTestDoWork_With_Now_In_The_Scheduled_Time_But_Not_On_A_Scheduled_Day()
        {
            MockRepository mockRepository = new MockRepository();
            const string StorageAccountName = "storageAccountName";
            const string TableName = "tableName";

            // Set start time to 1 hour before now.
            TimeSpan dailyStartTime = (DateTime.Now - DateTime.Today).Subtract(this.oneHour);

            // Set end time to 1 hour after now.
            TimeSpan dailyEndTime = (DateTime.Now - DateTime.Today).Add(this.oneHour);

            // Get a day that is not today.
            DayOfWeek notToday = DayOfWeek.Sunday;
            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                notToday = DayOfWeek.Monday;
            }

            const int PollingIntervalInMinutes = 60;

            // Arrange
            ITableService mockTableService = mockRepository.StrictMock<ITableService>();

            // Act
            mockRepository.ReplayAll();
            TableDeleteForecastWorker tableDeleteForecastWorker = new TableDeleteForecastWorker(
                mockTableService,
                StorageAccountName,
                new[] { TableName },
                new[] { new ScheduleDay { DayOfWeek = notToday, EndTime = dailyEndTime, StartTime = dailyStartTime } },
                PollingIntervalInMinutes);
            tableDeleteForecastWorker.DoWork();

            // Assert
            mockRepository.VerifyAll();
        }
        internal static TableDeleteForecastWorker[] GetTableDeleteForecastWorkers()
        {
            IConfigurationSource configurationSource = GetConfigurationSource();
            ArrayList list = new ArrayList();
            foreach (TableDeleteConfiguration tableDeleteConfiguration in configurationSource.GetWindowsAzureTableDeleteConfigurations())
            {
                TableService tableService = new TableService(tableDeleteConfiguration.StorageAccountName, tableDeleteConfiguration.StorageAccountKey);
                foreach (ScheduleDefinitionConfiguration scheduleDefinitionConfiguration in tableDeleteConfiguration.Schedules)
                {
                    ScheduleDay[] scheduleDays = GetScheduleDaysFromScheduleConfiguration(scheduleDefinitionConfiguration);
                    TableDeleteForecastWorker tableDeleteForecastWorker = new TableDeleteForecastWorker(
                        tableService,
                        tableDeleteConfiguration.StorageAccountName,
                        tableDeleteConfiguration.TableNames.ToArray(),
                        scheduleDays,
                        tableDeleteConfiguration.PollingIntervalInMinutes);
                    list.Add(tableDeleteForecastWorker);
                }
            }

            return (TableDeleteForecastWorker[])list.ToArray(typeof(TableDeleteForecastWorker));
        }