public void GetBatchJobTest() { // Setup cmdlet to get a Job by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call CloudJobGetResponse response = BatchTestHelpers.CreateCloudJobGetResponse(cmdlet.Id); RequestInterceptor interceptor = BatchTestHelpers.CreateNoOpInterceptor <CloudJobGetParameters, CloudJobGetResponse>(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudJob> pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())).Callback <object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the job returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); }
public void GetBatchJobODataTest() { // Setup cmdlet to get a single job BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testJob"; cmdlet.Select = "id,state"; cmdlet.Expand = "stats"; string requestSelect = null; string requestExpand = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. CloudJobGetResponse getResponse = BatchTestHelpers.CreateCloudJobGetResponse(cmdlet.Id); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudJobGetParameters, CloudJobGetResponse>(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { requestSelect = request.Parameters.DetailLevel.SelectClause; requestExpand = request.Parameters.DetailLevel.ExpandClause; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); Assert.Equal(cmdlet.Expand, requestExpand); }
public void GetBatchJobODataTest() { // Setup cmdlet to get a single job BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testJob"; cmdlet.Select = "id,state"; cmdlet.Expand = "stats"; string requestSelect = null; string requestExpand = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> getResponse = BatchTestHelpers.CreateCloudJobGetResponse(cmdlet.Id); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.JobGetOptions, AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> >(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.JobGetOptions options = (ProxyModels.JobGetOptions)request.Options; requestSelect = options.Select; requestExpand = options.Expand; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); Assert.Equal(cmdlet.Expand, requestExpand); }
public void GetBatchJobTest() { // Setup cmdlet to get a Job by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call ProxyModels.CloudJob job = new ProxyModels.CloudJob { Id = cmdlet.Id, OnAllTasksComplete = ProxyModels.OnAllTasksComplete.TerminateJob, OnTaskFailure = ProxyModels.OnTaskFailure.PerformExitOptionsJobAction }; AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(job); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.JobGetOptions, AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudJob> pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())).Callback <object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the job returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, pipeline[0].OnTaskFailure); Assert.Equal(OnAllTasksComplete.TerminateJob, pipeline[0].OnAllTasksComplete); }
public void WhenGettingAJobFromTheService_ApplicationPackageReferencesAreMapped() { // Setup cmdlet to get a Job by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call string applicationId = "foo"; string applicationVersion = "beta"; ProxyModels.CloudJob cloudTask = new ProxyModels.CloudJob { Id = "job-1", JobManagerTask = new ProxyModels.JobManagerTask { ApplicationPackageReferences = new[] { new ProxyModels.ApplicationPackageReference(applicationId, applicationVersion) } } }; AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.JobGetOptions, AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior> { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())).Callback <object>(t => pipeline.Add((PSCloudJob)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); var psApplicationPackageReference = pipeline[0].JobManagerTask.ApplicationPackageReferences.First(); Assert.Equal(applicationId, psApplicationPackageReference.ApplicationId); Assert.Equal(applicationVersion, psApplicationPackageReference.Version); }