예제 #1
0
        public void UnitTestDoWork_With_Now_Not_In_The_Scheduled_Time()
        {
            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).Add(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>();

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

            tableDeleteForecastWorker.DoWork();

            // Assert
            mockRepository.VerifyAll();
        }
예제 #2
0
        public void UnitTestDoWork_With_Now_In_The_Scheduled_Time_And_Table_Does_Not_Exist()
        {
            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()
            .Throw(new WebException("Table does not exist."));

            // 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();
            tableDeleteForecastWorker.DoWork(); // Call DoWork twice to check the polling window works.

            // Assert
            mockRepository.VerifyAll();
        }
예제 #3
0
        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)));
        }