/// <summary> /// Creates a test job schedule for use in Scenario tests. /// </summary> public static void CreateTestJobSchedule(BatchController controller, BatchAccountContext context, string jobScheduleId, TimeSpan?recurrenceInterval) { RequestInterceptor interceptor = CreateHttpRecordingInterceptor(); BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor }; BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient); PSJobSpecification jobSpecification = new PSJobSpecification(); jobSpecification.PoolInformation = new PSPoolInformation(); jobSpecification.PoolInformation.PoolId = SharedPool; PSSchedule schedule = new PSSchedule(); if (recurrenceInterval != null) { schedule = new PSSchedule(); schedule.RecurrenceInterval = recurrenceInterval; } NewJobScheduleParameters parameters = new NewJobScheduleParameters(context, jobScheduleId, behaviors) { JobSpecification = jobSpecification, Schedule = schedule }; client.CreateJobSchedule(parameters); }
public void SetBatchJobScheduleParametersGetPassedToRequestTest() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobSchedule = new PSCloudJobSchedule(BatchTestHelpers.CreateFakeBoundJobSchedule(context)); // Make changes to the job schedule PSJobSpecification jobSpec = new PSJobSpecification() { DisplayName = "job display name", CommonEnvironmentSettings = new List <PSEnvironmentSetting>() { new PSEnvironmentSetting("common1", "val1"), new PSEnvironmentSetting("common2", "val2") }, JobManagerTask = new PSJobManagerTask("job manager", "cmd /c echo job manager"), JobPreparationTask = new PSJobPreparationTask("cmd /c echo job prep"), JobReleaseTask = new PSJobReleaseTask("cmd /c echo job release"), PoolInformation = new PSPoolInformation() { PoolId = "myPool" } }; cmdlet.JobSchedule.JobSpecification = jobSpec; PSSchedule schedule = new PSSchedule() { DoNotRunAfter = DateTime.Now.AddYears(1), DoNotRunUntil = DateTime.Now.AddDays(1), RecurrenceInterval = TimeSpan.FromDays(1), StartWindow = TimeSpan.FromHours(1) }; cmdlet.JobSchedule.Schedule = schedule; cmdlet.JobSchedule.Metadata = new List <PSMetadataItem>() { new PSMetadataItem("metadata1", "value1") }; // Store the request parameters JobScheduleUpdateParameter requestParameters = null; RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < JobScheduleUpdateParameter, JobScheduleUpdateOptions, AzureOperationHeaderResponse <JobScheduleUpdateHeaders> >(requestAction: (r) => { requestParameters = r.Parameters; }); cmdlet.AdditionalBehaviors = new BatchClientBehavior[] { interceptor }; cmdlet.ExecuteCmdlet(); // Verify that the request parameters contain the updated properties Assert.Equal(jobSpec.CommonEnvironmentSettings.Count, requestParameters.JobSpecification.CommonEnvironmentSettings.Count); Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Name); Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Value); Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Name); Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Value); Assert.Equal(jobSpec.JobManagerTask.Id, requestParameters.JobSpecification.JobManagerTask.Id); Assert.Equal(jobSpec.JobPreparationTask.CommandLine, requestParameters.JobSpecification.JobPreparationTask.CommandLine); Assert.Equal(jobSpec.JobReleaseTask.CommandLine, requestParameters.JobSpecification.JobReleaseTask.CommandLine); Assert.Equal(jobSpec.PoolInformation.PoolId, requestParameters.JobSpecification.PoolInfo.PoolId); Assert.Equal(schedule.DoNotRunAfter, requestParameters.Schedule.DoNotRunAfter); Assert.Equal(schedule.DoNotRunUntil, requestParameters.Schedule.DoNotRunUntil); Assert.Equal(schedule.RecurrenceInterval, requestParameters.Schedule.RecurrenceInterval); Assert.Equal(schedule.StartWindow, requestParameters.Schedule.StartWindow); Assert.Equal(cmdlet.JobSchedule.Metadata.Count, requestParameters.Metadata.Count); Assert.Equal(cmdlet.JobSchedule.Metadata[0].Name, requestParameters.Metadata[0].Name); Assert.Equal(cmdlet.JobSchedule.Metadata[0].Value, requestParameters.Metadata[0].Value); }