public void ListJobsMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list jobs without filters and a max count BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobScheduleId = "jobSchedule"; cmdlet.Id = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] idsOfConstructedJobs = new[] { "job-1", "job-2", "job-3" }; // Build some CloudJobs instead of querying the service on a List CloudJobs call RequestInterceptor interceptor = new RequestInterceptor((baseRequest) => { BatchRequest <CloudJobListParameters, CloudJobListResponse> request = (BatchRequest <CloudJobListParameters, CloudJobListResponse>)baseRequest; request.ServiceRequestFunc = (cancellationToken) => { CloudJobListResponse response = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs); Task <CloudJobListResponse> task = Task.FromResult(response); return(task); }; }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudJob> pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())) .Callback <object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the max count was respected Assert.Equal(maxCount, pipeline.Count); // Verify setting max count <= 0 doesn't return nothing cmdlet.MaxCount = -5; pipeline.Clear(); cmdlet.ExecuteCmdlet(); Assert.Equal(idsOfConstructedJobs.Length, pipeline.Count); }
public void ListBatchJobsByODataFilterTest() { // Setup cmdlet to list jobs using an OData filter. Use JobScheduleId input. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobScheduleId = "jobSchedule"; cmdlet.Id = null; cmdlet.Filter = "state -eq 'active'"; string[] idsOfConstructedJobs = new[] { "job-1", "job-2" }; // Build some CloudJobs instead of querying the service on a List CloudJobs call RequestInterceptor interceptor = new RequestInterceptor((baseRequest) => { BatchRequest <CloudJobListParameters, CloudJobListResponse> request = (BatchRequest <CloudJobListParameters, CloudJobListResponse>)baseRequest; request.ServiceRequestFunc = (cancellationToken) => { CloudJobListResponse response = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs); Task <CloudJobListResponse> task = Task.FromResult(response); return(task); }; }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudJob> pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())) .Callback <object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed jobs to the pipeline Assert.Equal(2, pipeline.Count); int jobCount = 0; foreach (PSCloudJob j in pipeline) { Assert.True(idsOfConstructedJobs.Contains(j.Id)); jobCount++; } Assert.Equal(idsOfConstructedJobs.Length, jobCount); }
public void ListBatchJobsWithoutFiltersTest() { // Setup cmdlet to list jobs without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobScheduleId = "jobSchedule"; cmdlet.Id = null; cmdlet.Filter = null; string[] idsOfConstructedJobs = new[] { "job-1", "job-2", "job-3" }; // Build some CloudJobs instead of querying the service on a List CloudJobs call CloudJobListResponse response = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs); RequestInterceptor interceptor = BatchTestHelpers.CreateNoOpInterceptor <CloudJobListParameters, CloudJobListResponse>(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudJob> pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())) .Callback <object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed jobs to the pipeline Assert.Equal(3, pipeline.Count); int jobCount = 0; foreach (PSCloudJob j in pipeline) { Assert.True(idsOfConstructedJobs.Contains(j.Id)); jobCount++; } Assert.Equal(idsOfConstructedJobs.Length, jobCount); }
public void ListJobsMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list jobs without filters and a max count BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobScheduleId = null; cmdlet.Id = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] idsOfConstructedJobs = new[] { "job-1", "job-2", "job-3" }; // Build some CloudJobs instead of querying the service on a List CloudJobs call AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListHeaders> response = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.JobListOptions, AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudJob> pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())) .Callback <object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the max count was respected Assert.Equal(maxCount, pipeline.Count); // Verify setting max count <= 0 doesn't return nothing cmdlet.MaxCount = -5; pipeline.Clear(); cmdlet.ExecuteCmdlet(); Assert.Equal(idsOfConstructedJobs.Length, pipeline.Count); }