public void WhenGettingATaskFromTheService_ExitConditionsAreMapped() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-1"; cmdlet.JobId = "job-1"; cmdlet.Filter = null; // Build a CloudTask instead of querying the service on a Get CloudTask call ProxyModels.ExitOptions none = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.None }; ProxyModels.ExitOptions terminate = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.Terminate }; ProxyModels.CloudTask cloudTask = new ProxyModels.CloudTask { Id = "task-1", ExitConditions = new ProxyModels.ExitConditions { ExitCodeRanges = new [] { new ProxyModels.ExitCodeRangeMapping(2, 5, none) }, ExitCodes = new[] { new ProxyModels.ExitCodeMapping(4, terminate) }, SchedulingError = terminate, DefaultProperty = none, } }; AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> response = BatchTestHelpers.CreateCloudTaskGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.TaskGetOptions, AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var pipeline = new List <PSCloudTask>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudTask>())).Callback <object>(t => pipeline.Add((PSCloudTask)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); PSExitConditions psExitConditions = pipeline[0].ExitConditions; Assert.Equal(psExitConditions.Default.JobAction, JobAction.None); Assert.Equal(psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction, JobAction.None); Assert.Equal(psExitConditions.SchedulingError.JobAction, JobAction.Terminate); Assert.Equal(4, psExitConditions.ExitCodes.First().Code); Assert.Equal(JobAction.Terminate, psExitConditions.ExitCodes.First().ExitOptions.JobAction); Assert.Equal(2, psExitConditions.ExitCodeRanges.First().Start); Assert.Equal(5, psExitConditions.ExitCodeRanges.First().End); Assert.Equal(JobAction.None, psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction); }
/// <summary> /// Refreshes the current <see cref="CloudTask"/>. /// </summary> /// <param name="detailLevel">The detail level for the refresh. If a detail level which omits the <see cref="Id"/> property is specified, refresh will fail.</param> /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param> /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns> public async System.Threading.Tasks.Task RefreshAsync( DetailLevel detailLevel = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null, CancellationToken cancellationToken = default(CancellationToken)) { UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); // create the behavior managaer BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel); System.Threading.Tasks.Task <AzureOperationResponse <Models.CloudTask, Models.TaskGetHeaders> > asyncTask = this.parentBatchClient.ProtocolLayer.GetTask( this.parentJobId, this.Id, bhMgr, cancellationToken); AzureOperationResponse <Models.CloudTask, Models.TaskGetHeaders> response = await asyncTask.ConfigureAwait(continueOnCapturedContext : false); // get task from response Models.CloudTask newProtocolTask = response.Body; // immediately available to all threads this.propertyContainer = new PropertyContainer(newProtocolTask); }
public void CloudTask_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobId = "id-123"; const string taskId = "id-123"; const int exitCode = 1; const int exitCodeRangeStart = 0; const int exitCodeRangeEnd = 4; Models.ExitOptions terminateExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Terminate }; Models.ExitOptions disableExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Disable, DependencyAction = Models.DependencyAction.Satisfy }; using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { Models.CloudTask cloudTask = new Models.CloudTask() { Id = jobId, ExitConditions = new Models.ExitConditions() { DefaultProperty = disableExitOption, ExitCodeRanges = new List <Models.ExitCodeRangeMapping>() { new Models.ExitCodeRangeMapping(exitCodeRangeStart, exitCodeRangeEnd, terminateExitOption) }, ExitCodes = new List <Models.ExitCodeMapping>() { new Models.ExitCodeMapping(exitCode, terminateExitOption) }, PreProcessingError = terminateExitOption, FileUploadError = disableExitOption } }; CloudTask boundTask = client.JobOperations.GetTask( jobId, taskId, additionalBehaviors: InterceptorFactory.CreateGetTaskRequestInterceptor(cloudTask)); Assert.Equal(taskId, boundTask.Id); // reading is allowed from a task that is returned from the server. // These need to be compared as strings because they are different types but we are interested in the values being the same. Assert.Equal(disableExitOption.JobAction.ToString(), boundTask.ExitConditions.Default.JobAction.ToString()); Assert.Equal(DependencyAction.Satisfy, boundTask.ExitConditions.Default.DependencyAction); Assert.Equal(DependencyAction.Satisfy, boundTask.ExitConditions.FileUploadError.DependencyAction); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions = new ExitConditions()); Assert.Throws <InvalidOperationException>(() => boundTask.DependsOn = new TaskDependencies(new List <string>(), new List <TaskIdRange>())); Assert.Throws <InvalidOperationException>(() => boundTask.UserIdentity = new UserIdentity("abc")); Assert.Throws <InvalidOperationException>(() => boundTask.CommandLine = "Cannot change command line"); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions.Default = new ExitOptions() { JobAction = JobAction.Terminate }); } }
public void CloudTask_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobId = "id-123"; const string taskId = "id-123"; const int exitCode = 1; const int exitCodeRangeStart = 0; const int exitCodeRangeEnd = 4; Models.ExitOptions terminateExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Terminate }; Models.ExitOptions disableExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Disable }; BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential(); using (BatchClient client = BatchClient.Open(credentials)) { Models.CloudTask cloudTask = new Models.CloudTask() { Id = jobId, ExitConditions = new Models.ExitConditions() { DefaultProperty = disableExitOption, ExitCodeRanges = new List <Models.ExitCodeRangeMapping>() { new Models.ExitCodeRangeMapping(exitCodeRangeStart, exitCodeRangeEnd, terminateExitOption) }, ExitCodes = new List <Models.ExitCodeMapping>() { new Models.ExitCodeMapping(exitCode, terminateExitOption) }, SchedulingError = terminateExitOption, } }; CloudTask boundTask = client.JobOperations.GetTask( jobId, taskId, additionalBehaviors: InterceptorFactory.CreateGetTaskRequestInterceptor(cloudTask)); Assert.Equal(taskId, boundTask.Id); // reading is allowed from a task that is returned from the server. Assert.Equal(disableExitOption.JobAction.ToString(), boundTask.ExitConditions.Default.JobAction.ToString()); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions = new ExitConditions()); Assert.Throws <InvalidOperationException>(() => boundTask.DependsOn = new TaskDependencies(new List <string>(), new List <TaskIdRange>())); Assert.Throws <InvalidOperationException>(() => boundTask.RunElevated = true); Assert.Throws <InvalidOperationException>(() => boundTask.CommandLine = "Cannot change command line"); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions.Default = new ExitOptions() { JobAction = JobAction.Terminate }); } }
internal CloudTask( BatchClient parentBatchClient, string parentJobId, Models.CloudTask protocolObject, IEnumerable <BatchClientBehavior> baseBehaviors) { this.parentJobId = parentJobId; this.parentBatchClient = parentBatchClient; InheritUtil.InheritClientBehaviorsAndSetPublicProperty(this, baseBehaviors); this.propertyContainer = new PropertyContainer(protocolObject); }
/// <summary> /// Builds a CloudTaskGetResponse object /// </summary> public static ProxyModels.CloudTaskGetResponse CreateCloudTaskGetResponse(string taskId) { ProxyModels.CloudTaskGetResponse response = new ProxyModels.CloudTaskGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.CloudTask task = new ProxyModels.CloudTask(); task.Id = taskId; response.Task = task; return(response); }
/// <summary> /// Builds a CloudTaskGetResponse object /// </summary> public static AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> CreateCloudTaskGetResponse(string taskId) { var response = new AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); ProxyModels.CloudTask task = new ProxyModels.CloudTask(); task.Id = taskId; response.Body = task; return(response); }
/// <summary> /// Builds a CloudTaskListResponse object /// </summary> public static ProxyModels.CloudTaskListResponse CreateCloudTaskListResponse(IEnumerable <string> taskIds) { ProxyModels.CloudTaskListResponse response = new ProxyModels.CloudTaskListResponse(); response.StatusCode = HttpStatusCode.OK; List <ProxyModels.CloudTask> tasks = new List <ProxyModels.CloudTask>(); foreach (string id in taskIds) { ProxyModels.CloudTask task = new ProxyModels.CloudTask(); task.Id = id; tasks.Add(task); } response.Tasks = tasks; return(response); }
public void WhenGettingATaskFromTheService_ApplicationPackageReferencesAreMapped() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-1"; cmdlet.JobId = "job-1"; cmdlet.Filter = null; // Build a CloudTask instead of querying the service on a Get CloudTask call string applicationId = "foo"; string applicationVersion = "beta"; ProxyModels.CloudTask cloudTask = new ProxyModels.CloudTask { Id = "task-1", ApplicationPackageReferences = new[] { new ProxyModels.ApplicationPackageReference(applicationId, applicationVersion) } }; AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> response = BatchTestHelpers.CreateCloudTaskGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.TaskGetOptions, AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior> { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var pipeline = new List <PSCloudTask>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudTask>())).Callback <object>(t => pipeline.Add((PSCloudTask)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); var psApplicationPackageReference = pipeline[0].ApplicationPackageReferences.First(); Assert.Equal(applicationId, psApplicationPackageReference.ApplicationId); Assert.Equal(applicationVersion, psApplicationPackageReference.Version); }
/// <summary> /// Builds a CloudTaskListResponse object /// </summary> public static AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> CreateCloudTaskListResponse(IEnumerable <string> taskIds) { var response = new AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); List <ProxyModels.CloudTask> tasks = new List <ProxyModels.CloudTask>(); foreach (string id in taskIds) { ProxyModels.CloudTask task = new ProxyModels.CloudTask(); task.Id = id; tasks.Add(task); } response.Body = new MockPagedEnumerable <ProxyModels.CloudTask>(tasks); return(response); }
public PropertyContainer(Models.CloudTask protocolObject) : base(BindingState.Bound) { this.AffinityInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AffinityInfo, o => new AffinityInformation(o).Freeze()), "AffinityInformation", BindingAccess.Read); this.ApplicationPackageReferencesProperty = this.CreatePropertyAccessor( ApplicationPackageReference.ConvertFromProtocolCollectionAndFreeze(protocolObject.ApplicationPackageReferences), "ApplicationPackageReferences", BindingAccess.Read); this.CommandLineProperty = this.CreatePropertyAccessor( protocolObject.CommandLine, "CommandLine", BindingAccess.Read); this.ComputeNodeInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.NodeInfo, o => new ComputeNodeInformation(o).Freeze()), "ComputeNodeInformation", BindingAccess.Read); this.ConstraintsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Constraints, o => new TaskConstraints(o)), "Constraints", BindingAccess.Read | BindingAccess.Write); this.CreationTimeProperty = this.CreatePropertyAccessor( protocolObject.CreationTime, "CreationTime", BindingAccess.Read); this.DependsOnProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.DependsOn, o => new TaskDependencies(o).Freeze()), "DependsOn", BindingAccess.Read); this.DisplayNameProperty = this.CreatePropertyAccessor( protocolObject.DisplayName, "DisplayName", BindingAccess.Read); this.EnvironmentSettingsProperty = this.CreatePropertyAccessor( EnvironmentSetting.ConvertFromProtocolCollectionAndFreeze(protocolObject.EnvironmentSettings), "EnvironmentSettings", BindingAccess.Read); this.ETagProperty = this.CreatePropertyAccessor( protocolObject.ETag, "ETag", BindingAccess.Read); this.ExecutionInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExecutionInfo, o => new TaskExecutionInformation(o).Freeze()), "ExecutionInformation", BindingAccess.Read); this.ExitConditionsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExitConditions, o => new ExitConditions(o).Freeze()), "ExitConditions", BindingAccess.Read); this.FilesToStageProperty = this.CreatePropertyAccessor <IList <IFileStagingProvider> >( "FilesToStage", BindingAccess.None); this.IdProperty = this.CreatePropertyAccessor( protocolObject.Id, "Id", BindingAccess.Read); this.LastModifiedProperty = this.CreatePropertyAccessor( protocolObject.LastModified, "LastModified", BindingAccess.Read); this.MultiInstanceSettingsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.MultiInstanceSettings, o => new MultiInstanceSettings(o).Freeze()), "MultiInstanceSettings", BindingAccess.Read); this.PreviousStateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.TaskState, Common.TaskState>(protocolObject.PreviousState), "PreviousState", BindingAccess.Read); this.PreviousStateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.PreviousStateTransitionTime, "PreviousStateTransitionTime", BindingAccess.Read); this.ResourceFilesProperty = this.CreatePropertyAccessor( ResourceFile.ConvertFromProtocolCollectionAndFreeze(protocolObject.ResourceFiles), "ResourceFiles", BindingAccess.Read); this.RunElevatedProperty = this.CreatePropertyAccessor( protocolObject.RunElevated, "RunElevated", BindingAccess.Read); this.StateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.TaskState, Common.TaskState>(protocolObject.State), "State", BindingAccess.Read); this.StateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.StateTransitionTime, "StateTransitionTime", BindingAccess.Read); this.StatisticsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new TaskStatistics(o).Freeze()), "Statistics", BindingAccess.Read); this.UrlProperty = this.CreatePropertyAccessor( protocolObject.Url, "Url", BindingAccess.Read); }
public static IEnumerable <Protocol.RequestInterceptor> CreateGetTaskRequestInterceptor(Protocol.Models.CloudTask TaskToReturn) { return(CreateGetRequestInterceptor <Protocol.Models.TaskGetOptions, Protocol.Models.CloudTask, Protocol.Models.TaskGetHeaders>(TaskToReturn)); }
public PropertyContainer(Models.CloudTask protocolObject) : base(BindingState.Bound) { this.AffinityInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AffinityInfo, o => new AffinityInformation(o).Freeze()), nameof(AffinityInformation), BindingAccess.Read); this.ApplicationPackageReferencesProperty = this.CreatePropertyAccessor( ApplicationPackageReference.ConvertFromProtocolCollectionAndFreeze(protocolObject.ApplicationPackageReferences), nameof(ApplicationPackageReferences), BindingAccess.Read); this.AuthenticationTokenSettingsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AuthenticationTokenSettings, o => new AuthenticationTokenSettings(o).Freeze()), nameof(AuthenticationTokenSettings), BindingAccess.Read); this.CommandLineProperty = this.CreatePropertyAccessor( protocolObject.CommandLine, nameof(CommandLine), BindingAccess.Read); this.ComputeNodeInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.NodeInfo, o => new ComputeNodeInformation(o).Freeze()), nameof(ComputeNodeInformation), BindingAccess.Read); this.ConstraintsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Constraints, o => new TaskConstraints(o)), nameof(Constraints), BindingAccess.Read | BindingAccess.Write); this.ContainerSettingsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ContainerSettings, o => new TaskContainerSettings(o).Freeze()), nameof(ContainerSettings), BindingAccess.Read); this.CreationTimeProperty = this.CreatePropertyAccessor( protocolObject.CreationTime, nameof(CreationTime), BindingAccess.Read); this.DependsOnProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.DependsOn, o => new TaskDependencies(o).Freeze()), nameof(DependsOn), BindingAccess.Read); this.DisplayNameProperty = this.CreatePropertyAccessor( protocolObject.DisplayName, nameof(DisplayName), BindingAccess.Read); this.EnvironmentSettingsProperty = this.CreatePropertyAccessor( EnvironmentSetting.ConvertFromProtocolCollectionAndFreeze(protocolObject.EnvironmentSettings), nameof(EnvironmentSettings), BindingAccess.Read); this.ETagProperty = this.CreatePropertyAccessor( protocolObject.ETag, nameof(ETag), BindingAccess.Read); this.ExecutionInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExecutionInfo, o => new TaskExecutionInformation(o).Freeze()), nameof(ExecutionInformation), BindingAccess.Read); this.ExitConditionsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExitConditions, o => new ExitConditions(o).Freeze()), nameof(ExitConditions), BindingAccess.Read); this.FilesToStageProperty = this.CreatePropertyAccessor <IList <IFileStagingProvider> >( nameof(FilesToStage), BindingAccess.None); this.IdProperty = this.CreatePropertyAccessor( protocolObject.Id, nameof(Id), BindingAccess.Read); this.LastModifiedProperty = this.CreatePropertyAccessor( protocolObject.LastModified, nameof(LastModified), BindingAccess.Read); this.MultiInstanceSettingsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.MultiInstanceSettings, o => new MultiInstanceSettings(o).Freeze()), nameof(MultiInstanceSettings), BindingAccess.Read); this.OutputFilesProperty = this.CreatePropertyAccessor( OutputFile.ConvertFromProtocolCollectionAndFreeze(protocolObject.OutputFiles), nameof(OutputFiles), BindingAccess.Read); this.PreviousStateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.TaskState, Common.TaskState>(protocolObject.PreviousState), nameof(PreviousState), BindingAccess.Read); this.PreviousStateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.PreviousStateTransitionTime, nameof(PreviousStateTransitionTime), BindingAccess.Read); this.ResourceFilesProperty = this.CreatePropertyAccessor( ResourceFile.ConvertFromProtocolCollectionAndFreeze(protocolObject.ResourceFiles), nameof(ResourceFiles), BindingAccess.Read); this.StateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.TaskState, Common.TaskState>(protocolObject.State), nameof(State), BindingAccess.Read); this.StateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.StateTransitionTime, nameof(StateTransitionTime), BindingAccess.Read); this.StatisticsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new TaskStatistics(o).Freeze()), nameof(Statistics), BindingAccess.Read); this.UrlProperty = this.CreatePropertyAccessor( protocolObject.Url, nameof(Url), BindingAccess.Read); this.UserIdentityProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.UserIdentity, o => new UserIdentity(o).Freeze()), nameof(UserIdentity), BindingAccess.Read); }
/// <summary> /// Builds a CloudTaskListResponse object /// </summary> public static ProxyModels.CloudTaskListResponse CreateCloudTaskListResponse(IEnumerable<string> taskIds) { ProxyModels.CloudTaskListResponse response = new ProxyModels.CloudTaskListResponse(); response.StatusCode = HttpStatusCode.OK; List<ProxyModels.CloudTask> tasks = new List<ProxyModels.CloudTask>(); foreach (string id in taskIds) { ProxyModels.CloudTask task = new ProxyModels.CloudTask(); task.Id = id; tasks.Add(task); } response.Tasks = tasks; return response; }
public void WhenGettingATaskFromTheService_ExitConditionsAreMapped() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-1"; cmdlet.JobId = "job-1"; cmdlet.Filter = null; // Build a CloudTask instead of querying the service on a Get CloudTask call ProxyModels.ExitOptions none = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.None }; ProxyModels.ExitOptions terminate = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.Terminate }; ProxyModels.CloudTask cloudTask = new ProxyModels.CloudTask { Id = "task-1", ExitConditions = new ProxyModels.ExitConditions { ExitCodeRanges = new []{ new ProxyModels.ExitCodeRangeMapping(2, 5, none) }, ExitCodes = new[] { new ProxyModels.ExitCodeMapping(4, terminate) }, SchedulingError = terminate, DefaultProperty = none, }}; AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> response = BatchTestHelpers.CreateCloudTaskGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.TaskGetOptions, AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders>>(response); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var pipeline = new List<PSCloudTask>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSCloudTask>())).Callback<object>(t => pipeline.Add((PSCloudTask)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); PSExitConditions psExitConditions = pipeline[0].ExitConditions; Assert.Equal(psExitConditions.Default.JobAction, JobAction.None); Assert.Equal(psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction, JobAction.None); Assert.Equal(psExitConditions.SchedulingError.JobAction, JobAction.Terminate); Assert.Equal(4, psExitConditions.ExitCodes.First().Code); Assert.Equal(JobAction.Terminate, psExitConditions.ExitCodes.First().ExitOptions.JobAction); Assert.Equal(2, psExitConditions.ExitCodeRanges.First().Start); Assert.Equal(5, psExitConditions.ExitCodeRanges.First().End); Assert.Equal(JobAction.None, psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction); }
public void WhenGettingATaskFromTheService_ApplicationPackageReferencesAreMapped() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-1"; cmdlet.JobId = "job-1"; cmdlet.Filter = null; // Build a CloudTask instead of querying the service on a Get CloudTask call string applicationId = "foo"; string applicationVersion = "beta"; ProxyModels.CloudTask cloudTask = new ProxyModels.CloudTask { Id = "task-1", ApplicationPackageReferences = new[] { new ProxyModels.ApplicationPackageReference(applicationId, applicationVersion) } }; AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> response = BatchTestHelpers.CreateCloudTaskGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.TaskGetOptions, AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders>>(response); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior> { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var pipeline = new List<PSCloudTask>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSCloudTask>())).Callback<object>(t => pipeline.Add((PSCloudTask)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); var psApplicationPackageReference = pipeline[0].ApplicationPackageReferences.First(); Assert.Equal(applicationId, psApplicationPackageReference.ApplicationId); Assert.Equal(applicationVersion, psApplicationPackageReference.Version); }
/// <summary> /// Builds a CloudTaskGetResponse object /// </summary> public static ProxyModels.CloudTaskGetResponse CreateCloudTaskGetResponse(string taskId) { ProxyModels.CloudTaskGetResponse response = new ProxyModels.CloudTaskGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.CloudTask task = new ProxyModels.CloudTask(); task.Id = taskId; response.Task = task; return response; }