Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public void GetBatchNodeFileByTaskParametersTest()
        {
            // 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;

            string filePath = "stdout.txt";

            // Don't go to the service on a Get NodeFile call or Get NodeFile Properties call
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeGetFileAndPropertiesFromTaskResponseInterceptor(cmdlet.Path);

            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.Path   = filePath;

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