Beispiel #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);
            }
        }
Beispiel #2
0
        public void Test_GetQuota()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var quotaExtensionClient = QuotaTestUtilities.GetAzureQuotaExtensionAPIClient(
                    context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                var quota = quotaExtensionClient.Quota.Get(resourceName, scope);

                Assert.Equal(quota.Name, resourceName, ignoreCase: true);
            }
        }
Beispiel #3
0
        public void Test_GetQuotaRequest()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            string requestId = "2c3d0274-10b6-44ae-82ed-a0647057d696";

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var quotaExtensionClient = QuotaTestUtilities.GetAzureQuotaExtensionAPIClient(
                    context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                var quotaRequests = quotaExtensionClient.QuotaRequestStatus.Get(requestId, scope);

                Assert.Equal(quotaRequests.Name, requestId, ignoreCase: true);
            }
        }
Beispiel #4
0
        public void Test_ListQuotaRequest()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var quotaExtensionClient = QuotaTestUtilities.GetAzureQuotaExtensionAPIClient(
                    context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                var quotaRequests = quotaExtensionClient.QuotaRequestStatus.List(scope);

                Assert.True(quotaRequests.All(x =>
                                              string.Equals(x.Type, "Microsoft.Quota/QuotaRequests", StringComparison.OrdinalIgnoreCase)
                                              ));
            }
        }
Beispiel #5
0
        public void Test_ListQuotaRequestWithFilter()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            int    top    = 5;
            string filter = "provisioningState eq 'Failed'";

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var quotaExtensionClient = QuotaTestUtilities.GetAzureQuotaExtensionAPIClient(
                    context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                var quotaRequests = quotaExtensionClient.QuotaRequestStatus.List(scope, filter: filter, top: top);

                Assert.True(quotaRequests.Count() == top);

                Assert.True(quotaRequests.All(x =>
                                              string.Equals(x.ProvisioningState, "Failed", StringComparison.OrdinalIgnoreCase)
                                              ));
            }
        }
Beispiel #6
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());
            }
        }