Ejemplo n.º 1
0
        internal void SetHeaders(string authorizationType, string headerParameters)
        {
            string rawHeaderParameters = headerParameters.Replace(" And ", ",");
            var    arrayHeaders        = rawHeaderParameters.Split(',');

            if (authorizationType.Equals("jwt", StringComparison.InvariantCultureIgnoreCase))
            {
                string authority = TestContext.Properties["Parameter:authority"].ToString();
                string brand     = TestContext.Properties["Parameter:brand"].ToString();
                string uid       = TestContext.Properties["Parameter:customeruid"].ToString();
                RequestParameters.SetHeaders(_authHeader, JsonWebToken.GetJsonWebToken(authority, brand, uid));
            }
            else if (authorizationType.Equals("basic", StringComparison.InvariantCultureIgnoreCase))
            {
                string clientId          = TestContext.Properties["Parameter:clientid"].ToString();
                string clientSecret      = TestContext.Properties["Parameter:clientsecret"].ToString();
                string encodedAuthString = BasicAuthentication.GetBasicAuthString(clientId, clientSecret);
                RequestParameters.SetHeaders(_authHeader, "Basic " + encodedAuthString);
            }

            foreach (var authorizationParameter in arrayHeaders)
            {
                try
                {
                    var parameterValue = TestContext.Properties["Parameter:" + authorizationParameter].ToString();
                    if (parameterValue != null)
                    {
                        RequestParameters.SetHeaders(authorizationParameter, parameterValue);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            RequestParameters.SetHeaders("x-transaction-id", Helper.GenerateTransactionId());
        }