public StandaloneTestFixture()
     : this(Clients.Builder()
            .SetHttpClient(HttpClients.Create().SystemNetHttpClient())
            .SetSerializer(Serializers.Create().JsonNetSerializer())
            .Build())
 {
 }
Exemplo n.º 2
0
 private IClient CreateClient()
 {
     return(Clients.Builder()
            .SetApiKeyId(GetApiKey().Id)
            .SetApiKeySecret(GetApiKey().Secret)
            .SetHttpClient(HttpClients.Create().SystemNetHttpClient())
            .SetSerializer(Serializers.Create().JsonNetSerializer())
            .Build());
 }
Exemplo n.º 3
0
        public DefaultClientBuilder_tests()
        {
            this.builder = new DefaultClientBuilder(new FakeUserAgentBuilder());

            // Providing these means the tests won't try to do a dynamic assembly lookup
            // which tends to screw up parallel-running tests
            this.builder
            .SetHttpClient(HttpClients.Create().RestSharpClient())
            .SetSerializer(Serializers.Create().JsonNetSerializer());
        }
Exemplo n.º 4
0
        public static void Initialize()
        {
            // Build the IClient object and make it available on StormpathConfig.Client.
            var clientBuilder = Clients.Builder()
                                .SetApiKeyId("ME2ZQOJMA57VSDD8XPW1Q7B1X")
                                .SetApiKeySecret("+ikOs9ltXgwKTnWXb1e28J7a/5A/VdbqU0qS9NCzXa8")
                                .SetHttpClient(HttpClients.Create().RestSharpClient())
                                .SetSerializer(Serializers.Create().JsonNetSerializer()
                                               );

            Client      = clientBuilder.Build();
            Application = Client.GetApplication(ApplicationHref); // Prime the cache
        }
        public static void Initialize()
        {
            // Build the IClient object and make it available on StormpathConfig.Client.
            // (In a complex application, it would be better to use dependency injection to do this,
            // instead of a singleton/static object)
            var clientBuilder = Clients.Builder()
                                // Path to your API Key file path. You can also hardcode the API Key and Secret
                                // with .SetApiKeyId/SetApiKeySecret, but this should only be used for testing.
                                .SetApiKeyFilePath("~\\.stormpath\\useful-catapult.apiKey.properties")
                                .SetHttpClient(HttpClients.Create().RestSharpClient())
                                .SetSerializer(Serializers.Create().JsonNetSerializer());

            Client = clientBuilder.Build();
            Client.GetApplication(ApplicationHref); // Prime the cache
        }
Exemplo n.º 6
0
        private static IScopedClientFactory InitializeClient(object initialConfiguration, string configurationFileRoot, ICacheProviderBuilder cacheProviderBuilder, ILogger logger)
        {
            // Construct base client
            var clientBuilder = Clients.Builder()
#if NET45
                                .SetHttpClient(HttpClients.Create().RestSharpClient())
#else
                                .SetHttpClient(HttpClients.Create().SystemNetHttpClient())
#endif
                                .SetSerializer(Serializers.Create().JsonNetSerializer())
                                .SetConfiguration(initialConfiguration)
                                .SetConfigurationFileRoot(configurationFileRoot)
                                .SetLogger(logger);

            if (cacheProviderBuilder != null)
            {
                clientBuilder.SetCacheProviderBuilder(cacheProviderBuilder);
            }

            var baseClient = clientBuilder.Build();

            // Attempt to connect and prime the cache with ITenant
            try
            {
                var tenant = baseClient.GetCurrentTenant();
                if (string.IsNullOrEmpty(tenant?.Href))
                {
                    throw new InitializationException("Could not connect to Stormpath. No tenant could be found.");
                }

                logger.Info($"Using tenant {tenant.Key}", nameof(InitializeClient));
            }
            catch (Exception ex)
            {
                throw new InitializationException(
                          "Unable to initialize the Stormpath client. See the inner exception for details.", ex);
            }

            // Scope it!
            return(new ScopedClientFactory(baseClient));
        }
Exemplo n.º 7
0
        IClient IClientBuilder.Build()
        {
            if (this.apiKey == null)
            {
                if (this.clientApiKeyBuilder != null)
                {
                    this.apiKey = this.clientApiKeyBuilder.Build();
                }
                else
                {
                    throw new ApplicationException("No valid API Key and Secret could be found.");
                }
            }

            var logger = this.logger ?? new NullLogger();

            IJsonSerializer serializer = null;

            if (this.overrideSerializer != null)
            {
                serializer = this.overrideSerializer;
            }
            else
            {
                if (this.serializerBuilder == null)
                {
                    this.logger.Info("No serializer plugin specified, using default.");
                    this.serializerBuilder = Serializers.Create().AutoDetect();
                }

                serializer = this.serializerBuilder.Build();
            }

            IHttpClient httpClient = null;

            if (this.overrideHttpClient != null)
            {
                httpClient = this.overrideHttpClient;
            }
            else
            {
                if (this.httpClientBuilder == null)
                {
                    this.logger.Info("No HTTP client plugin specified, using default.");
                    this.httpClientBuilder = HttpClients.Create().AutoDetect();
                }

                this.httpClientBuilder
                .SetBaseUrl(this.baseUrl)
                .SetConnectionTimeout(this.connectionTimeout)
                .SetProxy(this.proxy)
                .SetLogger(this.logger);

                httpClient = this.httpClientBuilder.Build();
            }

            if (this.cacheProvider == null)
            {
                this.logger.Info("No CacheProvider configured. Defaulting to in-memory CacheProvider with default TTL and TTI of one hour.");

                this.cacheProvider = Caches
                                     .NewInMemoryCacheProvider()
                                     .WithDefaultTimeToIdle(TimeSpan.FromHours(1))
                                     .WithDefaultTimeToLive(TimeSpan.FromHours(1))
                                     .Build();
            }
            else
            {
                var injectableWithSerializer = this.cacheProvider as ISerializerConsumer <ICacheProvider>;
                if (injectableWithSerializer != null)
                {
                    injectableWithSerializer.SetSerializer(serializer);
                }

                var injectableWithLogger = this.cacheProvider as ILoggerConsumer <ICacheProvider>;
                if (injectableWithLogger != null)
                {
                    injectableWithLogger.SetLogger(this.logger);
                }
            }

            return(new DefaultClient(
                       this.apiKey,
                       this.baseUrl,
                       this.authenticationScheme,
                       this.connectionTimeout,
                       this.proxy,
                       httpClient,
                       serializer,
                       this.cacheProvider,
                       this.userAgentBuilder,
                       logger,
                       DefaultIdentityMapSlidingExpiration));
        }