public void OutputFilesAreSentToService() { // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-id"; cmdlet.JobId = "job-id"; const string pattern = @"**\*.txt"; const string containerUrl = "containerUrl"; const string path = "path"; const OutputFileUploadCondition uploadCondition = OutputFileUploadCondition.TaskCompletion; cmdlet.OutputFile = new[] { new PSOutputFile( pattern, new PSOutputFileDestination(new PSOutputFileBlobContainerDestination(containerUrl, path)), new PSOutputFileUploadOptions(uploadCondition)) }; // Don't go to the service on an Add CloudJob call RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <TaskAddParameter, TaskAddOptions, AzureOperationHeaderResponse <TaskAddHeaders> >( new AzureOperationHeaderResponse <TaskAddHeaders>(), request => { var outputFile = request.Parameters.OutputFiles.Single(); Assert.Equal(pattern, outputFile.FilePattern); Assert.Equal(containerUrl, outputFile.Destination.Container.ContainerUrl); Assert.Equal(path, outputFile.Destination.Container.Path); Assert.Equal(uploadCondition.ToString().ToLowerInvariant(), outputFile.UploadOptions.UploadCondition.ToString().ToLowerInvariant()); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Verify no exceptions when required parameters are set cmdlet.ExecuteCmdlet(); }
public PSOutputFileUploadOptions(Microsoft.Azure.Batch.Common.OutputFileUploadCondition uploadCondition) { this.omObject = new Microsoft.Azure.Batch.OutputFileUploadOptions(uploadCondition); }
public void NewBatchTaskCollectionParametersTest() { string commandLine = "cmd /c dir /s"; // Setup cmdlet without the required parameters BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); cmdlet.JobId = "job-collection"; Assert.Throws <ArgumentNullException>(() => cmdlet.ExecuteCmdlet()); const string pattern = @"**\*.txt"; const string containerUrl = "containerUrl"; const string path = "path"; const OutputFileUploadCondition uploadCondition = OutputFileUploadCondition.TaskCompletion; string[] taskIds = new[] { "simple1", "simple2" }; PSCloudTask[] tasks = taskIds.Select( id => new PSCloudTask(id, commandLine) { ResourceFiles = new[] { new PSResourceFile(ResourceFile.FromUrl("anotherFile.txt", "https://another.blob")) }, OutputFiles = new[] { new PSOutputFile( pattern, new PSOutputFileDestination(new PSOutputFileBlobContainerDestination(containerUrl, path)), new PSOutputFileUploadOptions(uploadCondition)) }, ApplicationPackageReferences = new[] { new PSApplicationPackageReference { ApplicationId = "1", Version = "foo" } }, ExitConditions = new PSExitConditions() { ExitCodeRanges = new List <PSExitCodeRangeMapping> { new PSExitCodeRangeMapping( 5, 10, new PSExitOptions { DependencyAction = Azure.Batch.Common.DependencyAction.Block }) }, ExitCodes = new List <PSExitCodeMapping> { new PSExitCodeMapping( 11, new PSExitOptions { DependencyAction = Azure.Batch.Common.DependencyAction.Block }) }, Default = new PSExitOptions { DependencyAction = Azure.Batch.Common.DependencyAction.Satisfy } } }).ToArray(); cmdlet.Tasks = tasks; IList <TaskAddParameter> requestCollection = null; Action <BatchRequest < IList <TaskAddParameter>, TaskAddCollectionOptions, AzureOperationResponse <TaskAddCollectionResult, TaskAddCollectionHeaders> > > extractCollection = (request) => { requestCollection = request.Parameters; }; // Don't go to the service on an Add Task Collection call AzureOperationResponse <TaskAddCollectionResult, TaskAddCollectionHeaders> response = BatchTestHelpers.CreateTaskCollectionResponse(cmdlet.Tasks); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor(responseToUse: response, requestAction: extractCollection); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Verify no exceptions when required parameters are set cmdlet.ExecuteCmdlet(); Assert.Equal(2, requestCollection.Count); foreach (var task in requestCollection) { Assert.Contains(task.Id, taskIds); Assert.NotNull(task.ResourceFiles); Assert.NotEmpty(task.ResourceFiles); Assert.NotNull(task.OutputFiles); Assert.NotEmpty(task.OutputFiles); Assert.NotNull(task.ApplicationPackageReferences); Assert.NotEmpty(task.ApplicationPackageReferences); Assert.NotNull(task.ExitConditions.ExitCodeRanges); Assert.NotEmpty(task.ExitConditions.ExitCodeRanges); Assert.NotNull(task.ExitConditions.ExitCodes); Assert.NotEmpty(task.ExitConditions.ExitCodes); Assert.NotNull(task.ExitConditions.DefaultProperty); } }