public void GetBatchTaskFileParametersTest() { // Setup cmdlet without required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.WorkItemName = null; cmdlet.JobName = null; cmdlet.TaskName = null; cmdlet.Name = null; cmdlet.InputObject = null; cmdlet.DestinationPath = null; string fileName = "stdout.txt"; // Don't hit the file system during unit tests cmdlet.Stream = new MemoryStream(); // Don't go to the service on a GetTaskFile call or GetTaskFileProperties call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is GetTaskFilePropertiesRequest) { GetTaskFilePropertiesResponse response = BatchTestHelpers.CreateGetTaskFilePropertiesResponse(fileName); Task <object> task = Task <object> .Factory.StartNew(() => { return(response); }); return(task); } if (request is GetTaskFileRequest) { GetTaskFileResponse response = new GetTaskFileResponse(); Task <object> task = Task <object> .Factory.StartNew(() => { return(response); }); return(task); } return(null); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); // Fill required Task file details cmdlet.WorkItemName = "workItem"; cmdlet.JobName = "job-0000000001"; cmdlet.TaskName = "task"; cmdlet.Name = fileName; try { // Verify no exceptions occur cmdlet.ExecuteCmdlet(); } finally { cmdlet.Stream.Dispose(); } }
/// <summary> /// Builds a GetTaskFilePropertiesResponse object /// </summary> public static GetTaskFilePropertiesResponse CreateGetTaskFilePropertiesResponse(string fileName) { GetTaskFilePropertiesResponse response = new GetTaskFilePropertiesResponse(); 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); }
public void GetBatchTaskFileTest() { // Setup cmdlet to get a Task file by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.WorkItemName = "workItem"; cmdlet.JobName = "job-0000000001"; cmdlet.TaskName = "task"; cmdlet.Name = "stdout.txt"; cmdlet.Filter = null; // Build a Task file instead of querying the service on a GetTaskFileProperties call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is GetTaskFilePropertiesRequest) { GetTaskFilePropertiesResponse response = BatchTestHelpers.CreateGetTaskFilePropertiesResponse(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 <PSTaskFile> pipeline = new List <PSTaskFile>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSTaskFile>())).Callback <object>(f => pipeline.Add((PSTaskFile)f)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the Task file returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Name, pipeline[0].Name); }
/// <summary> /// Builds a GetTaskFilePropertiesResponse object /// </summary> public static GetTaskFilePropertiesResponse CreateGetTaskFilePropertiesResponse(string fileName) { GetTaskFilePropertiesResponse response = new GetTaskFilePropertiesResponse(); 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; }