public void AutoCompletionSettingIsSentToService()
        {
            // Setup cmdlet without the required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            CloudJob cloudJob = new Azure.Batch.Protocol.Models.CloudJob(
                id: "job-id",
                poolInfo: new Azure.Batch.Protocol.Models.PoolInformation(),
                onAllTasksComplete: (Azure.Batch.Protocol.Models.OnAllTasksComplete?)OnAllTasksComplete.TerminateJob);

            cmdlet.Job = new PSCloudJob(BatchTestHelpers.CreateFakeBoundJob(context, cloudJob));
            cmdlet.Job.OnAllTasksComplete = OnAllTasksComplete.TerminateJob;

            RequestInterceptor interceptor =
                BatchTestHelpers.CreateFakeServiceResponseInterceptor <JobUpdateParameter, JobUpdateOptions, AzureOperationHeaderResponse <JobUpdateHeaders> >(
                    new AzureOperationHeaderResponse <JobUpdateHeaders>(),
                    request =>
            {
                Assert.Equal((OnAllTasksComplete)request.Parameters.OnAllTasksComplete, OnAllTasksComplete.TerminateJob);
            });

            cmdlet.AdditionalBehaviors = new BatchClientBehavior[] { interceptor };

            // Verify that no exceptions occur
            cmdlet.ExecuteCmdlet();
        }
        public void SetBatchJobParametersGetPassedToRequestTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            cmdlet.Job = new PSCloudJob(BatchTestHelpers.CreateFakeBoundJob(context, new CloudJob(id: "testJob")));

            // Update job
            cmdlet.Job.Constraints     = new PSJobConstraints(TimeSpan.FromHours(1), 5);
            cmdlet.Job.PoolInformation = new PSPoolInformation()
            {
                PoolId = "myPool"
            };
            cmdlet.Job.Priority = 2;
            cmdlet.Job.Metadata = new List <PSMetadataItem>()
            {
                new PSMetadataItem("meta1", "value1"),
                new PSMetadataItem("meta2", "value2")
            };

            JobUpdateParameter requestParameters = null;

            // Store the request parameters
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                JobUpdateParameter,
                JobUpdateOptions,
                AzureOperationHeaderResponse <JobUpdateHeaders> >(requestAction: (r) =>
            {
                requestParameters = r.Parameters;
            });

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

            // Verify the request parameters match the cmdlet parameters
            Assert.Equal(cmdlet.Job.Constraints.MaxTaskRetryCount, requestParameters.Constraints.MaxTaskRetryCount);
            Assert.Equal(cmdlet.Job.Constraints.MaxWallClockTime, requestParameters.Constraints.MaxWallClockTime);
            Assert.Equal(cmdlet.Job.PoolInformation.PoolId, requestParameters.PoolInfo.PoolId);
            Assert.Equal(cmdlet.Job.Priority, requestParameters.Priority);
            Assert.Equal(cmdlet.Job.Metadata.Count, requestParameters.Metadata.Count);
            Assert.Equal(cmdlet.Job.Metadata[0].Name, requestParameters.Metadata[0].Name);
            Assert.Equal(cmdlet.Job.Metadata[0].Value, requestParameters.Metadata[0].Value);
            Assert.Equal(cmdlet.Job.Metadata[1].Name, requestParameters.Metadata[1].Name);
            Assert.Equal(cmdlet.Job.Metadata[1].Value, requestParameters.Metadata[1].Value);
        }
        public void SetBatchJobParametersTest()
        {
            // Setup cmdlet without the required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.Job = new PSCloudJob(BatchTestHelpers.CreateFakeBoundJob(context));

            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudJobUpdateParameters, CloudJobUpdateResponse>();

            cmdlet.AdditionalBehaviors = new BatchClientBehavior[] { interceptor };

            // Verify that no exceptions occur
            cmdlet.ExecuteCmdlet();
        }