public void ListTaskFilesMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list Task files and a max count. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.WorkItemName = "workItem"; cmdlet.JobName = "job-0000000001"; cmdlet.TaskName = "task"; cmdlet.Name = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] namesOfConstructedTaskFiles = new[] { "stdout.txt", "stderr.txt", "wd" }; // Build some Task files instead of querying the service on a ListTaskFiles call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is ListTaskFilesRequest) { ListTaskFilesResponse response = BatchTestHelpers.CreateListTaskFilesResponse(namesOfConstructedTaskFiles); 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>(t => pipeline.Add((PSTaskFile)t)); cmdlet.ExecuteCmdlet(); // Verify that the max count was respected Assert.Equal(maxCount, pipeline.Count); // Verify setting max count <= 0 doesn't return nothing cmdlet.MaxCount = -5; pipeline.Clear(); cmdlet.ExecuteCmdlet(); Assert.Equal(namesOfConstructedTaskFiles.Length, pipeline.Count); }
public void ListBatchTaskFilesWithoutFiltersTest() { // Setup cmdlet to list Task files without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.WorkItemName = "workItem"; cmdlet.JobName = "job-0000000001"; cmdlet.TaskName = "task"; cmdlet.Name = null; cmdlet.Filter = null; string[] namesOfConstructedTaskFiles = new[] { "stdout.txt", "stderr.txt", "wd" }; // Build some Task files instead of querying the service on a ListTaskFiles call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is ListTaskFilesRequest) { ListTaskFilesResponse response = BatchTestHelpers.CreateListTaskFilesResponse(namesOfConstructedTaskFiles); 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>(t => pipeline.Add((PSTaskFile)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed Task files to the pipeline Assert.Equal(3, pipeline.Count); int taskCount = 0; foreach (PSTaskFile f in pipeline) { Assert.True(namesOfConstructedTaskFiles.Contains(f.Name)); taskCount++; } Assert.Equal(namesOfConstructedTaskFiles.Length, taskCount); }
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.Task = null; cmdlet.Filter = null; // Build some Task files instead of querying the service on a ListTaskFiles call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is ListTaskFilesRequest) { ListTaskFilesResponse response = BatchTestHelpers.CreateListTaskFilesResponse(new string[] { "stdout.txt" }); Task <object> task = Task <object> .Factory.StartNew(() => { return(response); }); return(task); } return(null); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.WorkItemName = "workItem"; cmdlet.JobName = "job-0000000001"; cmdlet.TaskName = "task"; // Verify no exceptions occur cmdlet.ExecuteCmdlet(); cmdlet.WorkItemName = null; cmdlet.JobName = null; cmdlet.TaskName = null; cmdlet.Task = new PSCloudTask("task", "cmd /c dir /s"); // Verify that we don't get an argument exception. We should get an InvalidOperationException though since the task is unbound Assert.Throws <InvalidOperationException>(() => cmdlet.ExecuteCmdlet()); }