public void ListNodeFilesByTaskMaxCountTest() { // Verify default max count Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount); // Setup cmdlet to list node files and a max count. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "job-1"; cmdlet.TaskId = "task"; cmdlet.Path = null; cmdlet.Filter = null; int maxCount = 2; cmdlet.MaxCount = maxCount; string[] namesOfConstructedNodeFiles = new[] { "stdout.txt", "stderr.txt", "wd" }; // Build some NodeFiles instead of querying the service on a List NodeFiles call AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> response = BatchTestHelpers.CreateNodeFileListByTaskResponse(namesOfConstructedNodeFiles); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < bool?, ProxyModels.FileListFromTaskOptions, AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeFile> pipeline = new List <PSNodeFile>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeFile>())) .Callback <object>(f => pipeline.Add((PSNodeFile)f)); 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(namesOfConstructedNodeFiles.Length, pipeline.Count); }
public void ListBatchNodeFilesByTaskWithoutFiltersTest() { // Setup cmdlet to list Task files without filters. BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "job-1"; cmdlet.TaskId = "task"; cmdlet.Path = null; cmdlet.Filter = null; string[] namesOfConstructedNodeFiles = new[] { "stdout.txt", "stderr.txt", "wd" }; // Build some NodeFiles instead of querying the service on a List NodeFiles call AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> response = BatchTestHelpers.CreateNodeFileListByTaskResponse(namesOfConstructedNodeFiles); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < bool?, ProxyModels.FileListFromTaskOptions, AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeFile> pipeline = new List <PSNodeFile>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeFile>())) .Callback <object>(f => pipeline.Add((PSNodeFile)f)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the constructed node files to the pipeline Assert.Equal(3, pipeline.Count); int taskCount = 0; foreach (PSNodeFile f in pipeline) { Assert.Contains(f.Path, namesOfConstructedNodeFiles); taskCount++; } Assert.Equal(namesOfConstructedNodeFiles.Length, taskCount); }
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.Task = null; cmdlet.Filter = null; // Build a NodeFile instead of querying the service on a List NodeFile call AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> response = BatchTestHelpers.CreateNodeFileListByTaskResponse(new string[] { }); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < bool?, ProxyModels.FileListFromTaskOptions, AzureOperationResponse <IPage <ProxyModels.NodeFile>, ProxyModels.FileListFromTaskHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; Assert.Throws <ArgumentException>(() => cmdlet.ExecuteCmdlet()); cmdlet.JobId = "job-1"; cmdlet.TaskId = "task"; // Verify no exceptions occur cmdlet.ExecuteCmdlet(); cmdlet.JobId = null; cmdlet.TaskId = 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()); }