/// <summary> /// Creates or updates an External Cache to be used in Api Management instance. /// <see href="https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-cache-external" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='cacheId'> /// Identifier of the Cache entity. Cache identifier (should be either /// 'default' or valid Azure region identifier). /// </param> /// <param name='parameters'> /// Create or Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> public static CacheContract CreateOrUpdate(this ICacheOperations operations, string resourceGroupName, string serviceName, string cacheId, CacheContract parameters, string ifMatch = default(string)) { return(operations.CreateOrUpdateAsync(resourceGroupName, serviceName, cacheId, parameters, ifMatch).GetAwaiter().GetResult()); }
/// <summary> /// Creates or updates an External Cache to be used in Api Management instance. /// <see href="https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-cache-external" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='cacheId'> /// Identifier of the Cache entity. Cache identifier (should be either /// 'default' or valid Azure region identifier). /// </param> /// <param name='parameters'> /// Create or Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. Not required when creating an entity, but required when /// updating an entity. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <CacheContract> CreateOrUpdateAsync(this ICacheOperations operations, string resourceGroupName, string serviceName, string cacheId, CacheContract parameters, string ifMatch = default(string), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serviceName, cacheId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public async Task CreateListUpdateDelete() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // list caches: there should be none var cacheListResponse = testBase.client.Cache.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(cacheListResponse); Assert.Empty(cacheListResponse); // create new cache string cacheid = testBase.serviceProperties.Location; try { var cacheContract = new CacheContract() { ConnectionString = TestUtilities.GenerateName(), Description = TestUtilities.GenerateName() }; var createResponse = await testBase.client.Cache.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, cacheid, cacheContract); Assert.NotNull(createResponse); Assert.Equal(cacheid, createResponse.Name); Assert.Equal(cacheContract.Description, createResponse.Description); // get the certificate to check is was created var getResponse = await testBase.client.Cache.GetWithHttpMessagesAsync( testBase.rgName, testBase.serviceName, cacheid); Assert.NotNull(getResponse); Assert.Equal(cacheid, getResponse.Body.Name); // list caches cacheListResponse = testBase.client.Cache.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(cacheListResponse); Assert.Single(cacheListResponse); // remove the certificate testBase.client.Cache.Delete( testBase.rgName, testBase.serviceName, cacheid, getResponse.Headers.ETag); // list again to see it was removed cacheListResponse = testBase.client.Cache.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(cacheListResponse); Assert.Empty(cacheListResponse); } finally { testBase.client.Cache.Delete(testBase.rgName, testBase.serviceName, cacheid, "*"); // clean up all properties var listOfProperties = testBase.client.NamedValue.ListByService( testBase.rgName, testBase.serviceName); foreach (var property in listOfProperties) { testBase.client.NamedValue.Delete( testBase.rgName, testBase.serviceName, property.Name, "*"); } } } }