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