public void UnitTestDoWork_With_Now_Not_In_The_Scheduled_Time()
        {
            MockRepository mockRepository = new MockRepository();

            // 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
            IDeployment mockDeployment = mockRepository.StrictMock <IDeployment>();
            IOperation  mockOperation  = mockRepository.StrictMock <IOperation>();

            // Act
            mockRepository.ReplayAll();
            DeploymentDeleteForecastWorker deploymentDeleteForecastWorker = new DeploymentDeleteForecastWorker(
                mockDeployment,
                mockOperation,
                this.subscriptionId,
                CertificateThumbprint,
                ServiceName,
                DeploymentSlot,
                new[] { new ScheduleDay {
                            DayOfWeek = DateTime.Now.DayOfWeek, EndTime = dailyEndTime, StartTime = dailyStartTime
                        } },
                PollingIntervalInMinutes);

            deploymentDeleteForecastWorker.DoWork();

            // Assert
            mockRepository.VerifyAll();
        }
Beispiel #2
0
        internal static DeploymentDeleteForecastWorker[] GetDeploymentDeleteForecastWorkers()
        {
            IConfigurationSource configurationSource = GetConfigurationSource();
            ArrayList            list = new ArrayList();

            foreach (DeploymentDeleteConfiguration deploymentDeleteConfiguration in configurationSource.GetWindowsAzureDeploymentDeleteConfigurations())
            {
                SubscriptionConfiguration subscriptionConfiguration = configurationSource.GetWindowsAzureSubscriptionConfiguration(deploymentDeleteConfiguration.SubscriptionConfigurationId);
                foreach (string deploymentSlot in deploymentDeleteConfiguration.DeploymentSlots)
                {
                    foreach (ScheduleDefinitionConfiguration scheduleDefinitionConfiguration in deploymentDeleteConfiguration.Schedules)
                    {
                        ScheduleDay[] scheduleDays = GetScheduleDaysFromScheduleConfiguration(scheduleDefinitionConfiguration);
                        DeploymentDeleteForecastWorker deploymentDeleteForecastWorker = new DeploymentDeleteForecastWorker(
                            new Deployment(),
                            new Operation(),
                            subscriptionConfiguration.SubscriptionId,
                            subscriptionConfiguration.CertificateThumbprint,
                            deploymentDeleteConfiguration.ServiceName,
                            deploymentSlot,
                            scheduleDays,
                            deploymentDeleteConfiguration.PollingIntervalInMinutes);
                        list.Add(deploymentDeleteForecastWorker);
                    }
                }
            }

            return((DeploymentDeleteForecastWorker[])list.ToArray(typeof(DeploymentDeleteForecastWorker)));
        }
        public void UnitTestDoWork_With_Now_In_The_Scheduled_Time_And_Deployment_Exists_And_Second_Call_Not_Within_Polling_Interval()
        {
            MockRepository mockRepository = new MockRepository();

            // 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);

            // Set polling window to zero so the second call to "DoWork" is not within the first polling window.
            const int       PollingIntervalInMinutes = 0;
            OperationResult operationResult          = new OperationResult
            {
                Code           = "Test",
                HttpStatusCode = HttpStatusCode.OK,
                Id             = Guid.NewGuid(),
                Message        = string.Empty,
                Status         = OperationStatus.Succeeded
            };

            // Arrange
            IDeployment mockDeployment = mockRepository.StrictMock <IDeployment>();
            IOperation  mockOperation  = mockRepository.StrictMock <IOperation>();

            mockDeployment
            .Expect(d => d.CheckExists(this.subscriptionId, CertificateThumbprint, ServiceName, DeploymentSlot))
            .Repeat.Twice()
            .Return(true);
            mockDeployment
            .Expect(d => d.DeleteRequest(this.subscriptionId, CertificateThumbprint, ServiceName, DeploymentSlot))
            .Repeat.Twice()
            .Return(DeleteRequestId);
            mockOperation
            .Expect(o => o.StatusCheck(this.subscriptionId, CertificateThumbprint, DeleteRequestId))
            .Repeat.Twice()
            .Return(operationResult);

            // Act
            mockRepository.ReplayAll();
            DeploymentDeleteForecastWorker deploymentDeleteForecastWorker = new DeploymentDeleteForecastWorker(
                mockDeployment,
                mockOperation,
                this.subscriptionId,
                CertificateThumbprint,
                ServiceName,
                DeploymentSlot,
                new[] { new ScheduleDay {
                            DayOfWeek = DateTime.Now.DayOfWeek, EndTime = dailyEndTime, StartTime = dailyStartTime
                        } },
                PollingIntervalInMinutes);

            deploymentDeleteForecastWorker.DoWork();
            Thread.Sleep(10);
            deploymentDeleteForecastWorker.DoWork(); // Call DoWork twice to check the polling window works.

            // Assert
            mockRepository.VerifyAll();
        }
        public void UnitTestDoWork_With_Now_In_The_Scheduled_Time_And_Deployment_Exists_And_Delete_Throws_An_Error()
        {
            MockRepository mockRepository = new MockRepository();

            // 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
            IDeployment mockDeployment = mockRepository.StrictMock <IDeployment>();
            IOperation  mockOperation  = mockRepository.StrictMock <IOperation>();

            mockDeployment
            .Expect(d => d.CheckExists(this.subscriptionId, CertificateThumbprint, ServiceName, DeploymentSlot))
            .Repeat.Once()
            .Return(true);
            mockDeployment
            .Expect(d => d.DeleteRequest(this.subscriptionId, CertificateThumbprint, ServiceName, DeploymentSlot))
            .Repeat.Once()
            .Throw(new Exception("Error"));

            // Act
            mockRepository.ReplayAll();
            DeploymentDeleteForecastWorker deploymentDeleteForecastWorker = new DeploymentDeleteForecastWorker(
                mockDeployment,
                mockOperation,
                this.subscriptionId,
                CertificateThumbprint,
                ServiceName,
                DeploymentSlot,
                new[] { new ScheduleDay {
                            DayOfWeek = DateTime.Now.DayOfWeek, EndTime = dailyEndTime, StartTime = dailyStartTime
                        } },
                PollingIntervalInMinutes);

            deploymentDeleteForecastWorker.DoWork();

            // Assert
            mockRepository.VerifyAll();
        }