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

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

            cmdlet.PoolId = "testPool";

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

            cmdlet.Id = "computeNode1";

            // Don't go to the service on a Reboot ComputeNode call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse> request =
                (BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    ComputeNodeRebootResponse response = new ComputeNodeRebootResponse();
                    Task<ComputeNodeRebootResponse> 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 RestartComputeNodeRequestTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            cmdlet.PoolId       = "testPool";
            cmdlet.Id           = "computeNode1";
            cmdlet.RebootOption = ComputeNodeRebootOption.Terminate;

            ComputeNodeRebootOption?requestRebootOption = null;

            // Don't go to the service on a Reboot ComputeNode call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <ComputeNodeRebootParameters, ComputeNodeRebootResponse> request =
                    (BatchRequest <ComputeNodeRebootParameters, ComputeNodeRebootResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    // Grab the reboot option from the outgoing request.
                    requestRebootOption = request.TypedParameters.ComputeNodeRebootOption;

                    ComputeNodeRebootResponse response    = new ComputeNodeRebootResponse();
                    Task <ComputeNodeRebootResponse> task = Task.FromResult(response);
                    return(task);
                };
            });

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

            cmdlet.ExecuteCmdlet();

            // Verify that the reboot option was properly set on the outgoing request
            Assert.Equal(cmdlet.RebootOption, requestRebootOption);
        }
        public void RestartComputeNodeRequestTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
            cmdlet.BatchContext = context;

            cmdlet.PoolId = "testPool";
            cmdlet.Id = "computeNode1";
            cmdlet.RebootOption = ComputeNodeRebootOption.Terminate;

            ComputeNodeRebootOption? requestRebootOption = null;

            // Don't go to the service on a Reboot ComputeNode call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse> request =
                (BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    // Grab the reboot option from the outgoing request.
                    requestRebootOption = request.TypedParameters.ComputeNodeRebootOption;

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

            cmdlet.ExecuteCmdlet();

            // Verify that the reboot option was properly set on the outgoing request
            Assert.Equal(cmdlet.RebootOption, requestRebootOption);
        }