public void GetBatchNodeFileByTaskTest()
        {
            // Setup cmdlet to get a Task file by name
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.JobId        = "job-1";
            cmdlet.TaskId       = "task";
            cmdlet.Name         = "stdout.txt";
            cmdlet.Filter       = null;

            // Build a NodeFile instead of querying the service on a Get NodeFile Properties call
            NodeFileGetPropertiesResponse response    = BatchTestHelpers.CreateNodeFileGetPropertiesResponse(cmdlet.Name);
            RequestInterceptor            interceptor = BatchTestHelpers.CreateNoOpInterceptor <NodeFileGetPropertiesParameters, NodeFileGetPropertiesResponse>(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 node file returned from the OM to the pipeline
            Assert.Equal(1, pipeline.Count);
            Assert.Equal(cmdlet.Name, pipeline[0].Name);
        }
        public void GetBatchNodeFileByComputeNodeTest()
        {
            // Setup cmdlet to get a Task file by name
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext  = context;
            cmdlet.PoolId        = "pool";
            cmdlet.ComputeNodeId = "vm1";
            cmdlet.Name          = "startup\\stdout.txt";
            cmdlet.Filter        = null;

            // Build a NodeFile instead of querying the service on a Get NodeFile Properties call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <NodeFileGetPropertiesParameters, NodeFileGetPropertiesResponse> request =
                    (BatchRequest <NodeFileGetPropertiesParameters, NodeFileGetPropertiesResponse>)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    NodeFileGetPropertiesResponse response    = BatchTestHelpers.CreateNodeFileGetPropertiesResponse(cmdlet.Name);
                    Task <NodeFileGetPropertiesResponse> task = Task.FromResult(response);
                    return(task);
                };
            });

            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 node file returned from the OM to the pipeline
            Assert.Equal(1, pipeline.Count);
            Assert.Equal(cmdlet.Name, pipeline[0].Name);
        }
Example #3
0
        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.InputObject     = null;
            cmdlet.DestinationPath = null;

            string fileName = "stdout.txt";

            // Don't go to the service on a Get NodeFile call or Get NodeFile Properties call
            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                BatchRequest <NodeFileGetParameters, NodeFileGetResponse> fileRequest = baseRequest as
                                                                                        BatchRequest <NodeFileGetParameters, NodeFileGetResponse>;

                if (fileRequest != null)
                {
                    fileRequest.ServiceRequestFunc = (cancellationToken) =>
                    {
                        NodeFileGetResponse response    = new NodeFileGetResponse();
                        Task <NodeFileGetResponse> task = Task.FromResult(response);
                        return(task);
                    };
                }
                else
                {
                    BatchRequest <NodeFileGetPropertiesParameters, NodeFileGetPropertiesResponse> propRequest =
                        (BatchRequest <NodeFileGetPropertiesParameters, NodeFileGetPropertiesResponse>)baseRequest;

                    propRequest.ServiceRequestFunc = (cancellationToken) =>
                    {
                        NodeFileGetPropertiesResponse response    = BatchTestHelpers.CreateNodeFileGetPropertiesResponse(cmdlet.Name);
                        Task <NodeFileGetPropertiesResponse> 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 <ArgumentException>(() => cmdlet.ExecuteCmdlet());

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

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