public void GetBatchPoolODataTest() { // Setup cmdlet to get a single pool BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testPool"; 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. CloudPoolGetResponse getResponse = BatchTestHelpers.CreateCloudPoolGetResponse(cmdlet.Id); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudPoolGetParameters, CloudPoolGetResponse>(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 GetBatchPoolTest() { // Setup cmdlet to get a pool by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testPool"; cmdlet.Filter = null; // Build a CloudPool instead of querying the service on a Get CloudPool call CloudPoolGetResponse response = BatchTestHelpers.CreateCloudPoolGetResponse(cmdlet.Id); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudPoolGetParameters, CloudPoolGetResponse>(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudPool> pipeline = new List <PSCloudPool>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())).Callback <object>(p => pipeline.Add((PSCloudPool)p)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the pool returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); }
public void GetBatchPoolODataTest() { // Setup cmdlet to get a single pool BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testPool"; 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.CloudPool, ProxyModels.PoolGetHeaders> getResponse = BatchTestHelpers.CreateCloudPoolGetResponse(cmdlet.Id); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.PoolGetOptions, AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> >(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.PoolGetOptions options = (ProxyModels.PoolGetOptions)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 GetBatchPoolTest() { // Setup cmdlet to get a pool by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testPool"; cmdlet.Filter = null; // Pool returned in the response ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = cmdlet.Id; pool.TaskSlotsPerNode = 16; // Build a CloudPool instead of querying the service on a Get CloudPool call AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> response = BatchTestHelpers.CreateCloudPoolGetResponse(pool); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.PoolGetOptions, AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudPool> pipeline = new List <PSCloudPool>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())).Callback <object>(p => pipeline.Add((PSCloudPool)p)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the pool returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); Assert.Equal(16, pipeline[0].TaskSlotsPerNode); }