예제 #1
0
        private void SetTesteeEnvironmentVariables(RepositoryFactory factory)
        {
            var localFilePath = Environment.GetEnvironmentVariable(LOCAL_DEV_ENV);

            if (string.IsNullOrEmpty(localFilePath))
            {
                factory.ConfigureEnvironment(
                    Environment.GetEnvironmentVariable(CLIENT_ID_ENV),
                    Environment.GetEnvironmentVariable(CLIENT_SECRET_ENV),
                    Environment.GetEnvironmentVariable(TENANT_ID_ENV)
                    );
            }
            else
            {
                var clientId     = "";
                var clientSecret = "";
                var tenantId     = "";

                // Read the JSON content from the file
                using (var jReader = new JsonTextReader(new System.IO.StreamReader(localFilePath)))
                {
                    while (jReader.Read())
                    {
                        // A bit of a hack to get it running for now
                        // When the path is the property name, but the value not, then the current token is the actual value.
                        if (jReader.Path.Equals("clientSecret") && !jReader.Value.ToString().Equals("clientSecret"))
                        {
                            clientSecret = jReader.Value.ToString();
                        }
                        else if (jReader.Path.Equals("clientId") && !jReader.Value.ToString().Equals("clientId"))
                        {
                            clientId = jReader.Value.ToString();
                        }
                        else if (jReader.Path.Equals("tenantId") && !jReader.Value.ToString().Equals("tenantId"))
                        {
                            tenantId = jReader.Value.ToString();
                        }
                    }
                }

                // Update the environment
                factory.ConfigureEnvironment(clientId, clientSecret, tenantId);
            }
        }