public void ListTasksMaxCountTest()
        {
            // Verify default max count
            Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);

            // Setup cmdlet to list Tasks without filters and a max count
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.WorkItemName = "workItem";
            cmdlet.JobName      = "job-0000000001";
            cmdlet.Name         = null;
            cmdlet.Filter       = null;
            int maxCount = 2;

            cmdlet.MaxCount = maxCount;

            string[] namesOfConstructedTasks = new[] { "testTask1", "testTask2", "testTask3" };

            // Build some Tasks instead of querying the service on a ListTasks call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is ListTasksRequest)
                {
                    ListTasksResponse response = BatchTestHelpers.CreateListTasksResponse(namesOfConstructedTasks);
                    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 <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 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(namesOfConstructedTasks.Length, pipeline.Count);
        }
        public void ListBatchTasksByODataFilterTest()
        {
            // Setup cmdlet to list Tasks using an OData filter. Use WorkItemName and JobName input.
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.WorkItemName = "workItem";
            cmdlet.JobName      = "job-0000000001";
            cmdlet.Name         = null;
            cmdlet.Filter       = "startswith(name,'test')";

            string[] namesOfConstructedTasks = new[] { "testTask1", "testTask2" };

            // Build some Tasks instead of querying the service on a ListTasks call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is ListTasksRequest)
                {
                    ListTasksResponse response = BatchTestHelpers.CreateListTasksResponse(namesOfConstructedTasks);
                    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 <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 constructed Tasks to the pipeline
            Assert.Equal(2, pipeline.Count);
            int taskCount = 0;

            foreach (PSCloudTask t in pipeline)
            {
                Assert.True(namesOfConstructedTasks.Contains(t.Name));
                taskCount++;
            }
            Assert.Equal(namesOfConstructedTasks.Length, taskCount);
        }