示例#1
0
        public void EnsureTestCoverage()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("azure-report.json"), ExpectedPath("AzureReport"), generator: "Azure.CSharp");
            using (var client =
                       new AutoRestReportServiceForAzure(Fixture.Uri,
                                                         new TokenCredentials(Guid.NewGuid().ToString())))
            {
                var report = client.GetReport();
#if PORTABLE
                float totalTests = report.Count - 6;
#else
                float totalTests = report.Count;
#endif
                float executedTests = report.Values.Count(v => v > 0);
                if (executedTests < totalTests)
                {
                    foreach (var r in report.Where(r => r.Value == 0))
                    {
                        _interceptor.Information(string.Format(CultureInfo.CurrentCulture,
                                                               "{0}/{1}", r.Key, r.Value));
                    }
                    _interceptor.Information(string.Format(CultureInfo.CurrentCulture,
                                                           "The test coverage for Azure is {0}/{1}",
                                                           executedTests, totalTests));
                    Assert.Equal(executedTests, totalTests);
                }
            }
        }
示例#2
0
 public void EnsureTestCoverage()
 {
     SwaggerSpecRunner.RunTests(
         SwaggerPath("azure-report.json"), ExpectedPath("AzureReport"), generator: "Azure.CSharp");
     using (var client =
                new AutoRestReportServiceForAzureClient(Fixture.Uri,
                                                        new TokenCredentials(Guid.NewGuid().ToString())))
     {
         var report = client.GetReport();
         // TODO: This is fudging some numbers. Fixing the actual problem is a priority.
         float totalTests    = report.Count - 11;
         float executedTests = report.Values.Count(v => v > 0);
         if (executedTests < totalTests)
         {
             foreach (var r in report.Where(r => r.Value == 0))
             {
                 _interceptor.Information(string.Format(CultureInfo.CurrentCulture,
                                                        "{0}/{1}", r.Key, r.Value));
             }
             _interceptor.Information(string.Format(CultureInfo.CurrentCulture,
                                                    "The test coverage for Azure is {0}/{1}",
                                                    executedTests, totalTests));
             Assert.Equal(totalTests, executedTests);
         }
     }
 }
示例#3
0
        public void PagingHappyPathTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("paging.json"), ExpectedPath("Paging"), generator: "Azure.CSharp");
            using (
                var client = new AutoRestPagingTestService(Fixture.Uri,
                                                           new TokenCredentials(Guid.NewGuid().ToString())))
            {
                Assert.Null(client.Paging.GetSinglePages().NextPageLink);

                var result = client.Paging.GetMultiplePages();
                Assert.NotNull(result.NextPageLink);
                int count = 1;
                while (result.NextPageLink != null)
                {
                    result = client.Paging.GetMultiplePagesNext(result.NextPageLink);
                    count++;
                }
                Assert.Equal(10, count);

                var options = new Fixtures.Azure.AcceptanceTestsPaging.Models.PagingGetMultiplePagesWithOffsetOptions();
                options.Offset = 100;
                result         = client.Paging.GetMultiplePagesWithOffset(options, "client-id");
                Assert.NotNull(result.NextPageLink);
                count = 1;
                while (result.NextPageLink != null)
                {
                    result = client.Paging.GetMultiplePagesWithOffsetNext(result.NextPageLink);
                    count++;
                }
                Assert.Equal(10, count);
                Assert.Equal(110, result.LastOrDefault().Properties.Id);

                result = client.Paging.GetMultiplePagesRetryFirst();
                Assert.NotNull(result.NextPageLink);
                count = 1;
                while (result.NextPageLink != null)
                {
                    result = client.Paging.GetMultiplePagesRetryFirstNext(result.NextPageLink);
                    count++;
                }
                Assert.Equal(10, count);

                result = client.Paging.GetMultiplePagesRetrySecond();
                Assert.NotNull(result.NextPageLink);
                count = 1;
                while (result.NextPageLink != null)
                {
                    result = client.Paging.GetMultiplePagesRetrySecondNext(result.NextPageLink);
                    count++;
                }
                Assert.Equal(10, count);
            }
        }
示例#4
0
 public void AzureCustomBaseUriTests()
 {
     SwaggerSpecRunner.RunTests(
         SwaggerPath("custom-baseUrl.json"), ExpectedPath("CustomBaseUri"), generator: "Azure.CSharp");
     using (var client = new AutoRestParameterizedHostTestClient(new TokenCredentials(Guid.NewGuid().ToString())))
     {
         // small modification to the "host" portion to include the port and the '.'
         client.Host = string.Format(CultureInfo.InvariantCulture, "{0}.:{1}", client.Host, Fixture.Port);
         Assert.Equal(HttpStatusCode.OK,
                      client.Paths.GetEmptyWithHttpMessagesAsync("local").Result.Response.StatusCode);
     }
 }
示例#5
0
        public void HeadExceptionTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("head-exceptions.json"), ExpectedPath("HeadExceptions"), generator: "Azure.CSharp");

            using (
                var client = new AutoRestHeadExceptionTestService(Fixture.Uri,
                                                                  new TokenCredentials(Guid.NewGuid().ToString())))
            {
                client.HeadException.Head200();
                client.HeadException.Head204();
                Assert.Throws <CloudException>(() => client.HeadException.Head404());
            }
        }
示例#6
0
        public void HeadTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("head.json"), ExpectedPath("Head"), generator: "Azure.CSharp");

            using (
                var client = new AutoRestHeadTestService(Fixture.Uri,
                                                         new TokenCredentials(Guid.NewGuid().ToString())))
            {
                Assert.True(client.HttpSuccess.Head200());
                Assert.True(client.HttpSuccess.Head204());
                Assert.False(client.HttpSuccess.Head404());
            }
        }
示例#7
0
        public void DurationTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("body-duration.json"), ExpectedPath("AzureBodyDuration"), generator: "Azure.CSharp");
            const string validSubscription = "1234-5678-9012-3456";

            using (var client = new AutoRestDurationTestService(Fixture.Uri,
                                                                new TokenCredentials(validSubscription, Guid.NewGuid().ToString())))
            {
                Assert.Null(client.Duration.GetNull());
                Assert.Throws <FormatException>(() => client.Duration.GetInvalid());

                client.Duration.GetPositiveDuration();
                client.Duration.PutPositiveDuration(new TimeSpan(123, 22, 14, 12, 11));
            }
        }
示例#8
0
        public void CustomNamedRequestIdTest()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("azure-special-properties.json"), ExpectedPath("AzureSpecials"), generator: "Azure.CSharp");

            const string validSubscription = "1234-5678-9012-3456";
            const string expectedRequestId = "9C4D50EE-2D56-4CD3-8152-34347DC9F2B0";

            using (var client = new AutoRestAzureSpecialParametersTestClient(Fixture.Uri,
                                                                             new TokenCredentials(validSubscription, Guid.NewGuid().ToString())))
            {
                IAzureOperationResponse response = client.Header.CustomNamedRequestIdWithHttpMessagesAsync(expectedRequestId).Result;

                Assert.Equal("123", response.RequestId);
            }
        }
示例#9
0
        public void AzureUrlTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("subscriptionId-apiVersion.json"), ExpectedPath("SubscriptionIdApiVersion"), generator: "Azure.CSharp");

            using (
                var client =
                    new MicrosoftAzureTestUrl(Fixture.Uri,
                                              new TokenCredentials(Guid.NewGuid().ToString())))
            {
                client.SubscriptionId = Guid.NewGuid().ToString();
                var group = client.Group.GetSampleResourceGroup("testgroup101");
                Assert.Equal("testgroup101", group.Name);
                Assert.Equal("West US", group.Location);
            }
        }
示例#10
0
        public void AzureSpecialParametersTests()
        {
            var validSubscription = "1234-5678-9012-3456";
            var validApiVersion   = "2.0";
            var unencodedPath     = "path1/path2/path3";
            var unencodedQuery    = "value1&q2=value2&q3=value3";

            SwaggerSpecRunner.RunTests(
                SwaggerPath("azure-special-properties.json"), ExpectedPath("AzureSpecials"), generator: "Azure.CSharp");
            using (
                var client = new AutoRestAzureSpecialParametersTestClient(Fixture.Uri,
                                                                          new TokenCredentials(Guid.NewGuid().ToString()))
            {
                SubscriptionId = validSubscription
            })
            {
                client.SubscriptionInCredentials.PostMethodGlobalNotProvidedValid();
                client.SubscriptionInCredentials.PostMethodGlobalValid();
                client.SubscriptionInCredentials.PostPathGlobalValid();
                client.SubscriptionInCredentials.PostSwaggerGlobalValid();
                client.SubscriptionInMethod.PostMethodLocalValid(validSubscription);
                client.SubscriptionInMethod.PostPathLocalValid(validSubscription);
                client.SubscriptionInMethod.PostSwaggerLocalValid(validSubscription);
                Assert.Throws <ValidationException>(() => client.SubscriptionInMethod.PostMethodLocalNull(null));

                client.ApiVersionDefault.GetMethodGlobalNotProvidedValid();
                client.ApiVersionDefault.GetMethodGlobalValid();
                client.ApiVersionDefault.GetPathGlobalValid();
                client.ApiVersionDefault.GetSwaggerGlobalValid();
                client.ApiVersionLocal.GetMethodLocalValid(validApiVersion);
                client.ApiVersionLocal.GetMethodLocalNull(null);
                client.ApiVersionLocal.GetPathLocalValid(validApiVersion);
                client.ApiVersionLocal.GetSwaggerLocalValid(validApiVersion);

                client.SkipUrlEncoding.GetMethodPathValid(unencodedPath);
                client.SkipUrlEncoding.GetPathPathValid(unencodedPath);
                client.SkipUrlEncoding.GetSwaggerPathValid(unencodedPath);
                client.SkipUrlEncoding.GetMethodQueryValid(unencodedQuery);
                client.SkipUrlEncoding.GetPathQueryValid(unencodedQuery);
                client.SkipUrlEncoding.GetSwaggerQueryValid(unencodedQuery);
                client.SkipUrlEncoding.GetMethodQueryNull();
                client.SkipUrlEncoding.GetMethodQueryNull(null);
            }
        }
示例#11
0
        public void AzureCustomBaseUriNegativeTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("custom-baseUrl.json"), ExpectedPath("CustomBaseUri"), generator: "Azure.CSharp");
            using (var client = new AutoRestParameterizedHostTestClient(new TokenCredentials(Guid.NewGuid().ToString())))
            {
                // use a bad acct name
                Assert.Throws <HttpRequestException>(() =>
                                                     client.Paths.GetEmpty("bad"));

                // pass in null
                Assert.Throws <ValidationException>(() => client.Paths.GetEmpty(null));

                // set the global parameter incorrectly
                client.Host = "badSuffix";
                Assert.Throws <HttpRequestException>(() =>
                                                     client.Paths.GetEmpty("local"));
            }
        }
示例#12
0
        public void PagingHappyPathTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("paging.json"), ExpectedPath("Paging"), generator: "Azure.CSharp");
            using (
                var client = new AutoRestPagingTestService(Fixture.Uri,
                                                           new TokenCredentials(Guid.NewGuid().ToString())))
            {
                Assert.Null(client.Paging.GetSinglePages().NextPageLink);

                var result = client.Paging.GetMultiplePages();
                Assert.NotNull(result.NextPageLink);
                int count = 1;
                while (result.NextPageLink != null)
                {
                    result = client.Paging.GetMultiplePagesNext(result.NextPageLink);
                    count++;
                }
                Assert.Equal(10, count);

                result = client.Paging.GetMultiplePagesRetryFirst();
                Assert.NotNull(result.NextPageLink);
                count = 1;
                while (result.NextPageLink != null)
                {
                    result = client.Paging.GetMultiplePagesRetryFirstNext(result.NextPageLink);
                    count++;
                }
                Assert.Equal(10, count);

                result = client.Paging.GetMultiplePagesRetrySecond();
                Assert.NotNull(result.NextPageLink);
                count = 1;
                while (result.NextPageLink != null)
                {
                    result = client.Paging.GetMultiplePagesRetrySecondNext(result.NextPageLink);
                    count++;
                }
                Assert.Equal(10, count);
            }
        }
示例#13
0
        public void AzureODataTests()
        {
            var validSubscription = "1234-5678-9012-3456";

            SwaggerSpecRunner.RunTests(
                SwaggerPath("azure-special-properties.json"), ExpectedPath("AzureSpecials"), generator: "Azure.CSharp");
            using (var client = new AutoRestAzureSpecialParametersTestClient(Fixture.Uri,
                                                                             new TokenCredentials(Guid.NewGuid().ToString()))
            {
                SubscriptionId = validSubscription
            })
            {
                var filter = new ODataQuery <OdataFilter>(f => f.Id > 5 && f.Name == "foo")
                {
                    Top     = 10,
                    OrderBy = "id"
                };
                Assert.Equal("$filter=id gt 5 and name eq 'foo'&$orderby=id&$top=10", filter.ToString());
                client.Odata.GetWithFilter(filter);
            }
        }
示例#14
0
        public void LroHappyPathTestsRest()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("lro.json"), ExpectedPath("Lro"), generator: "Azure.CSharp");
            using (
                var client = new AutoRestLongRunningOperationTestService(Fixture.Uri,
                                                                         new TokenCredentials(Guid.NewGuid().ToString())))
            {
                client.LongRunningOperationRetryTimeout = 0;

                var customHeaders = new Dictionary <string, List <string> >
                {
                    {
                        "x-ms-client-request-id", new List <string> {
                            "9C4D50EE-2D56-4CD3-8152-34347DC9F2B0"
                        }
                    }
                };

                Assert.Equal("Succeeded",
                             client.LRORetrys.Put201CreatingSucceeded200(new Product {
                    Location = "West US"
                }).ProvisioningState);
                Assert.Equal("Succeeded",
                             client.LRORetrys.PutAsyncRelativeRetrySucceeded(new Product {
                    Location = "West US"
                }).ProvisioningState);
                client.LRORetrys.Post202Retry200(new Product {
                    Location = "West US"
                });
                client.LRORetrys.PostAsyncRelativeRetrySucceeded(new Product {
                    Location = "West US"
                });

                Assert.NotNull(client.LROsCustomHeader.Put201CreatingSucceeded200WithHttpMessagesAsync(
                                   new Product {
                    Location = "West US"
                }, customHeaders).Result);
            }
        }
示例#15
0
 public void ResourceFlatteningGenerationTest()
 {
     SwaggerSpecRunner.RunTests(
         SwaggerPath("resource-flattening.json"), ExpectedPath("ResourceFlattening"), generator: "Azure.CSharp");
 }
示例#16
0
        public void LroHappyPathTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("lro.json"), ExpectedPath("Lro"), generator: "Azure.CSharp");
            using (
                var client = new AutoRestLongRunningOperationTestService(Fixture.Uri,
                                                                         new TokenCredentials(Guid.NewGuid().ToString())))
            {
                client.LongRunningOperationRetryTimeout = 0;

                Assert.Equal("Succeeded",
                             client.LROs.Put201CreatingSucceeded200(new Product {
                    Location = "West US"
                }).ProvisioningState);
                var exception =
                    Assert.Throws <CloudException>(
                        () => client.LROs.Put201CreatingFailed200(new Product {
                    Location = "West US"
                }));

                Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal);
                Assert.Equal("Succeeded",
                             client.LROs.Put200UpdatingSucceeded204(new Product {
                    Location = "West US"
                }).ProvisioningState);
                exception =
                    Assert.Throws <CloudException>(
                        () => client.LROs.Put200Acceptedcanceled200(new Product {
                    Location = "West US"
                }).ProvisioningState);
                Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal);
                Assert.Equal("Succeeded", client.LROs.PutNoHeaderInRetry(new Product {
                    Location = "West US"
                }).ProvisioningState);
                Assert.Equal("Succeeded", client.LROs.PutAsyncNoHeaderInRetry(new Product {
                    Location = "West US"
                }).ProvisioningState);
                Assert.Equal("Succeeded", client.LROs.PutSubResource(new SubProduct()).ProvisioningState);
                Assert.Equal("Succeeded", client.LROs.PutAsyncSubResource(new SubProduct()).ProvisioningState);
                Assert.Equal("100", client.LROs.PutNonResource(new Sku()).Id);
                Assert.Equal("100", client.LROs.PutAsyncNonResource(new Sku()).Id);
                client.LROs.Post202Retry200(new Product {
                    Location = "West US"
                });
                Assert.Equal("Succeeded", client.LROs.Put200Succeeded(new Product {
                    Location = "West US"
                }).ProvisioningState);
                Assert.Equal("100", client.LROs.Put200SucceededNoState(new Product {
                    Location = "West US"
                }).Id);
                Assert.Equal("100", client.LROs.Put202Retry200(new Product {
                    Location = "West US"
                }).Id);
                Assert.Equal("Succeeded",
                             client.LROs.PutAsyncRetrySucceeded(new Product {
                    Location = "West US"
                }).ProvisioningState);
                Assert.Equal("Succeeded",
                             client.LROs.PutAsyncNoRetrySucceeded(new Product {
                    Location = "West US"
                }).ProvisioningState);
                exception =
                    Assert.Throws <CloudException>(() => client.LROs.PutAsyncRetryFailed(new Product {
                    Location = "West US"
                }));
                Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal);
                exception =
                    Assert.Throws <CloudException>(
                        () => client.LROs.PutAsyncNoRetrycanceled(new Product {
                    Location = "West US"
                }));
                Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal);
                client.LROs.Delete204Succeeded();
                client.LROs.Delete202Retry200();
                client.LROs.Delete202NoRetry204();
                client.LROs.DeleteAsyncNoRetrySucceeded();
                client.LROs.DeleteNoHeaderInRetry();
                client.LROs.DeleteAsyncNoHeaderInRetry();
                exception = Assert.Throws <CloudException>(() => client.LROs.DeleteAsyncRetrycanceled());
                Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal);
                exception = Assert.Throws <CloudException>(() => client.LROs.DeleteAsyncRetryFailed());
                Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal);
                client.LROs.DeleteAsyncRetrySucceeded();
                client.LROs.DeleteProvisioning202Accepted200Succeeded();
                client.LROs.DeleteProvisioning202Deletingcanceled200();
                client.LROs.DeleteProvisioning202DeletingFailed200();
                client.LROs.Post202NoRetry204(new Product {
                    Location = "West US"
                });
                exception = Assert.Throws <CloudException>(() => client.LROs.PostAsyncRetryFailed());
                Assert.Contains("Long running operation failed with status 'Failed'", exception.Message,
                                StringComparison.Ordinal);
                Assert.NotNull(exception.Body);
                var error = exception.Body;
                Assert.NotNull(error.Code);
                Assert.NotNull(error.Message);
                exception = Assert.Throws <CloudException>(() => client.LROs.PostAsyncRetrycanceled());
                Assert.Contains("Long running operation failed with status 'Canceled'", exception.Message,
                                StringComparison.Ordinal);
                Product prod = client.LROs.PostAsyncRetrySucceeded();
                Assert.Equal("100", prod.Id);
                prod = client.LROs.PostAsyncNoRetrySucceeded();
                Assert.Equal("100", prod.Id);
                var sku = client.LROs.Post200WithPayload();
                Assert.Equal("1", sku.Id);
                // Retryable errors
                Assert.Equal("Succeeded",
                             client.LRORetrys.Put201CreatingSucceeded200(new Product {
                    Location = "West US"
                }).ProvisioningState);
                Assert.Equal("Succeeded",
                             client.LRORetrys.PutAsyncRelativeRetrySucceeded(new Product {
                    Location = "West US"
                }).ProvisioningState);
                client.LRORetrys.DeleteProvisioning202Accepted200Succeeded();
                client.LRORetrys.Delete202Retry200();
                client.LRORetrys.DeleteAsyncRelativeRetrySucceeded();
                client.LRORetrys.Post202Retry200(new Product {
                    Location = "West US"
                });
                client.LRORetrys.PostAsyncRelativeRetrySucceeded(new Product {
                    Location = "West US"
                });

                var customHeaders = new Dictionary <string, List <string> >
                {
                    {
                        "x-ms-client-request-id", new List <string> {
                            "9C4D50EE-2D56-4CD3-8152-34347DC9F2B0"
                        }
                    }
                };

                Assert.NotNull(client.LROsCustomHeader.PutAsyncRetrySucceededWithHttpMessagesAsync(
                                   new Product {
                    Location = "West US"
                }, customHeaders).Result);

                Assert.NotNull(client.LROsCustomHeader.PostAsyncRetrySucceededWithHttpMessagesAsync(
                                   new Product {
                    Location = "West US"
                }, customHeaders).Result);

                // Failing in CoreCLR - TODO: debug and fix
                // Assert.NotNull(client.LROsCustomHeader.Put201CreatingSucceeded200WithHttpMessagesAsync(
                //                    new Product { Location = "West US" }, customHeaders).Result);

                Assert.NotNull(client.LROsCustomHeader.Post202Retry200WithHttpMessagesAsync(
                                   new Product {
                    Location = "West US"
                }, customHeaders).Result);
            }
        }