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

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

            cmdlet.BatchContext = context;
            cmdlet.Id           = null;
            cmdlet.Filter       = null;
            int maxCount = 2;

            cmdlet.MaxCount = maxCount;

            string[] idsOfConstructedJobSchedules = new[] { "id1", "id2", "id3" };

            // Build some CloudJobSchedules instead of querying the service on a List CloudJobSchedules call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <CloudJobScheduleListParameters, CloudJobScheduleListResponse> request =
                    (BatchRequest <CloudJobScheduleListParameters, CloudJobScheduleListResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    CloudJobScheduleListResponse response    = BatchTestHelpers.CreateCloudJobScheduleListResponse(idsOfConstructedJobSchedules);
                    Task <CloudJobScheduleListResponse> 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 <PSCloudJobSchedule> pipeline = new List <PSCloudJobSchedule>();

            commandRuntimeMock.Setup(r =>
                                     r.WriteObject(It.IsAny <PSCloudJobSchedule>()))
            .Callback <object>(j => pipeline.Add((PSCloudJobSchedule)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(idsOfConstructedJobSchedules.Length, pipeline.Count);
        }
        public void ListBatchJobScheduleByODataFilterTest()
        {
            // Setup cmdlet to list job schedules using an OData filter
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Id           = null;
            cmdlet.Filter       = "startswith(id,'test')";

            string[] idsOfConstructedJobSchedules = new[] { "test1", "test2" };

            // Build some CloudJobSchedules instead of querying the service on a List CloudJobSchedules call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <CloudJobScheduleListParameters, CloudJobScheduleListResponse> request =
                    (BatchRequest <CloudJobScheduleListParameters, CloudJobScheduleListResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    CloudJobScheduleListResponse response    = BatchTestHelpers.CreateCloudJobScheduleListResponse(idsOfConstructedJobSchedules);
                    Task <CloudJobScheduleListResponse> 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 <PSCloudJobSchedule> pipeline = new List <PSCloudJobSchedule>();

            commandRuntimeMock.Setup(r =>
                                     r.WriteObject(It.IsAny <PSCloudJobSchedule>()))
            .Callback <object>(j => pipeline.Add((PSCloudJobSchedule)j));

            cmdlet.ExecuteCmdlet();

            // Verify that the cmdlet wrote the constructed job schedules to the pipeline
            Assert.Equal(2, pipeline.Count);
            int jobScheduleCount = 0;

            foreach (PSCloudJobSchedule j in pipeline)
            {
                Assert.True(idsOfConstructedJobSchedules.Contains(j.Id));
                jobScheduleCount++;
            }
            Assert.Equal(idsOfConstructedJobSchedules.Length, jobScheduleCount);
        }
        public void ListBatchJobSchedulesWithoutFiltersTest()
        {
            // Setup cmdlet to list job schedules without filters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Id           = null;
            cmdlet.Filter       = null;

            string[] idsOfConstructedJobSchedules = new[] { "id1", "id2", "id3" };

            // Build some CloudJobSchedules instead of querying the service on a List CloudJobSchedules call
            CloudJobScheduleListResponse response    = BatchTestHelpers.CreateCloudJobScheduleListResponse(idsOfConstructedJobSchedules);
            RequestInterceptor           interceptor = BatchTestHelpers.CreateNoOpInterceptor <CloudJobScheduleListParameters, CloudJobScheduleListResponse>(response);

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };

            // Setup the cmdlet to write pipeline output to a list that can be examined later
            List <PSCloudJobSchedule> pipeline = new List <PSCloudJobSchedule>();

            commandRuntimeMock.Setup(r =>
                                     r.WriteObject(It.IsAny <PSCloudJobSchedule>()))
            .Callback <object>(j => pipeline.Add((PSCloudJobSchedule)j));

            cmdlet.ExecuteCmdlet();

            // Verify that the cmdlet wrote the constructed job schedules to the pipeline
            Assert.Equal(3, pipeline.Count);
            int jobScheduleCount = 0;

            foreach (PSCloudJobSchedule j in pipeline)
            {
                Assert.True(idsOfConstructedJobSchedules.Contains(j.Id));
                jobScheduleCount++;
            }
            Assert.Equal(idsOfConstructedJobSchedules.Length, jobScheduleCount);
        }