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 = null;
            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
            AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListHeaders> response = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs);
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.JobListOptions, AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListHeaders> >(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);
        }
Beispiel #2
0
        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
            CloudTaskListResponse response    = BatchTestHelpers.CreateCloudTaskListResponse(idsOfConstructedTasks);
            RequestInterceptor    interceptor = BatchTestHelpers.CreateNoOpInterceptor <CloudTaskListParameters, CloudTaskListResponse>(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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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
            CertificateListResponse response    = BatchTestHelpers.CreateCertificateListResponse(thumbprintsOfConstructedCerts);
            RequestInterceptor      interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CertificateListParameters, CertificateListResponse>(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 GetBatchNodeFileByTaskParametersTest()
        {
            // Setup cmdlet without required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.JobId        = null;
            cmdlet.TaskId       = null;
            cmdlet.Name         = null;
            cmdlet.Task         = null;
            cmdlet.Filter       = null;

            // Build a NodeFile instead of querying the service on a List NodeFile call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <NodeFileListParameters, NodeFileListResponse> request =
                    (BatchRequest <NodeFileListParameters, NodeFileListResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    NodeFileListResponse response    = BatchTestHelpers.CreateNodeFileListResponse(new string[] { cmdlet.Name });
                    Task <NodeFileListResponse> task = Task.FromResult(response);
                    return(task);
                };
            });

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

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

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

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

            cmdlet.JobId  = null;
            cmdlet.TaskId = null;
            cmdlet.Task   = new PSCloudTask("task", "cmd /c dir /s");

            // Verify that we don't get an argument exception. We should get an InvalidOperationException though since the task is unbound
            Assert.Throws <InvalidOperationException>(() => cmdlet.ExecuteCmdlet());
        }
Beispiel #6
0
        public void GetBatchNodeFileByteRangeSet_IsPopulatedInRequest(long?rangeStart, long?rangeEnd)
        {
            // Setup cmdlet without required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext    = context;
            cmdlet.JobId           = null;
            cmdlet.TaskId          = null;
            cmdlet.Path            = null;
            cmdlet.InputObject     = null;
            cmdlet.DestinationPath = null;
            cmdlet.ByteRangeStart  = rangeStart;
            cmdlet.ByteRangeEnd    = rangeEnd;

            string fileName = "stdout.txt";
            bool   hit      = false;
            // Don't go to the service on a Get NodeFile call or Get NodeFile Properties call
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeGetFileAndPropertiesFromTaskResponseInterceptor(cmdlet.Path);
            RequestInterceptor examiner    = BatchTestHelpers.ExamineRequestInterceptor <FileGetFromTaskBatchRequest>(req =>
            {
                hit = true;
                Assert.Equal($"bytes={cmdlet.ByteRangeStart}-{cmdlet.ByteRangeEnd}", req.Options.OcpRange);
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior> {
                examiner, interceptor
            };

            using (MemoryStream memStream = new MemoryStream())
            {
                // Don't hit the file system during unit tests
                cmdlet.DestinationStream = memStream;

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

                // Fill required task details
                cmdlet.JobId  = "job-1";
                cmdlet.TaskId = "task";
                cmdlet.Path   = fileName;

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

                Assert.True(hit);
            }
        }
        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 GetBatchRemoteDesktopProtocolFileParametersTest()
        {
            // Setup cmdlet without required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext    = context;
            cmdlet.PoolId          = null;
            cmdlet.ComputeNodeId   = null;
            cmdlet.ComputeNode     = null;
            cmdlet.DestinationPath = null;

            // Don't go to the service on a Get ComputeNode Remote Desktop call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <ComputeNodeGetRemoteDesktopParameters, ComputeNodeGetRemoteDesktopResponse> request =
                    (BatchRequest <ComputeNodeGetRemoteDesktopParameters, ComputeNodeGetRemoteDesktopResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    ComputeNodeGetRemoteDesktopResponse response    = new ComputeNodeGetRemoteDesktopResponse();
                    Task <ComputeNodeGetRemoteDesktopResponse> task = Task.FromResult(response);
                    return(task);
                };
            });

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

            using (MemoryStream memStream = new MemoryStream())
            {
                // Don't hit the file system during unit tests
                cmdlet.DestinationStream = memStream;

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

                // Fill required compute node details
                cmdlet.PoolId        = "pool";
                cmdlet.ComputeNodeId = "computeNode1";

                // Verify no exceptions occur
                cmdlet.ExecuteCmdlet();
            }
        }
        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);
        }
Beispiel #10
0
        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 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 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 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 GetBatchRDPFileParametersTest()
        {
            // Setup cmdlet without required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext    = context;
            cmdlet.PoolName        = null;
            cmdlet.VMName          = null;
            cmdlet.VM              = null;
            cmdlet.DestinationPath = null;

            // Don't go to the service on a GetTVMRDPFile call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is GetTVMRDPFileRequest)
                {
                    GetTVMRDPFileResponse response = new GetTVMRDPFileResponse();
                    Task <object> task             = Task <object> .Factory.StartNew(() => { return(response); });
                    return(task);
                }
                return(null);
            });

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

            using (MemoryStream memStream = new MemoryStream())
            {
                // Don't hit the file system during unit tests
                cmdlet.DestinationStream = memStream;

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

                // Fill required Task file details
                cmdlet.PoolName = "pool";
                cmdlet.VMName   = "vm1";

                // Verify no exceptions occur
                cmdlet.ExecuteCmdlet();
            }
        }
        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);
        }
Beispiel #17
0
        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();
        }
Beispiel #18
0
        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();
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        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 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);
        }
Beispiel #22
0
        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 ListBatchNodeFilesByComputeNodeWithoutFiltersTest()
        {
            // Setup cmdlet to list vm files without filters.
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext  = context;
            cmdlet.PoolId        = "pool";
            cmdlet.ComputeNodeId = "computeNode1";
            cmdlet.Name          = null;
            cmdlet.Filter        = null;

            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.CreateNoOpInterceptor <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 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);
        }
Beispiel #27
0
        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();
        }
Beispiel #28
0
        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);
        }
Beispiel #29
0
        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 ListBatchJobsByODataFilterTest()
        {
            // Setup cmdlet to list jobs using an OData filter. Use JobScheduleId input.
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext  = context;
            cmdlet.JobScheduleId = "jobSchedule";
            cmdlet.Id            = null;
            cmdlet.Filter        = "state -eq 'active'";

            string[] idsOfConstructedJobs = new[] { "job-1", "job-2" };

            // Build some CloudJobs instead of querying the service on a List CloudJobs call
            CloudJobListResponse response    = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs);
            RequestInterceptor   interceptor = BatchTestHelpers.CreateNoOpInterceptor <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 cmdlet wrote the constructed jobs to the pipeline
            Assert.Equal(2, pipeline.Count);
            int jobCount = 0;

            foreach (PSCloudJob j in pipeline)
            {
                Assert.True(idsOfConstructedJobs.Contains(j.Id));
                jobCount++;
            }
            Assert.Equal(idsOfConstructedJobs.Length, jobCount);
        }