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

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

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

            cmdlet.MaxCount = maxCount;

            string[] namesOfConstructedWorkItems = new[] { "name1", "name2", "name3" };

            // Build some WorkItems instead of querying the service on a ListWorkItems call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is ListWorkItemsRequest)
                {
                    ListWorkItemsResponse response = BatchTestHelpers.CreateListWorkItemsResponse(namesOfConstructedWorkItems);
                    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 <PSCloudWorkItem> pipeline = new List <PSCloudWorkItem>();

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

            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(namesOfConstructedWorkItems.Length, pipeline.Count);
        }
        public void ListBatchWorkItemByODataFilterTest()
        {
            // Setup cmdlet to list WorkItems using an OData filter
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Name         = null;
            cmdlet.Filter       = "startswith(name,'test')";

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

            // Build some WorkItems instead of querying the service on a ListWorkItems call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is ListWorkItemsRequest)
                {
                    ListWorkItemsResponse response = BatchTestHelpers.CreateListWorkItemsResponse(namesOfConstructedWorkItems);
                    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 <PSCloudWorkItem> pipeline = new List <PSCloudWorkItem>();

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

            cmdlet.ExecuteCmdlet();

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

            foreach (PSCloudWorkItem w in pipeline)
            {
                Assert.True(namesOfConstructedWorkItems.Contains(w.Name));
                workItemCount++;
            }
            Assert.Equal(namesOfConstructedWorkItems.Length, workItemCount);
        }
예제 #3
0
        /// <summary>
        /// Builds a ListWorkItemsResponse object
        /// </summary>
        public static ListWorkItemsResponse CreateListWorkItemsResponse(IEnumerable <string> workItemNames)
        {
            ListWorkItemsResponse response = new ListWorkItemsResponse();

            SetProperty(response, "StatusCode", HttpStatusCode.OK);

            List <WorkItem>         workItems = new List <WorkItem>();
            JobExecutionEnvironment jee       = new JobExecutionEnvironment();

            foreach (string name in workItemNames)
            {
                workItems.Add(new WorkItem(name, jee));
            }

            SetProperty(response, "WorkItems", workItems);

            return(response);
        }
예제 #4
0
        /// <summary>
        /// Builds a ListWorkItemsResponse object
        /// </summary>
        public static ListWorkItemsResponse CreateListWorkItemsResponse(IEnumerable<string> workItemNames)
        {
            ListWorkItemsResponse response = new ListWorkItemsResponse();
            SetProperty(response, "StatusCode", HttpStatusCode.OK);

            List<WorkItem> workItems = new List<WorkItem>();
            JobExecutionEnvironment jee = new JobExecutionEnvironment();

            foreach (string name in workItemNames)
            {
                workItems.Add(new WorkItem(name, jee));
            }

            SetProperty(response, "WorkItems", workItems);

            return response;
        }