private void InitialBaseEndpointConfig(EndpointConfig testEndpoint)
 {
     testEndpoint.Initialize();
     testEndpoint.AppID = TestEndpointGuid2;
     testEndpoint.ADFSRelyingPartyID   = TestEndpointGuid1;
     testEndpoint.ADFSRelyingPartyName = EnvironmentConfig.App1Name;
     testEndpoint.AppName     = EnvironmentConfig.App1Name;
     testEndpoint.BackendUrl  = EnvironmentConfig.App1Url;
     testEndpoint.FrontendUrl = EnvironmentConfig.App1Url;
     testEndpoint.InactiveTransactionsTimeoutSec = Convert.ToString(300);
     testEndpoint.TranslateUrlInRequestHeaders   = Convert.ToString(true).ToLower();
     testEndpoint.TranslateUrlInResponseHeaders  = Convert.ToString(true).ToLower();
     testEndpoint.UseOAuthAuthentication         = Convert.ToString(false).ToLower();
     testEndpoint.ExternalCertificateThumbprint  = WebAppCertificate.Thumbprint;
     testEndpoint.ApplicationType           = "PublishedWebApplication";
     testEndpoint.BackendAuthNMode          = "None";
     testEndpoint.BackendCertValidationMode = "None";
     testEndpoint.ClientCertBindingMode     = "None";
     testEndpoint.ExternalPreauthentication = "ADFS";
 }
        /// <summary>
        /// Initializes server data store.
        /// </summary>
        private void InitializeDataStore(bool includeEndpoint = false)
        {
            // construct global config
            var storeConfigString = string.Empty;

            if (EnvironmentConfig.IsWin2016)
            {
                GlobalConfig_2016     globalConfig   = new GlobalConfig_2016();
                EndpointConfig_2016[] endpointConfig = null;

                this.InitialBaseGlobalConfig(globalConfig);
                globalConfig.AccessTokenAcceptanceDurationSec = Convert.ToString(AccessTokenAcceptanceDurationSec);
                globalConfig.ActiveEndpointAuthenticationURL  = UrlHelper.CombineUrls(EnvironmentConfig.ADFSServerUrl, AdfsServicePathPairs.ActiveEndpointAuthenticationURL);
                globalConfig.SchemaVersion = SchemaVersion;
                globalConfig.StsSignOutURL = UrlHelper.CombineUrls(EnvironmentConfig.ADFSServerUrl, AdfsServicePathPairs.StsSignOutURL);

                if (includeEndpoint)
                {
                    EndpointConfig_2016 testEndpoint = new EndpointConfig_2016();
                    this.InitialBaseEndpointConfig(testEndpoint);
                    testEndpoint.PersistentAccessCookieExpirationTimeSec = Convert.ToString(PersistentAccessCookieExpirationTimeSec);
                    testEndpoint.DisableHttpOnlyCookieProtection         = Convert.ToString(false).ToLower();
                    testEndpoint.EnableHttpRedirect = Convert.ToString(false).ToLower();
                    testEndpoint.EnableSignOut      = Convert.ToString(false).ToLower();
                    endpointConfig = new[] { testEndpoint };
                }

                var storeConfig = new StoreConfig_2016
                {
                    GlobalConfig   = (GlobalConfig_2016)globalConfig,
                    EndpointConfig = endpointConfig
                };
                storeConfigString = storeConfig.ToString().EncodeToBase64();
            }
            else
            {
                GlobalConfig     globalConfig   = new GlobalConfig();
                EndpointConfig[] endpointConfig = null;

                this.InitialBaseGlobalConfig(globalConfig);

                if (includeEndpoint)
                {
                    EndpointConfig testEndpoint = new EndpointConfig();
                    this.InitialBaseEndpointConfig(testEndpoint);
                    endpointConfig = new[] { testEndpoint };
                }
                var storeConfig = new StoreConfig
                {
                    GlobalConfig   = globalConfig,
                    EndpointConfig = endpointConfig
                };
                storeConfigString = storeConfig.ToString().EncodeToBase64();
            }


            // if the proxy store already exists, increase its version by one
            // if the proxy store has not been initialized yet, set the store version
            // to a random number.
            //
            // We do this to somewhat make sure that the store gets a different version
            // each time a test case runs. The proxy only updates its state when it gets
            // a different version from its cache. We want the proxy always to sync its
            // state with server's store config.
            //
            // For more detail, refer to Windows source code:
            // winblue_gdr/ds/security/ADFSv2/Product/ApplicationProxy/Configuration/src/ProxyConfigManager.cpp
            // in Function UpdateProxyConfig, it says:
            // if (m_currentConfigVersion != newConfigVersion)
            //
            var storeEntryKey = EnvironmentConfig.IsWin2016 ? EnvironmentConfig.SUTConfigEntryKey_2016 : EnvironmentConfig.SUTConfigEntryKey_2012R2;
            var newVersion    = _proxyStore == null
                ? MinStoreVersion // new Random(DateTime.Now.Millisecond).Next(MinStoreVersion, MaxStoreVersion)
                : _proxyStore.First(_ => _.key.EqualsIgnoreCase(storeEntryKey)).version + 1;

            //  set the new proxy store
            _proxyStore = new List <StoreEntry> {
                new StoreEntry {
                    version = newVersion,
                    key     = storeEntryKey,
                    value   = storeConfigString
                }
            };
        }