Exemple #1
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 = BatchTestHelpers.CreateFakGetFileAndPropertiesResponseInterceptor(cmdlet.Name);

            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();
            }
        }
Exemple #2
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();
            }
        }