示例#1
0
 public void IsCreateResourceMethodNoReturnType()
 {
     Assert.False(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod(body: new Parameter()
     {
         Location = ParameterLocation.Body
     })));
 }
示例#2
0
        public void ParseWithEmptyServiceClient()
        {
            ServiceClient serviceClient = new ServiceClient();
            IDictionary <string, ResourceSchema> schemas = ResourceSchemaParser.Parse(serviceClient);

            Assert.NotNull(schemas);
            Assert.Equal(0, schemas.Count);
        }
示例#3
0
        public void GetResourceTypesParameterReferenceWithNoMatchingParameterDefinition()
        {
            const string     provider          = "Microsoft.Network";
            const string     pathAfterProvider = "dnszones/{zoneName}/{recordType}/{relativeRecordSetName}";
            List <Parameter> methodParameters  = new List <Parameter>();

            Assert.Throws <ArgumentException>(() => { ResourceSchemaParser.GetResourceTypes(provider, pathAfterProvider, methodParameters); });
        }
示例#4
0
 public void IsCreateResourceMethodWithCompositeNonResourceReturnType()
 {
     Assert.False(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod(
                                                                  body: new Parameter()
     {
         Location = ParameterLocation.Body
     },
                                                                  responseBody: new CompositeType())));
 }
示例#5
0
 public void IsCreateResourceMethodWithNonResourceReturnType()
 {
     Assert.False(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod(
                                                                  body: new Parameter()
     {
         Location = ParameterLocation.Body
     },
                                                                  responseBody: new PrimaryType(KnownPrimaryType.Int))));
 }
        public void ParseWithServiceClientWithCreateResourceMethod()
        {
            ServiceClient serviceClient = new ServiceClient();

            serviceClient.ApiVersion = "2016-01-01";

            Parameter body = new Parameter()
            {
                Location = ParameterLocation.Body,
                Type     = new CompositeType(),
            };

            CompositeType responseBody = new CompositeType();

            responseBody.Extensions.Add("x-ms-azure-resource", true);

            const string url = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Mock.Provider/mockResourceNames/{mockResourceName}";

            Method method = new Method()
            {
                HttpMethod = HttpMethod.Put,
                ReturnType = new Response(responseBody, null),
                Url        = url,
            };

            method.Parameters.Add(body);

            serviceClient.Methods.Add(method);

            IDictionary <string, ResourceSchema> schemas = ResourceSchemaParser.Parse(serviceClient);

            Assert.NotNull(schemas);
            Assert.Equal(1, schemas.Count);

            ResourceSchema schema = schemas["Mock.Provider"];

            Assert.Equal("http://schema.management.azure.com/schemas/2016-01-01/Mock.Provider.json#", schema.Id);
            Assert.Equal("http://json-schema.org/draft-04/schema#", schema.Schema);
            Assert.Equal("Mock.Provider", schema.Title);
            Assert.Equal("Mock Provider Resource Types", schema.Description);
            Assert.Equal(1, schema.ResourceDefinitions.Count);
            Assert.Equal("mockResourceNames", schema.ResourceDefinitions.Keys.Single());
            Assert.Equal(
                new JsonSchema()
            {
                JsonType    = "object",
                Description = "Mock.Provider/mockResourceNames"
            }
                .AddProperty("type", JsonSchema.CreateStringEnum("Mock.Provider/mockResourceNames"), true)
                .AddProperty("apiVersion", JsonSchema.CreateStringEnum("2016-01-01"), true),
                schema.ResourceDefinitions["mockResourceNames"]);
            Assert.NotNull(schema.Definitions);
            Assert.Equal(0, schema.Definitions.Count);
        }
示例#7
0
        public void ParseWithCodeModelWithCreateResourceMethod()
        {
            CodeModel codeModel = New <CodeModel>();

            codeModel.ApiVersion = "2016-01-01";

            Parameter body = New <Parameter>(new
            {
                Location = ParameterLocation.Body,
                Type     = New <CompositeType>(),
            });

            CompositeType responseBody = New <CompositeType>();

            responseBody.Extensions.Add("x-ms-azure-resource", true);

            const string url = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Mock.Provider/mockResourceNames/{mockResourceName}";

            Method method = New <Method>(new
            {
                HttpMethod = HttpMethod.Put,
                ReturnType = new Response(responseBody, null),
                Url        = url,
            });

            method.Add(body);

            codeModel.Add(method);

            var schemas = ResourceSchemaParser.Parse(codeModel, codeModel.ApiVersion, false);

            Assert.NotNull(schemas);
            Assert.Equal(1, schemas.Count);

            ResourceSchema schema = schemas["Mock.Provider"];

            Assert.Equal("https://schema.management.azure.com/schemas/2016-01-01/Mock.Provider.json#", schema.Id);
            Assert.Equal("http://json-schema.org/draft-04/schema#", schema.Schema);
            Assert.Equal("Mock.Provider", schema.Title);
            Assert.Equal("Mock Provider Resource Types", schema.Description);
            Assert.Equal(1, schema.ResourceDefinitions.Count);
            Assert.Equal("mockResourceNames", schema.ResourceDefinitions.Keys.Single());
            Assert.Equal(
                new JsonSchema()
            {
                JsonType    = "object",
                Description = "Mock.Provider/mockResourceNames"
            }
                .AddProperty("type", JsonSchema.CreateSingleValuedEnum("Mock.Provider/mockResourceNames"), true)
                .AddProperty("apiVersion", JsonSchema.CreateSingleValuedEnum("2016-01-01"), true),
                schema.ResourceDefinitions["mockResourceNames"].Schema);
            Assert.NotNull(schema.Definitions);
            Assert.Equal(0, schema.Definitions.Count);
        }
示例#8
0
        public void IsCreateResourceMethodWithResourceReturnTypeButNoUrl()
        {
            CompositeType responseBody = new CompositeType();

            responseBody.Extensions.Add("x-ms-azure-resource", true);

            Assert.False(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod(
                                                                         body: new Parameter()
            {
                Location = ParameterLocation.Body
            },
                                                                         responseBody: responseBody)));
        }
示例#9
0
        public void IsCreateResourceMethodWhenUrlDoesntEndWithResourceNamePlaceholder()
        {
            CompositeType responseBody = new CompositeType();

            responseBody.Extensions.Add("x-ms-azure-resource", true);

            Assert.False(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod(
                                                                         body: new Parameter()
            {
                Location = ParameterLocation.Body
            },
                                                                         responseBody: responseBody,
                                                                         url: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/slotConfigNames")));
        }
示例#10
0
        public void IsCreateResourceMethodWithResourceReturnTypeAndUrl()
        {
            CompositeType responseBody = new CompositeType();

            responseBody.Extensions.Add("x-ms-azure-resource", true);

            Assert.True(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod(
                                                                        body: new Parameter()
            {
                Location = ParameterLocation.Body
            },
                                                                        responseBody: responseBody,
                                                                        url: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Mock.Provider/mockResourceNames/{mockResourceName}")));
        }
示例#11
0
        public void ParseWithServiceClientWithCreateResourceMethod()
        {
            ServiceClient serviceClient = new ServiceClient();

            Parameter body = new Parameter()
            {
                Location = ParameterLocation.Body,
                Type     = new CompositeType(),
            };

            CompositeType responseBody = new CompositeType();

            responseBody.Extensions.Add("x-ms-azure-resource", true);

            const string url = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Mock.Provider/mockResourceNames/{mockResourceName}";

            Method method = CreateMethod(body: body, responseBody: responseBody, url: url);

            serviceClient.Methods.Add(method);

            IDictionary <string, ResourceSchema> schemas = ResourceSchemaParser.Parse(serviceClient);

            Assert.NotNull(schemas);
            Assert.Equal(1, schemas.Count);

            ResourceSchema schema = schemas["Mock.Provider"];

            Assert.Null(schema.Id);
            Assert.Equal("http://json-schema.org/draft-04/schema#", schema.Schema);
            Assert.Equal("Mock.Provider", schema.Title);
            Assert.Equal("Mock Provider Resource Types", schema.Description);
            Assert.Equal(1, schema.ResourceDefinitions.Count);
            Assert.Equal("mockResourceNames", schema.ResourceDefinitions.Keys.Single());
            Assert.Equal(
                new JsonSchema()
            {
                JsonType    = "object",
                Description = "Mock.Provider/mockResourceNames"
            }
                .AddProperty("type", new JsonSchema()
            {
                JsonType = "string"
            }
                             .AddEnum("Mock.Provider/mockResourceNames"),
                             true),
                schema.ResourceDefinitions["mockResourceNames"]);
            Assert.NotNull(schema.Definitions);
            Assert.Equal(0, schema.Definitions.Count);
        }
示例#12
0
        public void GetResourceTypesWithParameterReferenceWithParameterDefinitionWithEnumTypeWithNoValues()
        {
            const string     provider          = "Microsoft.Network";
            const string     pathAfterProvider = "dnszones/{zoneName}/{recordType}/{relativeRecordSetName}";
            List <Parameter> methodParameters  = new List <Parameter>()
            {
                new Parameter()
                {
                    Name = "recordType",
                    Type = new EnumType()
                }
            };

            Assert.Throws <ArgumentException>(() => { ResourceSchemaParser.GetResourceTypes(provider, pathAfterProvider, methodParameters); });
        }
示例#13
0
        public void GetResourceTypesWithParameterReferenceWithParameterDefinitionWithEnumTypeWithMultipleValues()
        {
            const string provider          = "Microsoft.Network";
            const string pathAfterProvider = "dnszones/{zoneName}/{recordType}/{relativeRecordSetName}";
            EnumType     enumType          = new EnumType();

            enumType.Values.Add(new EnumValue()
            {
                Name = "A"
            });
            enumType.Values.Add(new EnumValue()
            {
                Name = "AAAA"
            });
            enumType.Values.Add(new EnumValue()
            {
                Name = "CNAME"
            });
            enumType.Values.Add(new EnumValue()
            {
                Name = "MX"
            });
            List <Parameter> methodParameters = new List <Parameter>()
            {
                new Parameter()
                {
                    Name = "recordType",
                    Type = enumType
                }
            };

            Assert.Equal(
                new string[]
            {
                "Microsoft.Network/dnszones/A",
                "Microsoft.Network/dnszones/AAAA",
                "Microsoft.Network/dnszones/CNAME",
                "Microsoft.Network/dnszones/MX"
            },
                ResourceSchemaParser.GetResourceTypes(provider, pathAfterProvider, methodParameters));
        }
示例#14
0
 public void GetResourceTypesWithOneLevelOfResources()
 {
     Assert.Equal(new string[] { "Microsoft.Cdn/profiles" }, ResourceSchemaParser.GetResourceTypes("Microsoft.Cdn", "profiles/{profileName}", new List <Parameter>()));
 }
示例#15
0
 public void IsCreateResourceMethodWithNoBody()
 {
     Assert.False(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod()));
 }
示例#16
0
 public void IsCreateResourceMethodWithGetHttpMethod()
 {
     Assert.False(ResourceSchemaParser.IsCreateResourceMethod(CreateMethod(HttpMethod.Get)));
 }
示例#17
0
 public void IsCreateResourceMethodWithNullMethod()
 {
     Assert.Throws <ArgumentNullException>(() => { ResourceSchemaParser.IsCreateResourceMethod(null); });
 }
 public void GetResourceTypeWithMultipleLevelsOfResources()
 {
     Assert.Equal("Microsoft.Cdn/profiles/endpoints/customDomains", ResourceSchemaParser.GetResourceType("Microsoft.Cdn", "profiles/{profileName}/endpoints/{endpointName}/customDomains/{customDomainName}"));
 }
示例#19
0
 public void GetResourceTypesWithMultipleLevelsOfResources()
 {
     Assert.Equal(new string[] { "Microsoft.Cdn/profiles/endpoints/customDomains" }, ResourceSchemaParser.GetResourceTypes("Microsoft.Cdn", "profiles/{profileName}/endpoints/{endpointName}/customDomains/{customDomainName}", new List <Parameter>()));
 }
 public void GetResourceTypeWithOneLevelOfResources()
 {
     Assert.Equal("Microsoft.Cdn/profiles", ResourceSchemaParser.GetResourceType("Microsoft.Cdn", "profiles/{profileName}"));
 }
示例#21
0
 public void ParseWithNullServiceClient()
 {
     Assert.Throws <ArgumentNullException>(() => { ResourceSchemaParser.Parse(null); });
 }