/// <summary> /// Builds a TaskCountsGetResponse object /// </summary> public static AzureOperationResponse <ProxyModels.TaskCounts, ProxyModels.JobGetTaskCountsHeaders> CreateTaskCountsGetResponse( int active, int running, int succeeded, int failed, ProxyModels.TaskCountValidationStatus validationStatus) { var response = new AzureOperationResponse <ProxyModels.TaskCounts, ProxyModels.JobGetTaskCountsHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); ProxyModels.TaskCounts taskCounts = new ProxyModels.TaskCounts(); taskCounts.Active = active; taskCounts.Running = running; taskCounts.Succeeded = succeeded; taskCounts.Failed = failed; taskCounts.Completed = succeeded + failed; taskCounts.ValidationStatus = validationStatus; response.Body = taskCounts; return(response); }
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 active = 3; const int running = 5; const int succeeded = 2; const int failed = 1; const ProxyModels.TaskCountValidationStatus validationStatus = ProxyModels.TaskCountValidationStatus.Validated; // Build a TaskCounts instead of querying the service on a Get TaskCounts call AzureOperationResponse <ProxyModels.TaskCounts, ProxyModels.JobGetTaskCountsHeaders> response = BatchTestHelpers.CreateTaskCountsGetResponse(active, running, succeeded, failed, validationStatus); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.JobGetTaskCountsOptions, AzureOperationResponse <ProxyModels.TaskCounts, 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(active, taskCounts.Active); Assert.Equal(running, taskCounts.Running); Assert.Equal(succeeded + failed, taskCounts.Completed); Assert.Equal(succeeded, taskCounts.Succeeded); Assert.Equal(failed, taskCounts.Failed); Assert.Equal(validationStatus.ToString(), taskCounts.ValidationStatus.ToString()); }