public PSExitCodeMapping(int code, PSExitOptions exitOptions)
 {
     this.omObject = new Microsoft.Azure.Batch.ExitCodeMapping(code, exitOptions.omObject);
 }
 public PSExitCodeRangeMapping(int start, int end, PSExitOptions exitOptions)
 {
     this.omObject = new Microsoft.Azure.Batch.ExitCodeRangeMapping(start, end, exitOptions.omObject);
 }
        public void ExitConditionsAreSentToService()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
            cmdlet.BatchContext = context;

            TaskAddParameter requestParameters = null;

            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                TaskAddBatchRequest request = (TaskAddBatchRequest)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    requestParameters = request.Parameters;

                    var response = new AzureOperationHeaderResponse<TaskAddHeaders>();
                    Task<AzureOperationHeaderResponse<TaskAddHeaders>> task = Task.FromResult(response);
                    return task;
                };
            });

            cmdlet.AdditionalBehaviors = new List<BatchClientBehavior> { interceptor };

            var none = new PSExitOptions { omObject = new Azure.Batch.ExitOptions { JobAction = Azure.Batch.Common.JobAction.None } };
            var terminate = new PSExitOptions { omObject = new Azure.Batch.ExitOptions { JobAction = Azure.Batch.Common.JobAction.Terminate } };

            cmdlet.ExitConditions = new PSExitConditions
            {
                ExitCodes = new List<PSExitCodeMapping> { new PSExitCodeMapping(0, none) },
                SchedulingError = terminate,
                ExitCodeRanges = new List<PSExitCodeRangeMapping> { new PSExitCodeRangeMapping(1, 5, terminate) },
                Default = none,
            };

            cmdlet.JobId = "job-Id";
            cmdlet.Id = "task-id";
            cmdlet.ExecuteCmdlet();

            var exitConditions = requestParameters.ExitConditions;
            Assert.Equal(1, exitConditions.ExitCodeRanges.First().Start);
            Assert.Equal(5, exitConditions.ExitCodeRanges.First().End);
            Assert.Equal(ProxyModels.JobAction.Terminate, exitConditions.ExitCodeRanges.First().ExitOptions.JobAction);
            Assert.Equal(ProxyModels.JobAction.None, exitConditions.ExitCodes.First().ExitOptions.JobAction);
            Assert.Equal(ProxyModels.JobAction.Terminate, exitConditions.SchedulingError.JobAction);
            Assert.Equal(ProxyModels.JobAction.None, exitConditions.DefaultProperty.JobAction);
        }
Beispiel #4
0
 public PSExitCodeMapping(int code, PSExitOptions exitOptions)
 {
     this.omObject = new Microsoft.Azure.Batch.ExitCodeMapping(code, exitOptions.omObject);
 }
 public PSExitCodeRangeMapping(int start, int end, PSExitOptions exitOptions)
 {
     this.omObject = new Microsoft.Azure.Batch.ExitCodeRangeMapping(start, end, exitOptions.omObject);
 }