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.JobId = "job-1"; cmdlet.Id = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] idsOfConstructedTasks = new[] { "testTask1", "testTask2", "testTask3" }; // Build some CloudTasks instead of querying the service on a List CloudTasks call AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> response = BatchTestHelpers.CreateCloudTaskListResponse(idsOfConstructedTasks); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.TaskListOptions, AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> >(response); 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(idsOfConstructedTasks.Length, pipeline.Count); }
public void ListCertificatesMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list pools without filters and a max count BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.ThumbprintAlgorithm = null; cmdlet.Thumbprint = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] thumbprintsOfConstructedCerts = new[] { "12345", "67890", "ABCDE" }; // Build some Certificates instead of querying the service on a List Certificates call AzureOperationResponse <IPage <ProxyModels.Certificate>, ProxyModels.CertificateListHeaders> response = BatchTestHelpers.CreateCertificateListResponse(thumbprintsOfConstructedCerts); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.CertificateListOptions, AzureOperationResponse <IPage <ProxyModels.Certificate>, ProxyModels.CertificateListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCertificate> pipeline = new List <PSCertificate>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCertificate>())) .Callback <object>(c => pipeline.Add((PSCertificate)c)); 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(thumbprintsOfConstructedCerts.Length, pipeline.Count); }
public void ListBatchSubtasksMaxCountTest() { // Verify default max count Assert.Equal(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 AzureOperationResponse <ProxyModels.CloudTaskListSubtasksResult, ProxyModels.TaskListSubtasksHeaders> response = BatchTestHelpers.CreateCloudTaskListSubtasksResponse(idsOfConstructedSubtasks); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.TaskListSubtasksOptions, AzureOperationResponse <ProxyModels.CloudTaskListSubtasksResult, ProxyModels.TaskListSubtasksHeaders> >(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); }
public void ListNodeFilesByComputeNodeMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list vm files and a max count. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "pool"; cmdlet.ComputeNodeId = "computeNode1"; cmdlet.Name = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] namesOfConstructedNodeFiles = new[] { "startup", "workitems", "shared" }; // Build some NodeFiles instead of querying the service on a List NodeFiles call NodeFileListResponse response = BatchTestHelpers.CreateNodeFileListResponse(namesOfConstructedNodeFiles); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <NodeFileListParameters, NodeFileListResponse>(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeFile> pipeline = new List <PSNodeFile>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeFile>())) .Callback <object>(f => pipeline.Add((PSNodeFile)f)); 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(namesOfConstructedNodeFiles.Length, pipeline.Count); }
public void SetBatchJobParametersGetPassedToRequestTest() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Job = new PSCloudJob(BatchTestHelpers.CreateFakeBoundJob(context, new CloudJob(id: "testJob"))); // Update job cmdlet.Job.Constraints = new PSJobConstraints(TimeSpan.FromHours(1), 5); cmdlet.Job.PoolInformation = new PSPoolInformation() { PoolId = "myPool" }; cmdlet.Job.Priority = 2; cmdlet.Job.Metadata = new Dictionary <string, string>() { { "meta1", "value1" }, { "meta2", "value2" } }; JobUpdateParameter requestParameters = null; // Store the request parameters RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < JobUpdateParameter, JobUpdateOptions, AzureOperationHeaderResponse <JobUpdateHeaders> >(requestAction: (r) => { requestParameters = r.Parameters; }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; cmdlet.ExecuteCmdlet(); // Verify the request parameters match the cmdlet parameters Assert.Equal(cmdlet.Job.Constraints.MaxTaskRetryCount, requestParameters.Constraints.MaxTaskRetryCount); Assert.Equal(cmdlet.Job.Constraints.MaxWallClockTime, requestParameters.Constraints.MaxWallClockTime); Assert.Equal(cmdlet.Job.PoolInformation.PoolId, requestParameters.PoolInfo.PoolId); Assert.Equal(cmdlet.Job.Priority, requestParameters.Priority); Assert.Equal(cmdlet.Job.Metadata.Count, requestParameters.Metadata.Count); Assert.Contains(requestParameters.Metadata, p => p.Name == "meta1" && p.Value == cmdlet.Job.Metadata["meta1"].ToString()); Assert.Contains(requestParameters.Metadata, p => p.Name == "meta2" && p.Value == cmdlet.Job.Metadata["meta2"].ToString()); }
public void ListBatchNodeFilesByComputeNodeWithoutFiltersTest() { // Setup cmdlet to list vm files without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "pool"; cmdlet.ComputeNodeId = "computeNode1"; cmdlet.Path = null; cmdlet.Filter = null; string[] namesOfConstructedNodeFiles = new[] { "startup", "workitems", "shared" }; // Build some NodeFiles instead of querying the service on a List NodeFiles call AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromComputeNodeHeaders> response = BatchTestHelpers.CreateNodeFileListByComputeNodeResponse(namesOfConstructedNodeFiles); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < bool?, ProxyModels.FileListFromComputeNodeOptions, AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromComputeNodeHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeFile> pipeline = new List <PSNodeFile>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeFile>())) .Callback <object>(f => pipeline.Add((PSNodeFile)f)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed node files to the pipeline Assert.Equal(3, pipeline.Count); int taskCount = 0; foreach (PSNodeFile f in pipeline) { Assert.Contains(f.Path, namesOfConstructedNodeFiles); taskCount++; } Assert.Equal(namesOfConstructedNodeFiles.Length, taskCount); }
public void ListBatchNodeFilesByTaskByODataFilterTest() { // Setup cmdlet to list node files using an OData filter. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "job-1"; cmdlet.TaskId = "task"; cmdlet.Name = null; cmdlet.Filter = "startswith(name,'std')"; string[] namesOfConstructedNodeFiles = new[] { "stdout.txt", "stderr.txt" }; // Build some NodeFiles instead of querying the service on a List NodeFiles call AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> response = BatchTestHelpers.CreateNodeFileListByTaskResponse(namesOfConstructedNodeFiles); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < bool?, ProxyModels.FileListFromTaskOptions, AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeFile> pipeline = new List <PSNodeFile>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeFile>())) .Callback <object>(f => pipeline.Add((PSNodeFile)f)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed node files to the pipeline Assert.Equal(2, pipeline.Count); int taskCount = 0; foreach (PSNodeFile f in pipeline) { Assert.True(namesOfConstructedNodeFiles.Contains(f.Name)); taskCount++; } Assert.Equal(namesOfConstructedNodeFiles.Length, taskCount); }
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.JobScheduleId = "jobSchedule"; cmdlet.Id = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] idsOfConstructedJobs = new[] { "job-1", "job-2", "job-3" }; // Build some CloudJobs instead of querying the service on a List CloudJobs call CloudJobListResponse response = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudJobListParameters, CloudJobListResponse>(response); 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(idsOfConstructedJobs.Length, pipeline.Count); }
public void ListBatchComputeNodesWithoutFiltersTest() { // Setup cmdlet to list compute nodes without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.Id = null; cmdlet.Filter = null; string[] idsOfConstructedComputeNodes = new[] { "computeNode1", "computeNode2", "computeNode3" }; // Build some compute nodes instead of querying the service on a List ComputeNodes call AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> response = BatchTestHelpers.CreateComputeNodeListResponse(idsOfConstructedComputeNodes); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeListOptions, AzureOperationResponse <IPage <ProxyModels.ComputeNode>, ProxyModels.ComputeNodeListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSComputeNode> pipeline = new List <PSComputeNode>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSComputeNode>())) .Callback <object>(c => pipeline.Add((PSComputeNode)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed compute nodes to the pipeline Assert.Equal(3, pipeline.Count); int computeNodeCount = 0; foreach (PSComputeNode c in pipeline) { Assert.Contains(c.Id, idsOfConstructedComputeNodes); computeNodeCount++; } Assert.Equal(idsOfConstructedComputeNodes.Length, computeNodeCount); }
public void SetBatchJobScheduleParametersTest() { // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.JobSchedule = new PSCloudJobSchedule(BatchTestHelpers.CreateFakeBoundJobSchedule(context)); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudJobScheduleUpdateParameters, CloudJobScheduleUpdateResponse>(); cmdlet.AdditionalBehaviors = new BatchClientBehavior[] { interceptor }; // Verify that no exceptions occur cmdlet.ExecuteCmdlet(); }
public void ListBatchTasksODataTest() { // Setup cmdlet to list tasks using an OData filter BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "testJob"; cmdlet.Id = null; cmdlet.Filter = "startswith(id,'test')"; cmdlet.Select = "id,state"; cmdlet.Expand = "stats"; string requestFilter = null; string requestSelect = null; string requestExpand = null; AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> response = BatchTestHelpers.CreateGenericAzureOperationListResponse <ProxyModels.CloudTask, ProxyModels.TaskListHeaders>(); Action <BatchRequest <ProxyModels.TaskListOptions, AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> > > extractTaskListAction = (request) => { ProxyModels.TaskListOptions options = request.Options; requestFilter = options.Filter; requestSelect = options.Select; requestExpand = options.Expand; }; RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor(responseToUse: response, requestAction: extractTaskListAction); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor }; cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); Assert.Equal(cmdlet.Select, requestSelect); Assert.Equal(cmdlet.Expand, requestExpand); }
public void GetBatchComputeNodeExtensionTest() { string extensionName = "testExtension"; string publisher = "testPublisher"; string type = "testType"; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.Name = extensionName; VMExtension extension = new VMExtension(extensionName, publisher, type); // Build an extension instead of querying the service on a Get ComputeNodeExtension call AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionGetOptions, AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeVMExtension> pipeline = new List <PSNodeVMExtension>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeVMExtension>())).Callback <object>(c => pipeline.Add((PSNodeVMExtension)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the compute node returned from the OM to the pipeline Assert.Single(pipeline); PSVMExtension pipelineExtension = pipeline[0].VmExtension; Assert.NotNull(pipelineExtension); Assert.Equal("testExtension", pipelineExtension.Name); Assert.Equal("testPublisher", pipelineExtension.Publisher); Assert.Equal("testType", pipelineExtension.Type); }
public void GetBatchTaskCountsTest() { // Setup cmdlet to get task counts by job id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "job-1"; const int requiredSlots = 2; const int active = 3; const int running = 5; const int succeeded = 2; const int failed = 1; // Build a TaskCounts instead of querying the service on a Get TaskCounts call AzureOperationResponse <ProxyModels.TaskCountsResult, ProxyModels.JobGetTaskCountsHeaders> response = BatchTestHelpers.CreateTaskCountsGetResponse(requiredSlots, active, running, succeeded, failed); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.JobGetTaskCountsOptions, AzureOperationResponse <ProxyModels.TaskCountsResult, ProxyModels.JobGetTaskCountsHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later PSTaskCounts taskCounts = null; commandRuntimeMock .Setup(r => r.WriteObject(It.IsAny <PSTaskCounts>())) .Callback <object>(p => { taskCounts = (PSTaskCounts)p; }); cmdlet.ExecuteCmdlet(); Assert.Equal(3, taskCounts.Active); Assert.Equal(5, taskCounts.Running); Assert.Equal(3, taskCounts.Completed); Assert.Equal(2, taskCounts.Succeeded); Assert.Equal(1, taskCounts.Failed); }
public void WhenGettingATaskFromTheService_ApplicationPackageReferencesAreMapped() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-1"; cmdlet.JobId = "job-1"; cmdlet.Filter = null; // Build a CloudTask instead of querying the service on a Get CloudTask call string applicationId = "foo"; string applicationVersion = "beta"; ProxyModels.CloudTask cloudTask = new ProxyModels.CloudTask { Id = "task-1", ApplicationPackageReferences = new[] { new ProxyModels.ApplicationPackageReference(applicationId, applicationVersion) } }; AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> response = BatchTestHelpers.CreateCloudTaskGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.TaskGetOptions, AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior> { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var 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 task returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); var psApplicationPackageReference = pipeline[0].ApplicationPackageReferences.First(); Assert.Equal(applicationId, psApplicationPackageReference.ApplicationId); Assert.Equal(applicationVersion, psApplicationPackageReference.Version); }
public void GetBatchPoolUsageWithFilter() { int year = 2013; int month = 4; int day = 1; BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Filter = "poolId lt 'p2'"; string requestFilter = null; string[] poolIds = new[] { "p1" }; DateTime[] startTimes = new[] { new DateTime(year, month, day, 0, 0, 0) }; DateTime[] endTimes = new[] { new DateTime(year, month, day, 0, 30, 0) }; AzureOperationResponse <IPage <ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListUsageMetricsHeaders> response = BatchTestHelpers.CreatePoolListUsageMetricsResponse(poolIds, startTimes, endTimes); // Don't go to the service on an Get PoolUsageMetrics call RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.PoolListUsageMetricsOptions, AzureOperationResponse <IPage <ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListUsageMetricsHeaders> >(responseToUse: response); ResponseInterceptor responseInterceptor = new ResponseInterceptor((responseToUse, request) => { ProxyModels.PoolListUsageMetricsOptions options = (ProxyModels.PoolListUsageMetricsOptions)request.Options; requestFilter = options.Filter; return(Task.FromResult(responseToUse)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; // Verify no exceptions when required parameter is set cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); }
public void ListBatchTasksWithoutFiltersTest() { // Setup cmdlet to list tasks without filters. Use WorkItemName and JobName. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "job-1"; cmdlet.Id = null; cmdlet.Filter = null; string[] idsOfConstructedTasks = new[] { "testTask1", "testTask2", "testTask3" }; // Build some CloudTasks instead of querying the service on a List CloudTasks call AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> response = BatchTestHelpers.CreateCloudTaskListResponse(idsOfConstructedTasks); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.TaskListOptions, AzureOperationResponse <IPage <ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> >(response); 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(3, pipeline.Count); int taskCount = 0; foreach (PSCloudTask t in pipeline) { Assert.True(idsOfConstructedTasks.Contains(t.Id)); taskCount++; } Assert.Equal(idsOfConstructedTasks.Length, taskCount); }
public void ApplicationPackageReferencesAreSentOnATask() { // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.Id = "task-id"; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.JobId = "job-id"; string applicationId = "foo"; string applicationVersion = "beta"; cmdlet.ApplicationPackageReferences = new[] { new PSApplicationPackageReference { ApplicationId = applicationId, Version = applicationVersion }, }; // Don't go to the service on an Add CloudJob call RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <TaskAddParameter, TaskAddOptions, AzureOperationHeaderResponse <TaskAddHeaders> >( new AzureOperationHeaderResponse <TaskAddHeaders>(), request => { var applicationPackageReference = request.Parameters.ApplicationPackageReferences.First(); Assert.Equal(applicationId, applicationPackageReference.ApplicationId); Assert.Equal(applicationVersion, applicationPackageReference.Version); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Verify no exceptions when required parameters are set cmdlet.ExecuteCmdlet(); }
public void ListBatchCertificatesWithoutFiltersTest() { // Setup cmdlet to list certs without filters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.ThumbprintAlgorithm = null; cmdlet.Thumbprint = null; cmdlet.Filter = null; string[] thumbprintsOfConstructedCerts = new[] { "12345", "67890", "ABCDE" }; // Build some Certificates instead of querying the service on a List Certificates call AzureOperationResponse <IPage <ProxyModels.Certificate>, ProxyModels.CertificateListHeaders> response = BatchTestHelpers.CreateCertificateListResponse(thumbprintsOfConstructedCerts); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.CertificateListOptions, AzureOperationResponse <IPage <ProxyModels.Certificate>, ProxyModels.CertificateListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCertificate> pipeline = new List <PSCertificate>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCertificate>())) .Callback <object>(c => pipeline.Add((PSCertificate)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed certs to the pipeline Assert.Equal(3, pipeline.Count); int poolCount = 0; foreach (PSCertificate c in pipeline) { Assert.True(thumbprintsOfConstructedCerts.Contains(c.Thumbprint)); poolCount++; } Assert.Equal(thumbprintsOfConstructedCerts.Length, poolCount); }
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 AzureOperationResponse <ProxyModels.CloudTaskListSubtasksResult, ProxyModels.TaskListSubtasksHeaders> response = BatchTestHelpers.CreateCloudTaskListSubtasksResponse(idsOfConstructedSubtasks); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.TaskListSubtasksOptions, AzureOperationResponse <ProxyModels.CloudTaskListSubtasksResult, ProxyModels.TaskListSubtasksHeaders> >(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.Contains(s.Id.Value, idsOfConstructedSubtasks); SubtaskCount++; } Assert.Equal(idsOfConstructedSubtasks.Length, SubtaskCount); }
public void OutputFilesAreSentToService() { // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-id"; cmdlet.JobId = "job-id"; const string pattern = @"**\*.txt"; const string containerUrl = "containerUrl"; const string path = "path"; const OutputFileUploadCondition uploadCondition = OutputFileUploadCondition.TaskCompletion; cmdlet.OutputFile = new[] { new PSOutputFile( pattern, new PSOutputFileDestination(new PSOutputFileBlobContainerDestination(containerUrl, path)), new PSOutputFileUploadOptions(uploadCondition)) }; // Don't go to the service on an Add CloudJob call RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <TaskAddParameter, TaskAddOptions, AzureOperationHeaderResponse <TaskAddHeaders> >( new AzureOperationHeaderResponse <TaskAddHeaders>(), request => { var outputFile = request.Parameters.OutputFiles.Single(); Assert.Equal(pattern, outputFile.FilePattern); Assert.Equal(containerUrl, outputFile.Destination.Container.ContainerUrl); Assert.Equal(path, outputFile.Destination.Container.Path); Assert.Equal(uploadCondition.ToString().ToLowerInvariant(), outputFile.UploadOptions.UploadCondition.ToString().ToLowerInvariant()); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Verify no exceptions when required parameters are set cmdlet.ExecuteCmdlet(); }
public void ListBatchPoolWithoutFiltersTest() { // Setup cmdlet to list pools without filters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = null; cmdlet.Filter = null; string[] idsOfConstructedPools = new[] { "pool1", "pool2", "pool3" }; // Build some CloudPools instead of querying the service on a List CloudPools call AzureOperationResponse <IPage <ProxyModels.CloudPool>, ProxyModels.PoolListHeaders> response = BatchTestHelpers.CreateCloudPoolListResponse(idsOfConstructedPools); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.PoolListOptions, AzureOperationResponse <IPage <ProxyModels.CloudPool>, ProxyModels.PoolListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudPool> pipeline = new List <PSCloudPool>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())) .Callback <object>(p => pipeline.Add((PSCloudPool)p)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed pools to the pipeline Assert.Equal(3, pipeline.Count); int poolCount = 0; foreach (PSCloudPool p in pipeline) { Assert.True(idsOfConstructedPools.Contains(p.Id)); poolCount++; } Assert.Equal(idsOfConstructedPools.Length, poolCount); }
public void ListBatchComputeNodeExtensionsWithMaxCountTest() { int maxCount = 3; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.MaxCount = maxCount; int count = 5; // Build an extension instead of querying the service on a Get ComputeNodeExtension call AzureOperationResponse <IPage <ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionListResponse(CreateTestExtensions(count)); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionListOptions, AzureOperationResponse <IPage <ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeVMExtension> pipeline = new List <PSNodeVMExtension>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeVMExtension>())).Callback <object>(c => pipeline.Add((PSNodeVMExtension)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the compute node returned from the OM to the pipeline Assert.Equal(maxCount, pipeline.Count); for (int i = 1; i <= maxCount; i++) { PSVMExtension extension = pipeline[i - 1].VmExtension; Assert.Equal($"testExtension{i}", extension.Name); Assert.Equal($"testPublisher{i}", extension.Publisher); Assert.Equal($"testType{i}", extension.Type); } }
public void GetBatchComputeNodeExtensionODataTest() { string extensionName = "testExtension"; string publisher = "testPublisher"; string type = "testType"; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.Name = extensionName; cmdlet.Select = "ExtensionName,Publisher"; VMExtension extension = new VMExtension(extensionName, publisher, type); // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> getResponse = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionGetOptions, AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> >(getResponse); string requestSelect = null; ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.ComputeNodeExtensionGetOptions options = (ProxyModels.ComputeNodeExtensionGetOptions)request.Options; requestSelect = options.Select; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); }
public void ListBatchNodeFilesByTaskWithoutFiltersTest() { // Setup cmdlet to list Task files without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "job-1"; cmdlet.TaskId = "task"; cmdlet.Name = null; cmdlet.Filter = null; string[] namesOfConstructedNodeFiles = new[] { "stdout.txt", "stderr.txt", "wd" }; // Build some NodeFiles instead of querying the service on a List NodeFiles call NodeFileListResponse response = BatchTestHelpers.CreateNodeFileListResponse(namesOfConstructedNodeFiles); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <NodeFileListParameters, NodeFileListResponse>(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeFile> pipeline = new List <PSNodeFile>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeFile>())) .Callback <object>(f => pipeline.Add((PSNodeFile)f)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed node files to the pipeline Assert.Equal(3, pipeline.Count); int taskCount = 0; foreach (PSNodeFile f in pipeline) { Assert.True(namesOfConstructedNodeFiles.Contains(f.Name)); taskCount++; } Assert.Equal(namesOfConstructedNodeFiles.Length, taskCount); }
public void RemoveBatchNodeFileParametersTest() { // Setup cmdlet to skip confirmation popup cmdlet.Force = true; commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true); // Setup cmdlet without required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = null; cmdlet.TaskId = null; cmdlet.Name = null; cmdlet.InputObject = null; // Don't go to the service on a Delete NodeFile call RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <NodeFileDeleteParameters, NodeFileDeleteResponse>(); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; Assert.Throws <ArgumentException>(() => cmdlet.ExecuteCmdlet()); // Fill required task details cmdlet.JobId = "job-1"; cmdlet.TaskId = "task"; cmdlet.Name = "stdout.txt"; // Verify no exceptions occur cmdlet.ExecuteCmdlet(); // Setup compute node parameters cmdlet.JobId = null; cmdlet.TaskId = null; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "computeNode-1"; // Verify no exceptions occur cmdlet.ExecuteCmdlet(); }
public void NewBatchTaskUserIdentityGetsPassedToRequest() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testTask"; cmdlet.JobId = "testJob"; cmdlet.CommandLine = "cmd /c echo hello"; cmdlet.UserIdentity = new PSUserIdentity( new PSAutoUserSpecification(Azure.Batch.Common.AutoUserScope.Task, Azure.Batch.Common.ElevationLevel.Admin)); TaskAddParameter requestParameters = null; // Store the request parameters RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < TaskAddParameter, TaskAddOptions, AzureOperationHeaderResponse <TaskAddHeaders> >(requestAction: (r) => { requestParameters = r.Parameters; }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; cmdlet.ExecuteCmdlet(); // Verify the request parameters match the cmdlet parameters Assert.Equal(cmdlet.UserIdentity.AutoUser.Scope.ToString().ToLowerInvariant(), requestParameters.UserIdentity.AutoUser.Scope.ToString().ToLowerInvariant()); Assert.Equal(cmdlet.UserIdentity.AutoUser.ElevationLevel.ToString().ToLowerInvariant(), requestParameters.UserIdentity.AutoUser.ElevationLevel.ToString().ToLowerInvariant()); Assert.Null(requestParameters.UserIdentity.UserName); // Set the user name instead and verify the request matches expectations cmdlet.UserIdentity = new PSUserIdentity("user1"); cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.UserIdentity.UserName, requestParameters.UserIdentity.UserName); Assert.Null(requestParameters.UserIdentity.AutoUser); }
public void ListBatchNodeAgentSkusParametersTest() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; string[] idsOfNodeAgentSkus = new[] { "batch.node.centos 7", "batch.node.debian 8", "batch.node.opensuse 13.2" }; // Don't go to the service on an Get NodeAgentSkus call AzureOperationResponse <IPage <ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> response = BatchTestHelpers.CreateNodeAgentSkuResponse(idsOfNodeAgentSkus); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.AccountListNodeAgentSkusOptions, AzureOperationResponse <IPage <ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> >(responseToUse: response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeAgentSku> pipeline = new List <PSNodeAgentSku>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeAgentSku>())) .Callback <object>(p => pipeline.Add((PSNodeAgentSku)p)); // Verify no exceptions when required parameter is set cmdlet.ExecuteCmdlet(); Assert.Equal(3, pipeline.Count); int nodeAgentCount = 0; foreach (PSNodeAgentSku p in pipeline) { Assert.True(idsOfNodeAgentSkus.Contains(p.Id)); nodeAgentCount++; } Assert.Equal(idsOfNodeAgentSkus.Length, nodeAgentCount); }
public void ContainerSettingsAreSentToService() { // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-id"; cmdlet.JobId = "job-id"; const string imageName = "foo"; const string containerRunOptions = "bar"; const string userName = "******"; const string password = "******"; cmdlet.ContainerSettings = new PSTaskContainerSettings( imageName, containerRunOptions, new PSContainerRegistry( userName, password: password)); // Don't go to the service on an Add CloudTask call RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <TaskAddParameter, TaskAddOptions, AzureOperationHeaderResponse <TaskAddHeaders> >( new AzureOperationHeaderResponse <TaskAddHeaders>(), request => { var containerSettings = request.Parameters.ContainerSettings; Assert.Equal(imageName, containerSettings.ImageName); Assert.Equal(containerRunOptions, containerSettings.ContainerRunOptions); Assert.Equal(userName, containerSettings.Registry.UserName); Assert.Equal(password, containerSettings.Registry.Password); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Verify no exceptions when required parameters are set cmdlet.ExecuteCmdlet(); }
public void GetBatchJobTest() { // Setup cmdlet to get a Job by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call ProxyModels.CloudJob job = new ProxyModels.CloudJob { Id = cmdlet.Id, OnAllTasksComplete = ProxyModels.OnAllTasksComplete.TerminateJob, OnTaskFailure = ProxyModels.OnTaskFailure.PerformExitOptionsJobAction }; AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(job); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.JobGetOptions, AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> >(response); 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 job returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, pipeline[0].OnTaskFailure); Assert.Equal(OnAllTasksComplete.TerminateJob, pipeline[0].OnAllTasksComplete); }
public void ListBatchJobsUnderScheduleTest() { // Setup cmdlet to list jobs without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobScheduleId = "jobSchedule"; string[] idsOfConstructedJobs = new[] { "job-1", "job-2", "job-3" }; // Build some CloudJobs instead of querying the service on a List Jobs from Job Schedule call AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders> response = BatchTestHelpers.CreateJobListFromJobScheduleResponse(idsOfConstructedJobs); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.JobListFromJobScheduleOptions, AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders> >(response); 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(3, pipeline.Count); int jobCount = 0; foreach (PSCloudJob j in pipeline) { Assert.Contains(j.Id, idsOfConstructedJobs); jobCount++; } Assert.Equal(idsOfConstructedJobs.Length, jobCount); }