private static void RunSwaggerTest(string resourceType, string apiVersion, string swaggerFileName) { SwaggerSpecHelper.RunTests( Path.Combine(Core.Utilities.Extensions.CodeBaseDirectory, "Resource", "Swagger", resourceType, apiVersion, swaggerFileName), Path.Combine(Core.Utilities.Extensions.CodeBaseDirectory, "Resource", "Expected", resourceType, apiVersion), plugin: "AzureResourceSchema"); }
public void EnsureTestCoverage() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("azure-report.json"), ExpectedPath("AzureReport")); using (var client = new AutoRestReportServiceForAzure(Fixture.Uri, new TokenCredentials(Guid.NewGuid().ToString()))) { var report = client.GetReport(); #if MONO float totalTests = report.Count - 5; #else float totalTests = report.Count; #endif float executedTests = report.Values.Count(v => v > 0); if (executedTests < totalTests) { report.ForEach(r => _output.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.TestCoverageReportItemFormat, r.Key, r.Value))); _output.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.TestCoverageReportSummaryFormat, executedTests, totalTests)); Assert.Equal(executedTests, totalTests); } } }
public static void SampleTestForGeneratingPython() { SwaggerSpecHelper.RunTests( SwaggerPath("storage.json"), ExpectedPath("StorageManagementClient"), plugin: "Azure.Python", nameSpace: "fixtures.acceptancetestsstoragemanagementclient"); }
public void CanRoundTripSequences() { SwaggerSpecHelper.RunTests <CSharpCodeGenerator>( SwaggerPath("swagger-mirror-sequences.json"), ExpectedPath("Mirror.Sequences")); using (var sequenceClient = MirrorTestHelpers.CreateSequenceClient()) { var testList = new List <int?> { 1, 1, 2, 3, 5, 8, 13, 21 }; var intList = sequenceClient.AddPetStyles(testList); MirrorTestHelpers.ValidateList(testList, intList, (s, t) => Assert.Equal(s, t)); var petList = new List <Pet> { new Pet { Id = 1, Name = "fluffy", Tag = "rabbit", Styles = new List <PetStyle> { new PetStyle { Name = "cute" }, new PetStyle { Name = "cuddly" } } }, new Pet { Id = 2, Name = "rex", Tag = "dog", Styles = new List <PetStyle> { new PetStyle { Name = "friendly" }, new PetStyle { Name = "loyal" } } }, new Pet { Id = 10111, Name = "Tabby", Tag = "cat", Styles = new List <PetStyle> { new PetStyle { Name = "independent" } } } }; var actualPets = sequenceClient.AddPet(petList); MirrorTestHelpers.ValidateList(petList, actualPets, MirrorTestHelpers.ValidatePet); } }
public static void SampleTestForGeneratingNodeJS() { SwaggerSpecHelper.RunTests <NodeJSCodeGenerator>( new Settings { Input = SwaggerPath("body-complex.json"), OutputDirectory = "X:\\Output", Header = "MICROSOFT_MIT", Modeler = "Swagger", CodeGenerator = "NodeJS", PayloadFlatteningThreshold = 1 }, ExpectedPath("BodyComplex")); }
public static void GeneratingComplexModelDefinitionsInNodeJS() { SwaggerSpecHelper.RunTests <NodeJSCodeGenerator>( new Settings { Input = SwaggerPath("complex-model.json"), OutputDirectory = "X:\\Output", Header = "MICROSOFT_MIT", Modeler = "Swagger", CodeGenerator = "NodeJS", PayloadFlatteningThreshold = 1 }, ExpectedPath("ComplexModelClient")); }
public void DurationTests() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("body-duration.json"), ExpectedPath("AzureBodyDuration")); using (var client = new AutoRestDurationTestService(Fixture.Uri)) { Assert.Null(client.Duration.GetNull()); Assert.Throws <FormatException>(() => client.Duration.GetInvalid()); client.Duration.GetPositiveDuration(); client.Duration.PutPositiveDuration(new TimeSpan(123, 22, 14, 12, 11)); } }
public void HeadTests() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("head.json"), ExpectedPath("Head")); using ( var client = new AutoRestHeadTestService(Fixture.Uri, new TokenCredentials(Guid.NewGuid().ToString()))) { Assert.True(client.HttpSuccess.Head204()); Assert.False(client.HttpSuccess.Head404()); } }
public void CanSerializeAndDeserializePrimitiveTypes() { // first regen the spec SwaggerSpecHelper.RunTests <CSharpCodeGenerator>( SwaggerPath("swagger-mirror-primitives.json"), ExpectedPath("Mirror.Primitives")); //Now run mocked tests using the client var product = MirrorTestHelpers.GenerateProduct(); using (var client = MirrorTestHelpers.CreateDataClient()) { var response = client.PutProduct("200", product); MirrorTestHelpers.ValidateProduct(product, response); } }
public void AzureUrlTests() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("subscriptionId-apiVersion.json"), ExpectedPath("SubscriptionIdApiVersion")); 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); } }
public void CustomNamedRequestIdTest() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("azure-special-properties.json"), ExpectedPath("AzureSpecials")); 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()))) { AzureOperationResponse response = client.Header.CustomNamedRequestIdWithHttpMessagesAsync(expectedRequestId).Result; Assert.Equal("123", response.RequestId); } }
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"; SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("azure-special-properties.json"), ExpectedPath("AzureSpecials")); 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); } }
public void PagingHappyPathTests() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("paging.json"), ExpectedPath("Paging")); 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); } }
public static void SampleTestForGeneratingAzureNodeJS() { SwaggerSpecHelper.RunTests <AzureNodeJSCodeGenerator>( SwaggerPath("storage.json"), ExpectedPath("StorageManagementClient")); }
private static void RunSwaggerTest(string swaggerFileName, string expectedFolderName) { SwaggerSpecHelper.RunTests <AzureResourceSchemaCodeGenerator>( Path.Combine("Swagger", swaggerFileName), Path.Combine("Expected", expectedFolderName)); }
private static void RunSwaggerTest(string resourceType, string apiVersion, string swaggerFileName) { SwaggerSpecHelper.RunTests( Path.Combine("Swagger", resourceType, apiVersion, swaggerFileName), Path.Combine("Expected", resourceType, apiVersion), plugin: "AzureResourceSchema"); }
public void ResourceFlatteningGenerationTest() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("resource-flattening.json"), ExpectedPath("ResourceFlattening")); }
public void LroHappyPathTests() { SwaggerSpecHelper.RunTests <AzureCSharpCodeGenerator>( SwaggerPath("lro.json"), ExpectedPath("Lro")); 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); Assert.NotNull(client.LROsCustomHeader.Put201CreatingSucceeded200WithHttpMessagesAsync( new Product { Location = "West US" }, customHeaders).Result); Assert.NotNull(client.LROsCustomHeader.Post202Retry200WithHttpMessagesAsync( new Product { Location = "West US" }, customHeaders).Result); } }
public static void SampleTestForGeneratingPython() { SwaggerSpecHelper.RunTests <PythonCodeGenerator>( SwaggerPath("body-complex.json"), ExpectedPath("BodyComplex")); }
public static void SampleTestForGeneratingPython() { SwaggerSpecHelper.RunTests( SwaggerPath("body-complex.json"), ExpectedPath("BodyComplex"), plugin: "Python"); }
private static void RunSwaggerTest(string resourceType, string apiVersion, string swaggerFileName) { SwaggerSpecHelper.RunTests <AzureResourceSchemaCodeGenerator>( Path.Combine("Swagger", resourceType, apiVersion, swaggerFileName), Path.Combine("Expected", resourceType, apiVersion)); }
public static void SampleTestForGeneratingPython() { SwaggerSpecHelper.RunTests( SwaggerPath("storage.json"), ExpectedPath("StorageManagementClient"), plugin: "Azure.Python"); }