コード例 #1
0
        public void ListBatchSubtasksMaxCountTest()
        {
            // Verify default max count
            Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);

            // Setup cmdlet to list Subtasks with a max count
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.JobId        = "job-1";
            cmdlet.TaskId       = "task1";
            int maxCount = 2;

            cmdlet.MaxCount = maxCount;

            int[] idsOfConstructedSubtasks = new[] { 1, 2, 3 };

            // Build some SubtaskInformation objects instead of querying the service on a List Subtasks call
            CloudTaskListSubtasksResponse response    = BatchTestHelpers.CreateCloudTaskListSubtasksResponse(idsOfConstructedSubtasks);
            RequestInterceptor            interceptor = CreateFakeListSubtasksInterceptor(cmdlet.TaskId, response);

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

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

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

            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(idsOfConstructedSubtasks.Length, pipeline.Count);
        }
コード例 #2
0
        public void ListBatchSubtasksWithoutFiltersTest()
        {
            // Setup cmdlet to list Subtasks without filters. Use WorkItemName and JobName.
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.JobId        = "job-1";
            cmdlet.TaskId       = "task1";

            int[] idsOfConstructedSubtasks = new[] { 1, 2, 3 };

            // Build some SubtaskInformation objects instead of querying the service on a List Subtasks call
            CloudTaskListSubtasksResponse response    = BatchTestHelpers.CreateCloudTaskListSubtasksResponse(idsOfConstructedSubtasks);
            RequestInterceptor            interceptor = CreateFakeListSubtasksInterceptor(cmdlet.TaskId, response);

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

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

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

            cmdlet.ExecuteCmdlet();

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

            foreach (PSSubtaskInformation s in pipeline)
            {
                Assert.True(idsOfConstructedSubtasks.Contains(s.Id.Value));
                SubtaskCount++;
            }
            Assert.Equal(idsOfConstructedSubtasks.Length, SubtaskCount);
        }
コード例 #3
0
        public void GetBatchSubtaskParametersTest()
        {
            // Setup cmdlet without required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.JobId        = null;
            cmdlet.TaskId       = null;

            AzureOperationResponse <ProxyModels.CloudTaskListSubtasksResult, ProxyModels.TaskListSubtasksHeaders> response = BatchTestHelpers.CreateCloudTaskListSubtasksResponse();
            // Build a SubtaskInformation instead of querying the service on a List Subtasks call
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                ProxyModels.TaskListSubtasksOptions,
                AzureOperationResponse <ProxyModels.CloudTaskListSubtasksResult,
                                        ProxyModels.TaskListSubtasksHeaders> >(response);

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

            Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.JobId  = "job-1";
            cmdlet.TaskId = "task1";

            // Verify no exceptions occur
            cmdlet.ExecuteCmdlet();
        }