public void GetBatchVMFileContentParametersTest()
        {
            // Setup cmdlet without required parameters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext    = context;
            cmdlet.PoolName        = null;
            cmdlet.VMName          = null;
            cmdlet.Name            = null;
            cmdlet.InputObject     = null;
            cmdlet.DestinationPath = null;

            string fileName = "startup\\stdout.txt";

            // Don't go to the service on a GetTVMFile call or GetTVMFileProperties call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is GetTVMFilePropertiesRequest)
                {
                    GetTVMFilePropertiesResponse response = BatchTestHelpers.CreateGetTVMFilePropertiesResponse(fileName);
                    Task <object> task = Task <object> .Factory.StartNew(() => { return(response); });
                    return(task);
                }
                if (request is GetTVMFileRequest)
                {
                    GetTVMFileResponse response = new GetTVMFileResponse();
                    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";
                cmdlet.Name     = fileName;

                // Verify no exceptions occur
                cmdlet.ExecuteCmdlet();
            }
        }
        /// <summary>
        /// Builds a GetTVMFilePropertiesResponse object
        /// </summary>
        public static GetTVMFilePropertiesResponse CreateGetTVMFilePropertiesResponse(string fileName)
        {
            GetTVMFilePropertiesResponse response = new GetTVMFilePropertiesResponse();

            SetProperty(response, "StatusCode", HttpStatusCode.OK);

            Azure.Batch.Protocol.Entities.File file = new Azure.Batch.Protocol.Entities.File();
            SetProperty(file, "Name", fileName);

            SetProperty(response, "File", file);

            return(response);
        }
Exemple #3
0
        public void GetBatchVMFileTest()
        {
            // Setup cmdlet to get a Task file by name
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

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

            // Build a vm file instead of querying the service on a GetVMFileProperties call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is GetTVMFilePropertiesRequest)
                {
                    GetTVMFilePropertiesResponse response = BatchTestHelpers.CreateGetTVMFilePropertiesResponse(cmdlet.Name);
                    Task <object> task = Task <object> .Factory.StartNew(() => { return(response); });
                    return(task);
                }
                return(null);
            });

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

            // Setup the cmdlet to write pipeline output to a list that can be examined later
            List <PSVMFile> pipeline = new List <PSVMFile>();

            commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSVMFile>())).Callback <object>(f => pipeline.Add((PSVMFile)f));

            cmdlet.ExecuteCmdlet();

            // Verify that the cmdlet wrote the vm file returned from the OM to the pipeline
            Assert.Equal(1, pipeline.Count);
            Assert.Equal(cmdlet.Name, pipeline[0].Name);
        }
        /// <summary>
        /// Builds a GetTVMFilePropertiesResponse object
        /// </summary>
        public static GetTVMFilePropertiesResponse CreateGetTVMFilePropertiesResponse(string fileName)
        {
            GetTVMFilePropertiesResponse response = new GetTVMFilePropertiesResponse();
            SetProperty(response, "StatusCode", HttpStatusCode.OK);

            Azure.Batch.Protocol.Entities.File file = new Azure.Batch.Protocol.Entities.File();
            SetProperty(file, "Name", fileName);

            SetProperty(response, "File", file);

            return response;
        }