public async void ShouldCreateInitialAPITemplateResourceFromCreatorConfig()
        {
            // arrange
            APITemplateCreator apiTemplateCreator = APITemplateCreatorFactory.GenerateAPITemplateCreator();
            CreatorConfig      creatorConfig      = new CreatorConfig()
            {
                apis = new List <APIConfig>()
            };
            APIConfig api = new APIConfig()
            {
                name                   = "name",
                apiVersion             = "apiVersion",
                apiVersionDescription  = "apiVersionDescription",
                apiVersionSetId        = "apiVersionSetId",
                apiRevision            = "revision",
                apiRevisionDescription = "revisionDescription",
                suffix                 = "suffix",
                subscriptionRequired   = true,
                authenticationSettings = new APITemplateAuthenticationSettings()
                {
                    oAuth2 = new APITemplateOAuth2()
                    {
                        authorizationServerId = "",
                        scope = ""
                    },
                    openid = new APITemplateOpenID()
                    {
                        openidProviderId          = "",
                        bearerTokenSendingMethods = new string[] { }
                    },
                    subscriptionKeyRequired = true
                },
                openApiSpec = "https://petstore.swagger.io/v2/swagger.json",
                protocols   = "https",
                isCurrent   = true,
                type        = "http"
            };

            creatorConfig.apis.Add(api);

            // act
            APITemplateResource apiTemplateResource = await apiTemplateCreator.CreateAPITemplateResourceAsync(api, true, false);

            // assert
            Assert.Equal($"[concat(parameters('ApimServiceName'), '/{api.name}')]", apiTemplateResource.name);
            Assert.Equal(api.name, apiTemplateResource.properties.displayName);
            Assert.Equal(api.apiVersion, apiTemplateResource.properties.apiVersion);
            Assert.Equal(api.apiVersionDescription, apiTemplateResource.properties.apiVersionDescription);
            Assert.Equal(api.type, apiTemplateResource.properties.type);
            Assert.Equal(api.type, apiTemplateResource.properties.apiType);
            Assert.Equal(api.isCurrent, apiTemplateResource.properties.isCurrent);
            Assert.Equal(new string[] { api.protocols }, apiTemplateResource.properties.protocols);
            Assert.Equal($"[resourceId('Microsoft.ApiManagement/service/apiVersionSets', parameters('ApimServiceName'), '{api.apiVersionSetId}')]", apiTemplateResource.properties.apiVersionSetId);
            Assert.Equal(api.apiRevision, apiTemplateResource.properties.apiRevision);
            Assert.Equal(api.apiRevisionDescription, apiTemplateResource.properties.apiRevisionDescription);
            Assert.Equal(api.suffix, apiTemplateResource.properties.path);
            Assert.Equal(api.subscriptionRequired, apiTemplateResource.properties.subscriptionRequired);
            Assert.Equal(api.authenticationSettings.oAuth2.authorizationServerId, apiTemplateResource.properties.authenticationSettings.oAuth2.authorizationServerId);
            Assert.Equal(api.authenticationSettings.oAuth2.scope, apiTemplateResource.properties.authenticationSettings.oAuth2.scope);
            Assert.Equal(api.authenticationSettings.openid.openidProviderId, apiTemplateResource.properties.authenticationSettings.openid.openidProviderId);
            Assert.Equal(api.authenticationSettings.openid.bearerTokenSendingMethods, apiTemplateResource.properties.authenticationSettings.openid.bearerTokenSendingMethods);
            Assert.Equal(api.authenticationSettings.subscriptionKeyRequired, apiTemplateResource.properties.authenticationSettings.subscriptionKeyRequired);
        }
        public void ShouldCreateBackendTemplateFromCreatorConfig()
        {
            // arrange
            BackendTemplateCreator backendTemplateCreator = new BackendTemplateCreator();
            CreatorConfig          creatorConfig          = new CreatorConfig()
            {
                backends = new List <BackendTemplateProperties>()
            };
            BackendTemplateProperties backend = new BackendTemplateProperties()
            {
                title       = "title",
                description = "description",
                resourceId  = "resourceId",
                url         = "url",
                protocol    = "protocol",
                proxy       = new BackendProxy()
                {
                    url      = "url",
                    username = "******",
                    password = "******"
                },
                tls = new BackendTLS()
                {
                    validateCertificateChain = true,
                    validateCertificateName  = true
                },
                credentials = new BackendCredentials()
                {
                    certificate   = new string[] { "cert1" },
                    query         = new object(),
                    header        = new object(),
                    authorization = new BackendCredentialsAuthorization()
                    {
                        scheme    = "scheme",
                        parameter = "parameter"
                    }
                },
                properties = new BackendSubProperties()
                {
                    serviceFabricCluster = new BackendServiceFabricCluster()
                    {
                        clientCertificatethumbprint   = "",
                        managementEndpoints           = new string[] { "endpoint" },
                        maxPartitionResolutionRetries = 1,
                        serverCertificateThumbprints  = new string[] { "thumbprint" },
                        serverX509Names = new ServerX509Names[] {
                            new ServerX509Names()
                            {
                                name = "name",
                                issuerCertificateThumbprint = "thumbprint"
                            }
                        }
                    }
                }
            };

            creatorConfig.backends.Add(backend);

            // act
            Template backendTemplate = backendTemplateCreator.CreateBackendTemplate(creatorConfig);
            BackendTemplateResource backendTemplateResource = (BackendTemplateResource)backendTemplate.resources[0];

            // assert
            Assert.Equal($"[concat(parameters('ApimServiceName'), '/{backend.title}')]", backendTemplateResource.name);
            Assert.Equal(backend.title, backendTemplateResource.properties.title);
            Assert.Equal(backend.description, backendTemplateResource.properties.description);
            Assert.Equal(backend.resourceId, backendTemplateResource.properties.resourceId);
            Assert.Equal(backend.url, backendTemplateResource.properties.url);
            Assert.Equal(backend.protocol, backendTemplateResource.properties.protocol);
            Assert.Equal(backend.proxy.url, backendTemplateResource.properties.proxy.url);
            Assert.Equal(backend.proxy.username, backendTemplateResource.properties.proxy.username);
            Assert.Equal(backend.proxy.password, backendTemplateResource.properties.proxy.password);
            Assert.Equal(backend.tls.validateCertificateChain, backendTemplateResource.properties.tls.validateCertificateChain);
            Assert.Equal(backend.tls.validateCertificateName, backendTemplateResource.properties.tls.validateCertificateName);
            Assert.Equal(backend.credentials.certificate, backendTemplateResource.properties.credentials.certificate);
            Assert.Equal(backend.credentials.query, backendTemplateResource.properties.credentials.query);
            Assert.Equal(backend.credentials.header, backendTemplateResource.properties.credentials.header);
            Assert.Equal(backend.credentials.authorization.scheme, backendTemplateResource.properties.credentials.authorization.scheme);
            Assert.Equal(backend.credentials.authorization.parameter, backendTemplateResource.properties.credentials.authorization.parameter);
            Assert.Equal(backend.properties.serviceFabricCluster.clientCertificatethumbprint, backendTemplateResource.properties.properties.serviceFabricCluster.clientCertificatethumbprint);
            Assert.Equal(backend.properties.serviceFabricCluster.managementEndpoints, backendTemplateResource.properties.properties.serviceFabricCluster.managementEndpoints);
            Assert.Equal(backend.properties.serviceFabricCluster.maxPartitionResolutionRetries, backendTemplateResource.properties.properties.serviceFabricCluster.maxPartitionResolutionRetries);
            Assert.Equal(backend.properties.serviceFabricCluster.serverCertificateThumbprints, backendTemplateResource.properties.properties.serviceFabricCluster.serverCertificateThumbprints);
            Assert.Equal(backend.properties.serviceFabricCluster.serverX509Names[0].issuerCertificateThumbprint, backendTemplateResource.properties.properties.serviceFabricCluster.serverX509Names[0].issuerCertificateThumbprint);
            Assert.Equal(backend.properties.serviceFabricCluster.serverX509Names[0].name, backendTemplateResource.properties.properties.serviceFabricCluster.serverX509Names[0].name);
        }
        public Template CreateProductTemplate(CreatorConfig creatorConfig)
        {
            // create empty template
            Template productTemplate = this.templateBuilder.GenerateEmptyTemplate().Build();

            // add parameters
            productTemplate.Parameters = new Dictionary <string, TemplateParameterProperties>
            {
                { ParameterNames.ApimServiceName, new TemplateParameterProperties()
                  {
                      Type = "string"
                  } }
            };

            List <TemplateResource> resources = new List <TemplateResource>();

            foreach (ProductConfig product in creatorConfig.products)
            {
                if (string.IsNullOrEmpty(product.Name))
                {
                    product.Name = product.DisplayName;
                }
                // create product resource with properties
                ProductsTemplateResource productsTemplateResource = new ProductsTemplateResource()
                {
                    Name       = $"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{product.Name}')]",
                    Type       = ResourceTypeConstants.Product,
                    ApiVersion = GlobalConstants.ApiVersion,
                    Properties = new ProductsProperties()
                    {
                        Description          = product.Description,
                        Terms                = product.Terms,
                        SubscriptionRequired = product.SubscriptionRequired,
                        ApprovalRequired     = product.SubscriptionRequired ? product.ApprovalRequired : null,
                        SubscriptionsLimit   = product.SubscriptionRequired ? product.SubscriptionsLimit : null,
                        State                = product.State,
                        DisplayName          = product.DisplayName
                    },
                    DependsOn = new string[] { }
                };
                resources.Add(productsTemplateResource);

                // create product policy resource that depends on the product, if provided
                if (product.policy != null)
                {
                    string[] dependsOn = new string[] { $"[resourceId('Microsoft.ApiManagement/service/products', parameters('{ParameterNames.ApimServiceName}'), '{product.Name}')]" };
                    PolicyTemplateResource productPolicy = this.policyTemplateCreator.CreateProductPolicyTemplateResource(product, dependsOn);
                    resources.Add(productPolicy);
                }

                // create product group resources if provided
                if (product.groups != null)
                {
                    string[] dependsOn = new string[] { $"[resourceId('Microsoft.ApiManagement/service/products', parameters('{ParameterNames.ApimServiceName}'), '{product.Name}')]" };
                    List <GroupTemplateResource> productGroups = this.productGroupTemplateCreator.CreateProductGroupTemplateResources(product, dependsOn);
                    resources.AddRange(productGroups);
                }

                // create product subscriptions if provided
                if (product.subscriptions != null)
                {
                    string[] dependsOn = new string[] { $"[resourceId('Microsoft.ApiManagement/service/products', parameters('{ParameterNames.ApimServiceName}'), '{product.Name}')]" };
                    List <SubscriptionsTemplateResource> subscriptions = this.subscriptionTemplateCreator.CreateSubscriptionsTemplateResources(product, dependsOn);
                    resources.AddRange(subscriptions);
                }
            }

            productTemplate.Resources = resources.ToArray();
            return(productTemplate);
        }
        public Dictionary <string, TemplateParameterProperties> CreateMasterTemplateParameters(CreatorConfig creatorConfig)
        {
            // used to create the parameter metatadata, etc (not value) for use in file with resources
            // add parameters with metadata properties
            Dictionary <string, TemplateParameterProperties> parameters = new Dictionary <string, TemplateParameterProperties>();
            TemplateParameterProperties apimServiceNameProperties       = new TemplateParameterProperties()
            {
                Metadata = new TemplateParameterMetadata()
                {
                    Description = "Name of the API Management"
                },
                Type = "string"
            };

            parameters.Add(ParameterNames.ApimServiceName, apimServiceNameProperties);
            // add remote location of template files for linked option
            if (creatorConfig.linked == true)
            {
                TemplateParameterProperties linkedTemplatesBaseUrlProperties = new TemplateParameterProperties()
                {
                    Metadata = new TemplateParameterMetadata()
                    {
                        Description = "Base URL of the repository"
                    },
                    Type = "string"
                };
                parameters.Add(ParameterNames.LinkedTemplatesBaseUrl, linkedTemplatesBaseUrlProperties);
                if (creatorConfig.linkedTemplatesUrlQueryString != null)
                {
                    TemplateParameterProperties linkedTemplatesUrlQueryStringProperties = new TemplateParameterProperties()
                    {
                        Metadata = new TemplateParameterMetadata()
                        {
                            Description = "Query string for the URL of the repository"
                        },
                        Type = "string"
                    };
                    parameters.Add(ParameterNames.LinkedTemplatesUrlQueryString, linkedTemplatesUrlQueryStringProperties);
                }
            }

            // add serviceUrl parameter for linked option
            if (creatorConfig.serviceUrlParameters != null && creatorConfig.serviceUrlParameters.Count > 0)
            {
                foreach (var serviceUrlProperty in creatorConfig.serviceUrlParameters)
                {
                    TemplateParameterProperties serviceUrlParamProperty = new TemplateParameterProperties()
                    {
                        Metadata = new TemplateParameterMetadata()
                        {
                            Description = "ServiceUrl parameter for API: " + serviceUrlProperty.ApiName
                        },
                        Type = "string"
                    };
                    parameters.Add(serviceUrlProperty.ApiName + "-ServiceUrl", serviceUrlParamProperty);
                }
            }

            return(parameters);
        }
 public string GenerateLinkedTemplateUri(CreatorConfig creatorConfig, string fileName)
 {
     return(creatorConfig.linkedTemplatesUrlQueryString != null ?
            $"[concat(parameters('{ParameterNames.LinkedTemplatesBaseUrl}'), '{fileName}', parameters('{ParameterNames.LinkedTemplatesUrlQueryString}'))]"
      : $"[concat(parameters('{ParameterNames.LinkedTemplatesBaseUrl}'), '{fileName}')]");
 }
        public Template CreateLinkedMasterTemplate(CreatorConfig creatorConfig,
                                                   Template globalServicePolicyTemplate,
                                                   Template apiVersionSetTemplate,
                                                   Template productsTemplate,
                                                   Template productAPIsTemplate,
                                                   Template propertyTemplate,
                                                   Template loggersTemplate,
                                                   Template backendsTemplate,
                                                   Template authorizationServersTemplate,
                                                   Template tagTemplate,
                                                   List <LinkedMasterTemplateAPIInformation> apiInformation,
                                                   FileNames fileNames,
                                                   string apimServiceName)
        {
            // create empty template
            Template masterTemplate = this.templateBuilder.GenerateEmptyTemplate().Build();

            // add parameters
            masterTemplate.Parameters = this.CreateMasterTemplateParameters(creatorConfig);

            // add deployment resources that links to all resource files
            List <TemplateResource> resources = new List <TemplateResource>();

            // globalServicePolicy
            if (globalServicePolicyTemplate != null)
            {
                string globalServicePolicyUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.GlobalServicePolicy);
                resources.Add(this.CreateLinkedMasterTemplateResource("globalServicePolicyTemplate", globalServicePolicyUri, new string[] { }, null, false));
            }

            // apiVersionSet
            if (apiVersionSetTemplate != null)
            {
                string apiVersionSetUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.ApiVersionSets);
                resources.Add(this.CreateLinkedMasterTemplateResource("versionSetTemplate", apiVersionSetUri, new string[] { }, null, false));
            }

            // product
            if (productsTemplate != null)
            {
                string productsUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.Products);
                resources.Add(this.CreateLinkedMasterTemplateResource("productsTemplate", productsUri, new string[] { }, null, false));
            }

            // productApi
            if (productAPIsTemplate != null)
            {
                // depends on all products and APIs
                string[] dependsOn      = this.CreateProductAPIResourceDependencies(productsTemplate, apiInformation);
                string   productAPIsUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.ProductAPIs);
                resources.Add(this.CreateLinkedMasterTemplateResource("productAPIsTemplate", productAPIsUri, dependsOn, null, false));
            }

            // property
            if (propertyTemplate != null)
            {
                string propertyUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.NamedValues);
                resources.Add(this.CreateLinkedMasterTemplateResource("propertyTemplate", propertyUri, new string[] { }, null, false));
            }

            // logger
            if (loggersTemplate != null)
            {
                string loggersUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.Loggers);
                resources.Add(this.CreateLinkedMasterTemplateResource("loggersTemplate", loggersUri, new string[] { }, null, false));
            }

            // backend
            if (backendsTemplate != null)
            {
                string backendsUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.Backends);
                resources.Add(this.CreateLinkedMasterTemplateResource("backendsTemplate", backendsUri, new string[] { }, null, false));
            }

            // authorizationServer
            if (authorizationServersTemplate != null)
            {
                string authorizationServersUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.AuthorizationServers);
                resources.Add(this.CreateLinkedMasterTemplateResource("authorizationServersTemplate", authorizationServersUri, new string[] { }, null, false));
            }

            // tag
            if (tagTemplate != null)
            {
                string tagUri = this.GenerateLinkedTemplateUri(creatorConfig, fileNames.Tags);
                resources.Add(this.CreateLinkedMasterTemplateResource("tagTemplate", tagUri, new string[] { }, null, false));
            }

            string previousAPIName = null;

            // each api has an associated api info class that determines whether the api is split and its dependencies on other resources
            foreach (LinkedMasterTemplateAPIInformation apiInfo in apiInformation)
            {
                if (apiInfo.isSplit == true)
                {
                    // add a deployment resource for both api template files
                    string originalAPIName = FileNameGenerator.GenerateOriginalAPIName(apiInfo.name);
                    string subsequentAPIDeploymentResourceName = $"{originalAPIName}-SubsequentAPITemplate";
                    string initialAPIDeploymentResourceName    = $"{originalAPIName}-InitialAPITemplate";

                    string   initialAPIFileName  = FileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, true);
                    string   initialAPIUri       = this.GenerateLinkedTemplateUri(creatorConfig, initialAPIFileName);
                    string[] initialAPIDependsOn = this.CreateAPIResourceDependencies(creatorConfig, globalServicePolicyTemplate, apiVersionSetTemplate, productsTemplate, loggersTemplate, backendsTemplate, authorizationServersTemplate, tagTemplate, apiInfo, previousAPIName);
                    resources.Add(this.CreateLinkedMasterTemplateResource(initialAPIDeploymentResourceName, initialAPIUri, initialAPIDependsOn, originalAPIName, apiInfo.isServiceUrlParameterize));

                    string   subsequentAPIFileName  = FileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, false);
                    string   subsequentAPIUri       = this.GenerateLinkedTemplateUri(creatorConfig, subsequentAPIFileName);
                    string[] subsequentAPIDependsOn = new string[] { $"[resourceId('Microsoft.Resources/deployments', '{initialAPIDeploymentResourceName}')]" };
                    resources.Add(this.CreateLinkedMasterTemplateResource(subsequentAPIDeploymentResourceName, subsequentAPIUri, subsequentAPIDependsOn, originalAPIName, apiInfo.isServiceUrlParameterize));

                    // Set previous API name for dependency chain
                    previousAPIName = subsequentAPIDeploymentResourceName;
                }
                else
                {
                    // add a deployment resource for the unified api template file
                    string   originalAPIName = FileNameGenerator.GenerateOriginalAPIName(apiInfo.name);
                    string   subsequentAPIDeploymentResourceName = $"{originalAPIName}-SubsequentAPITemplate";
                    string   unifiedAPIDeploymentResourceName    = $"{originalAPIName}-APITemplate";
                    string   unifiedAPIFileName  = FileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, true);
                    string   unifiedAPIUri       = this.GenerateLinkedTemplateUri(creatorConfig, unifiedAPIFileName);
                    string[] unifiedAPIDependsOn = this.CreateAPIResourceDependencies(creatorConfig, globalServicePolicyTemplate, apiVersionSetTemplate, productsTemplate, loggersTemplate, backendsTemplate, authorizationServersTemplate, tagTemplate, apiInfo, previousAPIName);
                    resources.Add(this.CreateLinkedMasterTemplateResource(unifiedAPIDeploymentResourceName, unifiedAPIUri, unifiedAPIDependsOn, originalAPIName, apiInfo.isServiceUrlParameterize));

                    // Set previous API name for dependency chain
                    previousAPIName = subsequentAPIDeploymentResourceName;
                }
            }

            masterTemplate.Resources = resources.ToArray();
            return(masterTemplate);
        }
        public void ShouldCreateProductAPIFromCreatorConfig()
        {
            // arrange
            ProductAPITemplateCreator productAPITemplateCreator = new ProductAPITemplateCreator(new TemplateBuilder());
            CreatorConfig             creatorConfig             = new CreatorConfig()
            {
                products = new List <ProductConfig>(), apis = new List <APIConfig>()
            };
            ProductConfig product = new ProductConfig()
            {
                Name                 = "productName",
                DisplayName          = "display name",
                Description          = "description",
                Terms                = "terms",
                SubscriptionRequired = true,
                ApprovalRequired     = true,
                SubscriptionsLimit   = 1,
                State                = "state"
            };

            creatorConfig.products.Add(product);
            APIConfig api = new APIConfig()
            {
                name                   = "apiName",
                apiVersion             = "apiVersion",
                apiVersionDescription  = "apiVersionDescription",
                apiVersionSetId        = "apiVersionSetId",
                apiRevision            = "revision",
                apiRevisionDescription = "revisionDescription",
                suffix                 = "suffix",
                products               = "productName",
                subscriptionRequired   = true,
                authenticationSettings = new APITemplateAuthenticationSettings()
                {
                    OAuth2 = new APITemplateOAuth2()
                    {
                        AuthorizationServerId = "",
                        Scope = ""
                    },
                    Openid = new APITemplateOpenID()
                    {
                        OpenIdProviderId          = "",
                        BearerTokenSendingMethods = new string[] { }
                    },
                    SubscriptionKeyRequired = true
                },
                openApiSpec = "https://petstore.swagger.io/v2/swagger.json",
                protocols   = "https",
                isCurrent   = true,
                type        = "http"
            };

            creatorConfig.apis.Add(api);

            // act
            Template productAPITemplate = productAPITemplateCreator.CreateProductAPITemplate(creatorConfig);
            ProductApiTemplateResource productAPITemplateResource = (ProductApiTemplateResource)productAPITemplate.Resources[0];

            // assert
            Assert.Equal($"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{product.Name}/{api.name}')]", productAPITemplateResource.Name);
        }
        public void ShouldCreateBackendTemplateFromCreatorConfig()
        {
            // arrange
            BackendTemplateCreator backendTemplateCreator = new BackendTemplateCreator(new TemplateBuilder());
            CreatorConfig          creatorConfig          = new CreatorConfig()
            {
                backends = new List <BackendTemplateProperties>()
            };
            BackendTemplateProperties backend = new BackendTemplateProperties()
            {
                Title       = "title",
                Description = "description",
                ResourceId  = "resourceId",
                Url         = "url",
                Protocol    = "protocol",
                Proxy       = new BackendProxy()
                {
                    Url      = "url",
                    Username = "******",
                    Password = "******"
                },
                Tls = new BackendTls()
                {
                    ValidateCertificateChain = true,
                    ValidateCertificateName  = true
                },
                Credentials = new BackendCredentials()
                {
                    Certificate   = new string[] { "cert1" },
                    Query         = new object(),
                    Header        = new object(),
                    Authorization = new BackendCredentialsAuthorization()
                    {
                        Scheme    = "scheme",
                        Parameter = "parameter"
                    }
                },
                Properties = new BackendServiceFabricProperties()
                {
                    ServiceFabricCluster = new BackendServiceFabricCluster()
                    {
                        ClientCertificatethumbprint   = "",
                        ManagementEndpoints           = new string[] { "endpoint" },
                        MaxPartitionResolutionRetries = 1,
                        ServerCertificateThumbprints  = new string[] { "thumbprint" },
                        ServerX509Names = new ServerX509Names[] {
                            new ServerX509Names()
                            {
                                Name = "name",
                                IssuerCertificateThumbprint = "thumbprint"
                            }
                        }
                    }
                }
            };

            creatorConfig.backends.Add(backend);

            // act
            Template backendTemplate = backendTemplateCreator.CreateBackendTemplate(creatorConfig);
            BackendTemplateResource backendTemplateResource = (BackendTemplateResource)backendTemplate.Resources[0];

            // assert
            Assert.Equal($"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{backend.Title}')]", backendTemplateResource.Name);
            Assert.Equal(backend.Title, backendTemplateResource.Properties.Title);
            Assert.Equal(backend.Description, backendTemplateResource.Properties.Description);
            Assert.Equal(backend.ResourceId, backendTemplateResource.Properties.ResourceId);
            Assert.Equal(backend.Url, backendTemplateResource.Properties.Url);
            Assert.Equal(backend.Protocol, backendTemplateResource.Properties.Protocol);
            Assert.Equal(backend.Proxy.Url, backendTemplateResource.Properties.Proxy.Url);
            Assert.Equal(backend.Proxy.Username, backendTemplateResource.Properties.Proxy.Username);
            Assert.Equal(backend.Proxy.Password, backendTemplateResource.Properties.Proxy.Password);
            Assert.Equal(backend.Tls.ValidateCertificateChain, backendTemplateResource.Properties.Tls.ValidateCertificateChain);
            Assert.Equal(backend.Tls.ValidateCertificateName, backendTemplateResource.Properties.Tls.ValidateCertificateName);
            Assert.Equal(backend.Credentials.Certificate, backendTemplateResource.Properties.Credentials.Certificate);
            Assert.Equal(backend.Credentials.Query, backendTemplateResource.Properties.Credentials.Query);
            Assert.Equal(backend.Credentials.Header, backendTemplateResource.Properties.Credentials.Header);
            Assert.Equal(backend.Credentials.Authorization.Scheme, backendTemplateResource.Properties.Credentials.Authorization.Scheme);
            Assert.Equal(backend.Credentials.Authorization.Parameter, backendTemplateResource.Properties.Credentials.Authorization.Parameter);
            Assert.Equal(backend.Properties.ServiceFabricCluster.ClientCertificatethumbprint, backendTemplateResource.Properties.Properties.ServiceFabricCluster.ClientCertificatethumbprint);
            Assert.Equal(backend.Properties.ServiceFabricCluster.ManagementEndpoints, backendTemplateResource.Properties.Properties.ServiceFabricCluster.ManagementEndpoints);
            Assert.Equal(backend.Properties.ServiceFabricCluster.MaxPartitionResolutionRetries, backendTemplateResource.Properties.Properties.ServiceFabricCluster.MaxPartitionResolutionRetries);
            Assert.Equal(backend.Properties.ServiceFabricCluster.ServerCertificateThumbprints, backendTemplateResource.Properties.Properties.ServiceFabricCluster.ServerCertificateThumbprints);
            Assert.Equal(backend.Properties.ServiceFabricCluster.ServerX509Names[0].IssuerCertificateThumbprint, backendTemplateResource.Properties.Properties.ServiceFabricCluster.ServerX509Names[0].IssuerCertificateThumbprint);
            Assert.Equal(backend.Properties.ServiceFabricCluster.ServerX509Names[0].Name, backendTemplateResource.Properties.Properties.ServiceFabricCluster.ServerX509Names[0].Name);
        }
        public void ShouldCreateDiagnosticTemplateResourceFromCreatorConfig()
        {
            // arrange
            DiagnosticTemplateCreator diagnosticTemplateCreator = new DiagnosticTemplateCreator();
            CreatorConfig             creatorConfig             = new CreatorConfig()
            {
                api = new APIConfig()
                {
                    diagnostic = new DiagnosticConfig()
                    {
                        name      = "applicationinsights",
                        alwaysLog = "alwaysLog",
                        loggerId  = "loggerId",
                        sampling  = new DiagnosticTemplateSampling()
                        {
                            samplingType = "samplingType",
                            percentage   = 100
                        },
                        frontend = new DiagnosticTemplateFrontendBackend()
                        {
                            request = new DiagnosticTemplateRequestResponse()
                            {
                                headers = new string[] { "frontendrequestheader" },
                                body    = new DiagnosticTemplateRequestResponseBody()
                                {
                                    bytes = 512
                                }
                            },
                            response = new DiagnosticTemplateRequestResponse()
                            {
                                headers = new string[] { "frontendresponseheader" },
                                body    = new DiagnosticTemplateRequestResponseBody()
                                {
                                    bytes = 512
                                }
                            }
                        },
                        backend = new DiagnosticTemplateFrontendBackend()
                        {
                            request = new DiagnosticTemplateRequestResponse()
                            {
                                headers = new string[] { "backendrequestheader" },
                                body    = new DiagnosticTemplateRequestResponseBody()
                                {
                                    bytes = 512
                                }
                            },
                            response = new DiagnosticTemplateRequestResponse()
                            {
                                headers = new string[] { "backendresponseheader" },
                                body    = new DiagnosticTemplateRequestResponseBody()
                                {
                                    bytes = 512
                                }
                            }
                        },
                        enableHttpCorrelationHeaders = true
                    }
                }
            };

            // act
            string[] dependsOn = new string[] { "dependsOn" };
            DiagnosticTemplateResource diagnosticTemplateResource = diagnosticTemplateCreator.CreateAPIDiagnosticTemplateResource(creatorConfig, dependsOn);

            // assert
            Assert.Equal($"[concat(parameters('ApimServiceName'), '/{creatorConfig.api.name}/{creatorConfig.api.diagnostic.name}')]", diagnosticTemplateResource.name);
            Assert.Equal(dependsOn, diagnosticTemplateResource.dependsOn);
            Assert.Equal(creatorConfig.api.diagnostic.alwaysLog, diagnosticTemplateResource.properties.alwaysLog);
            Assert.Equal(creatorConfig.api.diagnostic.loggerId, diagnosticTemplateResource.properties.loggerId);
            Assert.Equal(creatorConfig.api.diagnostic.enableHttpCorrelationHeaders, diagnosticTemplateResource.properties.enableHttpCorrelationHeaders);
            Assert.Equal(creatorConfig.api.diagnostic.sampling.samplingType, diagnosticTemplateResource.properties.sampling.samplingType);
            Assert.Equal(creatorConfig.api.diagnostic.sampling.percentage, diagnosticTemplateResource.properties.sampling.percentage);
            Assert.Equal(creatorConfig.api.diagnostic.frontend.request.headers, diagnosticTemplateResource.properties.frontend.request.headers);
            Assert.Equal(creatorConfig.api.diagnostic.frontend.request.body.bytes, diagnosticTemplateResource.properties.frontend.request.body.bytes);
            Assert.Equal(creatorConfig.api.diagnostic.frontend.response.headers, diagnosticTemplateResource.properties.frontend.response.headers);
            Assert.Equal(creatorConfig.api.diagnostic.frontend.response.body.bytes, diagnosticTemplateResource.properties.frontend.response.body.bytes);
            Assert.Equal(creatorConfig.api.diagnostic.backend.request.headers, diagnosticTemplateResource.properties.backend.request.headers);
            Assert.Equal(creatorConfig.api.diagnostic.backend.request.body.bytes, diagnosticTemplateResource.properties.backend.request.body.bytes);
            Assert.Equal(creatorConfig.api.diagnostic.backend.response.headers, diagnosticTemplateResource.properties.backend.response.headers);
            Assert.Equal(creatorConfig.api.diagnostic.backend.response.body.bytes, diagnosticTemplateResource.properties.backend.response.body.bytes);
        }
Exemple #10
0
 public CreatorConfigurationValidator(CreatorConfig creatorConfig)
 {
     this.creatorConfig = creatorConfig;
 }