public override void ExecuteCmdlet() { GetTaskCountsOptions options = new GetTaskCountsOptions(this.BatchContext, this.JobId, this.Job, this.AdditionalBehaviors); PSTaskCounts taskCounts = BatchClient.GetTaskCounts(options); WriteObject(taskCounts); }
public void GetBatchTaskCountsTest() { // Setup cmdlet to get task counts by job id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "job-1"; const int requiredSlots = 2; const int active = 3; const int running = 5; const int succeeded = 2; const int failed = 1; // Build a TaskCounts instead of querying the service on a Get TaskCounts call AzureOperationResponse <ProxyModels.TaskCountsResult, ProxyModels.JobGetTaskCountsHeaders> response = BatchTestHelpers.CreateTaskCountsGetResponse(requiredSlots, active, running, succeeded, failed); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.JobGetTaskCountsOptions, AzureOperationResponse <ProxyModels.TaskCountsResult, ProxyModels.JobGetTaskCountsHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later PSTaskCounts taskCounts = null; commandRuntimeMock .Setup(r => r.WriteObject(It.IsAny <PSTaskCounts>())) .Callback <object>(p => { taskCounts = (PSTaskCounts)p; }); cmdlet.ExecuteCmdlet(); Assert.Equal(3, taskCounts.Active); Assert.Equal(5, taskCounts.Running); Assert.Equal(3, taskCounts.Completed); Assert.Equal(2, taskCounts.Succeeded); Assert.Equal(1, taskCounts.Failed); }