public void DisableJobParametersTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
            cmdlet.BatchContext = context;
            cmdlet.Id = null;

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

            cmdlet.Id = "testJob";
            cmdlet.DisableJobOption = DisableJobOption.Terminate;

            // Don't go to the service on a Disable CloudJob call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse> request =
                (BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    CloudJobDisableResponse response = new CloudJobDisableResponse();
                    Task<CloudJobDisableResponse> task = Task.FromResult(response);
                    return task;
                };
            });
            cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

            // Verify no exceptions when required parameter is set
            cmdlet.ExecuteCmdlet();
        }
Ejemplo n.º 2
0
        public void DisableJobRequestTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            DisableJobOption disableOption        = DisableJobOption.Terminate;
            DisableJobOption requestDisableOption = DisableJobOption.Requeue;

            cmdlet.Id = "testJob";
            cmdlet.DisableJobOption = disableOption;

            // Don't go to the service on an Enable AutoScale call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <CloudJobDisableParameters, CloudJobDisableResponse> request =
                    (BatchRequest <CloudJobDisableParameters, CloudJobDisableResponse>)baseRequest;

                // Grab the disable option off the outgoing request.
                requestDisableOption = request.TypedParameters.DisableJobOption;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    CloudJobDisableResponse response    = new CloudJobDisableResponse();
                    Task <CloudJobDisableResponse> task = Task.FromResult(response);
                    return(task);
                };
            });

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

            cmdlet.ExecuteCmdlet();

            // Verify that the job disable option was properly set on the outgoing request
            Assert.Equal(disableOption, requestDisableOption);
        }
        public void DisableJobRequestTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
            cmdlet.BatchContext = context;

            DisableJobOption disableOption = DisableJobOption.Terminate;
            DisableJobOption requestDisableOption = DisableJobOption.Requeue;

            cmdlet.Id = "testJob";
            cmdlet.DisableJobOption = disableOption;

            // Don't go to the service on an Enable AutoScale call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse> request =
                (BatchRequest<CloudJobDisableParameters, CloudJobDisableResponse>)baseRequest;

                requestDisableOption = request.TypedParameters.DisableJobOption;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    CloudJobDisableResponse response = new CloudJobDisableResponse();
                    Task<CloudJobDisableResponse> task = Task.FromResult(response);
                    return task;
                };
            });
            cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

            cmdlet.ExecuteCmdlet();

            // Verify that the job disable option was properly set on the outgoing request
            Assert.Equal(disableOption, requestDisableOption);
        }