public void GetBatchTaskTest()
        {
            // Setup cmdlet to get a task by id
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.JobId        = "job-1";
            cmdlet.Id           = "task1";
            cmdlet.Filter       = null;

            // Build a CloudTask instead of querying the service on a Get CloudTask call
            CloudTaskGetResponse response    = BatchTestHelpers.CreateCloudTaskGetResponse(cmdlet.Id);
            RequestInterceptor   interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudTaskGetParameters, CloudTaskGetResponse>(response);

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

            // Setup the cmdlet to write pipeline output to a list that can be examined later
            List <PSCloudTask> 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);
        }
        // TO DO: Since we have to fetch the task, the interceptor needs to handle that case too. Once
        // the cmdlet can directly call the List Subtasks method by itself, update these test cases to
        // use the generic interceptor creation helper.
        private RequestInterceptor CreateFakeListSubtasksInterceptor(string taskId, CloudTaskListSubtasksResponse listSubtasksResponse)
        {
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <CloudTaskListSubtasksParameters, CloudTaskListSubtasksResponse> listSubtaskRequest = baseRequest as
                                                                                                                   BatchRequest <CloudTaskListSubtasksParameters, CloudTaskListSubtasksResponse>;

                if (listSubtaskRequest != null)
                {
                    listSubtaskRequest.ServiceRequestFunc = (cancellationToken) =>
                    {
                        Task <CloudTaskListSubtasksResponse> task = Task.FromResult(listSubtasksResponse);
                        return(task);
                    };
                }
                else
                {
                    BatchRequest <CloudTaskGetParameters, CloudTaskGetResponse> getTaskRequest =
                        (BatchRequest <CloudTaskGetParameters, CloudTaskGetResponse>)baseRequest;

                    getTaskRequest.ServiceRequestFunc = (cancellationToken) =>
                    {
                        CloudTaskGetResponse response    = BatchTestHelpers.CreateCloudTaskGetResponse(taskId);
                        Task <CloudTaskGetResponse> task = Task.FromResult(response);
                        return(task);
                    };
                }
            });

            return(interceptor);
        }
        public void GetBatchTaskODataTest()
        {
            // Setup cmdlet to get a single task
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.JobId        = "testJob";
            cmdlet.Id           = "testTask1";
            cmdlet.Select       = "id,state";
            cmdlet.Expand       = "stats";

            string requestSelect = null;
            string requestExpand = null;

            // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
            CloudTaskGetResponse getResponse         = BatchTestHelpers.CreateCloudTaskGetResponse(cmdlet.Id);
            RequestInterceptor   requestInterceptor  = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudTaskGetParameters, CloudTaskGetResponse>(getResponse);
            ResponseInterceptor  responseInterceptor = new ResponseInterceptor((response, request) =>
            {
                requestSelect = request.Parameters.DetailLevel.SelectClause;
                requestExpand = request.Parameters.DetailLevel.ExpandClause;

                return(Task.FromResult(response));
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                requestInterceptor, responseInterceptor
            };

            cmdlet.ExecuteCmdlet();

            Assert.Equal(cmdlet.Select, requestSelect);
            Assert.Equal(cmdlet.Expand, requestExpand);
        }