Пример #1
0
        public void Test_SetQuota()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var quotaExtensionClient = QuotaTestUtilities.GetAzureQuotaExtensionAPIClient(
                    context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                var newQuotaLimit = new QuotaProperties()
                {
                    Limit = new LimitObject()
                    {
                        Value = 1005
                    },
                    Name = new ResourceName()
                    {
                        Value = resourceName
                    }
                };

                var quotaRequest = quotaExtensionClient.Quota.BeginCreateOrUpdate(resourceName, scope, newQuotaLimit);

                // 202 response has no response body
                Assert.True(quotaRequest == null);
            }
        }
Пример #2
0
        internal static CurrentQuotaLimitBaseData DeserializeCurrentQuotaLimitBaseData(JsonElement element)
        {
            Optional <QuotaProperties> properties = default;
            ResourceIdentifier         id         = default;
            string       name       = default;
            ResourceType type       = default;
            SystemData   systemData = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    properties = QuotaProperties.DeserializeQuotaProperties(property.Value);
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
            }
            return(new CurrentQuotaLimitBaseData(id, name, type, systemData, properties.Value));
        }
Пример #3
0
        public void Test_SetQuotaInvalidResourceName()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            try
            {
                using (MockContext context = MockContext.Start(this.GetType()))
                {
                    var quotaExtensionClient = QuotaTestUtilities.GetAzureQuotaExtensionAPIClient(
                        context, new RecordedDelegatingHandler {
                        StatusCodeToReturn = HttpStatusCode.OK
                    });

                    var newQuotaLimit = new QuotaProperties()
                    {
                        Limit = new LimitObject()
                        {
                            Value = 1005
                        },
                        Name = new ResourceName()
                        {
                            Value = "PublicIPAddress"
                        }
                    };

                    var quotaRequest = quotaExtensionClient.Quota.BeginCreateOrUpdate(
                        "PublicIPAddress", scope, newQuotaLimit);

                    Assert.True(quotaRequest == null);
                }
            }
            catch (ExceptionResponseException ex)
            {
                Assert.True(ex.Response.StatusCode == HttpStatusCode.BadRequest);
                Assert.Contains("InvalidResourceName", ex.ToString());
            }
        }
Пример #4
0
 internal CurrentQuotaLimitBaseData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, QuotaProperties properties) : base(id, name, resourceType, systemData)
 {
     Properties = properties;
 }
Пример #5
0
 /// <summary>
 /// Update the quota limit for a specific resource to the specified value:
 /// 1. Use the Usages-GET and Quota-GET operations to determine the remaining
 /// quota for the specific resource and to calculate the new quota limit. These
 /// steps are detailed in [this
 /// example](https://techcommunity.microsoft.com/t5/azure-governance-and-management/using-the-new-quota-rest-api/ba-p/2183670).
 /// 2. Use this PUT operation to update the quota limit. Please check the URI
 /// in location header for the detailed status of the request.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceName'>
 /// Resource name for a given resource provider. For example:
 /// - SKU name for Microsoft.Compute
 /// - SKU or TotalLowPriorityCores for Microsoft.MachineLearningServices
 /// For Microsoft.Network PublicIPAddresses.
 /// </param>
 /// <param name='scope'>
 /// The target Azure resource URI. For example,
 /// `/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/qms-test/providers/Microsoft.Batch/batchAccounts/testAccount/`.
 /// This is the target Azure resource URI for the List GET operation. If a
 /// `{resourceName}` is added after `/quotas`, then it's the target Azure
 /// resource URI in the GET operation for the specific resource.
 /// </param>
 /// <param name='properties'>
 /// Quota properties for the specified resource, based on the API called,
 /// Quotas or Usages.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <CurrentQuotaLimitBase> BeginUpdateAsync(this IQuotaOperations operations, string resourceName, string scope, QuotaProperties properties = default(QuotaProperties), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceName, scope, properties, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #6
0
 /// <summary>
 /// Update the quota limit for a specific resource to the specified value:
 /// 1. Use the Usages-GET and Quota-GET operations to determine the remaining
 /// quota for the specific resource and to calculate the new quota limit. These
 /// steps are detailed in [this
 /// example](https://techcommunity.microsoft.com/t5/azure-governance-and-management/using-the-new-quota-rest-api/ba-p/2183670).
 /// 2. Use this PUT operation to update the quota limit. Please check the URI
 /// in location header for the detailed status of the request.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceName'>
 /// Resource name for a given resource provider. For example:
 /// - SKU name for Microsoft.Compute
 /// - SKU or TotalLowPriorityCores for Microsoft.MachineLearningServices
 /// For Microsoft.Network PublicIPAddresses.
 /// </param>
 /// <param name='scope'>
 /// The target Azure resource URI. For example,
 /// `/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/qms-test/providers/Microsoft.Batch/batchAccounts/testAccount/`.
 /// This is the target Azure resource URI for the List GET operation. If a
 /// `{resourceName}` is added after `/quotas`, then it's the target Azure
 /// resource URI in the GET operation for the specific resource.
 /// </param>
 /// <param name='properties'>
 /// Quota properties for the specified resource, based on the API called,
 /// Quotas or Usages.
 /// </param>
 public static CurrentQuotaLimitBase BeginUpdate(this IQuotaOperations operations, string resourceName, string scope, QuotaProperties properties = default(QuotaProperties))
 {
     return(operations.BeginUpdateAsync(resourceName, scope, properties).GetAwaiter().GetResult());
 }