public void GetBatchTaskODataTest() { // Setup cmdlet to get a single task BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "testJob"; cmdlet.Id = "testTask1"; 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. CloudTaskGetResponse getResponse = BatchTestHelpers.CreateCloudTaskGetResponse(cmdlet.Id); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudTaskGetParameters, CloudTaskGetResponse>(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 GetBatchCertificateODataTest() { // Setup cmdlet to get a single certificate BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.ThumbprintAlgorithm = "sha1"; cmdlet.Thumbprint = "123456789"; cmdlet.Select = "thumbprint,state"; string requestSelect = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. AzureOperationResponse <ProxyModels.Certificate, ProxyModels.CertificateGetHeaders> getResponse = BatchTestHelpers.CreateCertificateGetResponse(cmdlet.Thumbprint); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.CertificateGetOptions, AzureOperationResponse <ProxyModels.Certificate, ProxyModels.CertificateGetHeaders> >(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.CertificateGetOptions certOptions = (ProxyModels.CertificateGetOptions)request.Options; requestSelect = certOptions.Select; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); }
public void ListBatchCertificatesODataTest() { // Setup cmdlet to list certs using an OData filter BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.ThumbprintAlgorithm = null; cmdlet.Thumbprint = null; cmdlet.Filter = "state eq 'active'"; cmdlet.Select = "id,state"; string requestFilter = null; string requestSelect = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CertificateListParameters, CertificateListResponse>(); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { requestFilter = request.Parameters.DetailLevel.FilterClause; requestSelect = request.Parameters.DetailLevel.SelectClause; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); Assert.Equal(cmdlet.Select, requestSelect); }
public void ListBatchNodeAgentSkusWithFilterTest() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Filter = "osType eq 'linux'"; string requestFilter = null; // Don't go to the service on an Get NodeAgentSkus call AzureOperationResponse <IPage <ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> getResponse = BatchTestHelpers.CreateGenericAzureOperationListResponse <ProxyModels.NodeAgentSku, ProxyModels.AccountListNodeAgentSkusHeaders>(); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.AccountListNodeAgentSkusOptions, AzureOperationResponse <IPage <ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> >(responseToUse: getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.AccountListNodeAgentSkusOptions listNodeAgentSkusOptions = (ProxyModels.AccountListNodeAgentSkusOptions)request.Options; requestFilter = listNodeAgentSkusOptions.Filter; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; // Verify no exceptions when required parameter is set cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); }
/// <summary> /// Executes the given call to the RP and returns the response content (i.e. raw json). /// </summary> /// <param name="operation"></param> /// <returns></returns> public string GetResponseBody(Action <DataFactoryManagementClient> operation) { var handler = new ResponseInterceptor(); DataFactoryManagementClient client = this.WithHandler(handler); operation(client); return(handler.ResponseBody); }
/// <summary> /// Executes the given call to the RP and returns the response content (i.e. raw json). /// </summary> /// <param name="operation"></param> /// <returns></returns> public async Task <string> GetResponseBodyAsync(Func <DataFactoryManagementClient, Task> operation) { var handler = new ResponseInterceptor(); DataFactoryManagementClient fakeClient = this.WithHandler(handler); await operation(fakeClient); return(handler.ResponseBody); }
public void GetBatchPoolUsageWithFilter() { int year = 2013; int month = 4; int day = 1; BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Filter = "poolId lt 'p2'"; string requestFilter = null; string[] poolIds = new[] { "p1" }; DateTime[] startTimes = new[] { new DateTime(year, month, day, 0, 0, 0) }; DateTime[] endTimes = new[] { new DateTime(year, month, day, 0, 30, 0) }; AzureOperationResponse <IPage <ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListUsageMetricsHeaders> response = BatchTestHelpers.CreatePoolListUsageMetricsResponse(poolIds, startTimes, endTimes); // Don't go to the service on an Get PoolUsageMetrics call RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.PoolListUsageMetricsOptions, AzureOperationResponse <IPage <ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListUsageMetricsHeaders> >(responseToUse: response); ResponseInterceptor responseInterceptor = new ResponseInterceptor((responseToUse, request) => { ProxyModels.PoolListUsageMetricsOptions options = (ProxyModels.PoolListUsageMetricsOptions)request.Options; requestFilter = options.Filter; return(Task.FromResult(responseToUse)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; // Verify no exceptions when required parameter is set cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); }
public void GetBatchComputeNodeExtensionODataTest() { string extensionName = "testExtension"; string publisher = "testPublisher"; string type = "testType"; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.Name = extensionName; cmdlet.Select = "ExtensionName,Publisher"; VMExtension extension = new VMExtension(extensionName, publisher, type); // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> getResponse = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionGetOptions, AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> >(getResponse); string requestSelect = null; ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.ComputeNodeExtensionGetOptions options = (ProxyModels.ComputeNodeExtensionGetOptions)request.Options; requestSelect = options.Select; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); }
public void ReadClientRequestIdAndRequestIdFromResponse() { void test() { using BatchClient batchCli = TestUtilities.OpenBatchClient(TestUtilities.GetCredentialsFromEnvironment()); string requestId = null; //Set up an interceptor to read RequestId from all responses ResponseInterceptor responseInterceptor = new ResponseInterceptor( (response, request) => { requestId = response.RequestId; return(Task.FromResult(response)); }); batchCli.PoolOperations.ListPools(additionalBehaviors: new[] { responseInterceptor }).ToList(); //Force an enumeration to go to the server Assert.NotNull(requestId); } SynchronizationContextHelper.RunTest(test, TestTimeout); }
public void GetBatchTaskODataTest() { // Setup cmdlet to get a single task BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.JobId = "testJob"; cmdlet.Id = "testTask1"; 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.CloudTask, ProxyModels.TaskGetHeaders> getResponse = BatchTestHelpers.CreateCloudTaskGetResponse(cmdlet.Id); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.TaskGetOptions, AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> >(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.TaskGetOptions options = (ProxyModels.TaskGetOptions)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 GetBatchCertificateODataTest() { // Setup cmdlet to get a single certificate BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.ThumbprintAlgorithm = "sha1"; cmdlet.Thumbprint = "123456789"; cmdlet.Select = "thumbprint,state"; string requestSelect = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. CertificateGetResponse getResponse = BatchTestHelpers.CreateCertificateGetResponse(cmdlet.Thumbprint); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CertificateGetParameters, CertificateGetResponse>(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { requestSelect = request.Parameters.DetailLevel.SelectClause; return Task.FromResult(response); }); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); }
public void ListBatchNodeAgentSkusWithFilterTest() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Filter = "osType eq 'linux'"; string requestFilter = null; // Don't go to the service on an Get NodeAgentSkus call AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> getResponse = BatchTestHelpers.CreateGenericAzureOperationListResponse<ProxyModels.NodeAgentSku, ProxyModels.AccountListNodeAgentSkusHeaders>(); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.AccountListNodeAgentSkusOptions, AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>>(responseToUse: getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.AccountListNodeAgentSkusOptions listNodeAgentSkusOptions = (ProxyModels.AccountListNodeAgentSkusOptions)request.Options; requestFilter = listNodeAgentSkusOptions.Filter; return Task.FromResult(response); }); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor }; // Verify no exceptions when required parameter is set cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); }
public void GetBatchComputeNodeODataTest() { // Setup cmdlet to get a single compute node BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.Id = "computeNode1"; cmdlet.Select = "id,state"; string requestSelect = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. AzureOperationResponse<ProxyModels.ComputeNode, ProxyModels.ComputeNodeGetHeaders> getResponse = BatchTestHelpers.CreateComputeNodeGetResponse(cmdlet.Id); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor< ProxyModels.ComputeNodeGetOptions, AzureOperationResponse<ProxyModels.ComputeNode, ProxyModels.ComputeNodeGetHeaders>>(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { ProxyModels.ComputeNodeGetOptions computeNodeOptions = (ProxyModels.ComputeNodeGetOptions)request.Options; requestSelect = computeNodeOptions.Select; return Task.FromResult(response); }); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); }
/// <summary> /// Executes the given call to the RP and returns the response content (i.e. raw json). /// </summary> /// <param name="operation"></param> /// <returns></returns> public async Task<string> GetResponseBodyAsync(Func<DataFactoryManagementClient, Task> operation) { var handler = new ResponseInterceptor(); DataFactoryManagementClient fakeClient = this.WithHandler(handler); await operation(fakeClient); return handler.ResponseBody; }
/// <summary> /// Executes the given call to the RP and returns the response content (i.e. raw json). /// </summary> /// <param name="operation"></param> /// <returns></returns> public string GetResponseBody(Action<DataFactoryManagementClient> operation) { var handler = new ResponseInterceptor(); DataFactoryManagementClient client = this.WithHandler(handler); operation(client); return handler.ResponseBody; }
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 GetBatchPoolUsageWithFilter() { int year = 2013; int month = 4; int day = 1; BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Filter = "poolId lt 'p2'"; string requestFilter = null; string[] poolIds = new[] { "p1" }; DateTime[] startTimes = new[] { new DateTime(year, month, day, 0, 0, 0) }; DateTime[] endTimes = new[] { new DateTime(year, month, day, 0, 30, 0) }; AzureOperationResponse<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders> response = BatchTestHelpers.CreatePoolListUsageMetricsResponse(poolIds, startTimes, endTimes); // Don't go to the service on an Get PoolUsageMetrics call RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor< ProxyModels.PoolListPoolUsageMetricsOptions, AzureOperationResponse<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders>>(responseToUse: response); ResponseInterceptor responseInterceptor = new ResponseInterceptor((responseToUse, request) => { ProxyModels.PoolListPoolUsageMetricsOptions options = (ProxyModels.PoolListPoolUsageMetricsOptions)request.Options; requestFilter = options.Filter; return Task.FromResult(responseToUse); }); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor }; // Verify no exceptions when required parameter is set cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); }
public void ListBatchComputeNodesODataTest() { // Setup cmdlet to list compute nodes using an OData filter BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.Id = null; cmdlet.Filter = "startswith(id,'test')"; cmdlet.Select = "id,state"; string requestFilter = null; string requestSelect = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeListParameters, ComputeNodeListResponse>(); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { requestFilter = request.Parameters.DetailLevel.FilterClause; requestSelect = request.Parameters.DetailLevel.SelectClause; return Task.FromResult(response); }); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Filter, requestFilter); Assert.Equal(cmdlet.Select, requestSelect); }