Beispiel #1
0
        public void GetBatchNodeFileByComputeNodeParametersTest()
        {
            // Setup cmdlet without required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext  = context;
            cmdlet.PoolId        = null;
            cmdlet.ComputeNodeId = null;
            cmdlet.Path          = null;
            cmdlet.ComputeNode   = null;
            cmdlet.Filter        = null;

            // Build a NodeFile instead of querying the service on a List NodeFile call
            AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromComputeNodeHeaders> response =
                BatchTestHelpers.CreateNodeFileListByComputeNodeResponse(new string[] { });
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                bool?,
                ProxyModels.FileListFromComputeNodeOptions,
                AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromComputeNodeHeaders> >(response);

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

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

            cmdlet.PoolId        = "pool";
            cmdlet.ComputeNodeId = "computeNode1";

            // Verify no exceptions occur
            cmdlet.ExecuteCmdlet();
        }
Beispiel #2
0
        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.Path          = 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
            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 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);
        }
Beispiel #3
0
        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);
        }