void AssertBasicConfigurationSettings(CommunicatorConfiguration configuration)
 {
     Assert.AreEqual(new Uri("https://eu.sandbox.api-ingenico.com"), configuration.ApiEndpoint);
     Assert.AreEqual(AuthorizationType.V1HMAC, configuration.AuthorizationType);
     Assert.AreEqual(20000, configuration.ConnectTimeout?.TotalMilliseconds);
     Assert.AreEqual(10000, configuration.SocketTimeout?.TotalMilliseconds);
 }
Пример #2
0
        public void TestConstructFromPropertiesWithIPv6Host()
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            properties["connect.api.endpoint.host"] = "::1";
            properties["connect.api.authorizationType"] = AuthType;
            properties["connect.api.connectTimeout"] = "20000";
            properties["connect.api.socketTimeout"] = "10000";

            CommunicatorConfiguration configuration = new CommunicatorConfiguration(properties);

            Assert.AreEqual(new Uri("https://[::1]"), configuration.ApiEndpoint);
        }
        public void TestConstructFromPropertiesWithoutProxy()
        {
            CommunicatorConfiguration configuration = CreateBasicConfiguration();

            AssertBasicConfigurationSettings(configuration);
            Assert.AreEqual(CommunicatorConfiguration.DefaultMaxConnections, configuration.MaxConnections);
            Assert.Null(configuration.ApiKeyId);
            Assert.Null(configuration.SecretApiKey);

            // In original tests was null, but not anymore, because of app config configuration
            //Assert.Null(configuration.ProxyConfiguration);
        }
Пример #4
0
        public void TestConstructFromPropertiesWithHostAndPort()
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();
            properties["connect.api.endpoint.port"] = "8443";
            properties["connect.api.endpoint.host"] = "api-sandbox.globalcollect.com";
            properties["connect.api.authorizationType"] = AuthType;
            properties["connect.api.connectTimeout"] = "20000";
            properties["connect.api.socketTimeout"] = "10000";

            CommunicatorConfiguration configuration = new CommunicatorConfiguration(properties);

            Assert.AreEqual(new Uri("https://api-sandbox.globalcollect.com:8443"), configuration.ApiEndpoint);
        }
        public void TestCreateConfiguration()
        {
            CommunicatorConfiguration configuration = Factory.CreateConfiguration(
                DICT, API_KEY_ID, SECRET_API_KEY);

            Assert.AreEqual(new Uri("https://eu.sandbox.api-ingenico.com"), configuration.ApiEndpoint);
            Assert.AreEqual(AuthorizationType.V1HMAC, configuration.AuthorizationType);
            Assert.AreEqual(-1, configuration.ConnectTimeout?.TotalMilliseconds);
            Assert.AreEqual(-1, configuration.SocketTimeout?.TotalMilliseconds);
            Assert.AreEqual(100, configuration.MaxConnections);
            Assert.AreEqual(API_KEY_ID, configuration.ApiKeyId);
            Assert.AreEqual(SECRET_API_KEY, configuration.SecretApiKey);
        }
        public void TestConstructFromPropertiesWithHostAndScheme()
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties["connect.api.endpoint.scheme"]   = "http";
            properties["connect.api.endpoint.host"]     = "eu.sandbox.api-ingenico.com";
            properties["connect.api.authorizationType"] = AuthType;
            properties["connect.api.connectTimeout"]    = "20000";
            properties["connect.api.socketTimeout"]     = "10000";

            CommunicatorConfiguration configuration = new CommunicatorConfiguration(properties);

            Assert.AreEqual(new Uri("http://eu.sandbox.api-ingenico.com"), configuration.ApiEndpoint);
        }
Пример #7
0
        /// <summary>
        /// Creates a <see cref="CommunicatorConfiguration"/> based on the configuration
        /// values in <c>configurationDictionary</c>, <c>apiKeyId</c> and <c>secretApiKey</c>.
        /// </summary>
        /// <param name="configurationDictionary">Dictionary containing configuration.</param>
        /// <param name="apiKeyId">The API key identifier.</param>
        /// <param name="secretApiKey">The secret API key.</param>
        /// <returns>The communicator configuration that can still be changed.</returns>
        public static CommunicatorConfiguration CreateConfiguration(IDictionary <string, string> configurationDictionary, string apiKeyId, string secretApiKey)
        {
            var configuration = new CommunicatorConfiguration(configurationDictionary);

            if (apiKeyId != null)
            {
                configuration.ApiKeyId = apiKeyId;
            }
            if (secretApiKey != null)
            {
                configuration.SecretApiKey = secretApiKey;
            }
            return(configuration);
        }
Пример #8
0
        public void TestConstructFromPropertiesWithProxyWithoutAuthentication()
        {
            CommunicatorConfiguration configuration =
                createBasicConfiguration()
                                          .WithProxyUri(new Uri("http://proxy.example.org:3128"));

            AssertBasicConfigurationSettings(configuration);
            Assert.AreEqual(CommunicatorConfiguration.DefaultMaxConnections, configuration.MaxConnections);
            Assert.Null(configuration.ApiKeyId);
            Assert.Null(configuration.SecretApiKey);

            Assert.NotNull(configuration.ProxyConfiguration);
            ProxyConfiguration proxyFig = configuration.ProxyConfiguration;
            AssertBasicProxySettings(proxyFig);
            Assert.That(proxyFig.Username, Is.Empty);
            Assert.That(proxyFig.Password, Is.Empty);
        }
Пример #9
0
        public void TestConstructFromPropertiesWithProxyWithAuthentication()
        {
            CommunicatorConfiguration configuration = createBasicConfiguration()
                                                      .WithProxyUri(new Uri("http://proxy.example.org:3128"))
                                                      .WithProxyUserName("global-collect-username")
                                                      .WithProxyPassword("global-collect-password");

            AssertBasicConfigurationSettings(configuration);
            Assert.AreEqual(CommunicatorConfiguration.DefaultMaxConnections, configuration.MaxConnections);
            Assert.Null(configuration.ApiKeyId);
            Assert.Null(configuration.SecretApiKey);

            Assert.NotNull(configuration.ProxyConfiguration);
            ProxyConfiguration proxyFig = configuration.ProxyConfiguration;

            AssertBasicProxySettings(proxyFig);
            Assert.AreEqual("global-collect-username", proxyFig.Username);
            Assert.AreEqual("global-collect-password", proxyFig.Password);
        }
Пример #10
0
        /// <summary>
        /// Creates a <see cref="CommunicatorConfiguration"/> based on the configuration values in
        /// your <c>app.conf</c> or <c>web.conf</c> file, <c>apiKeyId</c> and <c>secretApiKey</c>.
        /// </summary>
        /// <param name="apiKeyId">The API key identifier.</param>
        /// <param name="secretApiKey">The secret API key.</param>
        /// <returns>The communicator configuration that can still be changed.</returns>
        public static CommunicatorConfiguration CreateConfiguration(string apiKeyId, string secretApiKey)
        {
            var configurationSection = System.Configuration.ConfigurationManager.GetSection("ConnectSDK") as CommunicatorConfigurationSection;

            if (configurationSection == null)
            {
                throw new InvalidOperationException("Unable to load configuration");
            }
            var configuration = new CommunicatorConfiguration(configurationSection);

            if (apiKeyId != null)
            {
                configuration.ApiKeyId = apiKeyId;
            }
            if (secretApiKey != null)
            {
                configuration.SecretApiKey = secretApiKey;
            }
            return(configuration);
        }
Пример #11
0
 /// <summary>
 /// Creates a <see cref="SessionBuilder"/> based on the passed configuration.
 /// </summary>
 public static SessionBuilder CreateSessionBuilder(CommunicatorConfiguration configuration)
 {
     return(new SessionBuilder()
            .WithApiEndpoint(configuration.ApiEndpoint)
            .WithConnection(new DefaultConnection(
                                configuration.SocketTimeout,
                                // connect timeout not supported
                                configuration.ProxyConfiguration,
                                configuration.MaxConnections
                                ))
            .WithMetaDataProvider(
                new MetaDataProviderBuilder(configuration.Integrator)
     {
         ShoppingCartExtension = configuration.ShoppingCartExtension
     }.Build()
                )
            .WithAuthenticator(new DefaultAuthenticator(
                                   configuration.AuthorizationType,
                                   configuration.ApiKeyId,
                                   configuration.SecretApiKey
                                   )));
 }
Пример #12
0
        /// <summary>
        /// Creates a <see cref="SessionBuilder"/> based on the configuration values in
        /// your <c>app.conf</c> or <c>web.conf</c> file, <c>apiKeyId</c> and <c>secretApiKey</c>.
        /// </summary>
        /// <param name="apiKeyId">The API key identifier.</param>
        /// <param name="secretApiKey">The secret API key.</param>
        public static SessionBuilder CreateSessionBuilder(string apiKeyId, string secretApiKey)
        {
            CommunicatorConfiguration configuration = CreateConfiguration(apiKeyId, secretApiKey);

            return(CreateSessionBuilder(configuration));
        }
Пример #13
0
 /// <summary>
 /// Creates a <see cref="Client"/> based on the passed configuration.
 /// </summary>
 public static Client CreateClient(CommunicatorConfiguration configuration)
 {
     return(CreateClient(CreateCommunicator(configuration)));
 }
Пример #14
0
        /// <summary>
        /// Creates a <see cref="Communicator"/> based on the passed configuration.
        /// </summary>
        public static Communicator CreateCommunicator(CommunicatorConfiguration configuration)
        {
            SessionBuilder sessionBuilder = CreateSessionBuilder(configuration);

            return(CreateCommunicator(sessionBuilder.Build()));
        }
Пример #15
0
        /// <summary>
        /// Creates a <see cref="Communicator"/> based on the configuration values
        /// <c>configurationDictionary</c>, <c>apiKeyId</c> and <c>secretApiKey</c>.
        /// </summary>
        /// <param name="configurationDictionary">Dictionary containing configuration.</param>
        /// <param name="apiKeyId">The API key identifier.</param>
        /// <param name="secretApiKey">The secret API key.</param>
        public static Communicator CreateCommunicator(IDictionary <string, string> configurationDictionary, string apiKeyId, string secretApiKey)
        {
            CommunicatorConfiguration configuration = CreateConfiguration(configurationDictionary, apiKeyId, secretApiKey);

            return(CreateCommunicator(configuration));
        }