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.WorkItem = BatchTestHelpers.CreatePSCloudWorkItem(); cmdlet.Name = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] namesOfConstructedJobs = new[] { "job-0000000001", "job-0000000002", "job-0000000003" }; // Build some Jobs instead of querying the service on a ListJobs call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is ListJobsRequest) { ListJobsResponse response = BatchTestHelpers.CreateListJobsResponse(namesOfConstructedJobs); Task <object> task = Task <object> .Factory.StartNew(() => { return(response); }); return(task); } return(null); }); 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(namesOfConstructedJobs.Length, pipeline.Count); }
public void ListBatchJobsByODataFilterTest() { // Setup cmdlet to list Jobs using an OData filter. Use WorkItemName input. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.WorkItemName = "workItem"; cmdlet.Name = null; cmdlet.Filter = "state -eq 'active'"; string[] namesOfConstructedJobs = new[] { "job-0000000001", "job-0000000002" }; // Build some Jobs instead of querying the service on a ListJobs call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is ListJobsRequest) { ListJobsResponse response = BatchTestHelpers.CreateListJobsResponse(namesOfConstructedJobs); Task <object> task = Task <object> .Factory.StartNew(() => { return(response); }); return(task); } return(null); }); 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(namesOfConstructedJobs.Contains(j.Name)); jobCount++; } Assert.Equal(namesOfConstructedJobs.Length, jobCount); }