public void TestCreateCommunicator()
        {
            Communicator communicator = Factory.CreateCommunicator(DICT, API_KEY_ID, SECRET_API_KEY);

            Assert.AreSame(DefaultMarshaller.Instance, communicator.Marshaller);

            Session session = communicator.Session;

            IConnection connection = session.Connection;

            Assert.True(connection is DefaultConnection);
            //DefaultConnectionTest.assertConnection((DefaultConnection) connection, -1, -1, 100, null);

            IAuthenticator authenticator = session.Authenticator;

            Assert.True(authenticator is DefaultAuthenticator);
            Assert.AreEqual(AuthorizationType.V1HMAC, GetInstanceField(typeof(DefaultAuthenticator), authenticator, "_authorizationType"));
            Assert.AreEqual(API_KEY_ID, GetInstanceField(typeof(DefaultAuthenticator), authenticator, "_apiKeyId"));
            Assert.AreEqual(SECRET_API_KEY, GetInstanceField(typeof(DefaultAuthenticator), authenticator, "_secretApiKey"));

            MetaDataProvider metaDataProvider = session.MetaDataProvider;

            Assert.AreEqual(typeof(MetaDataProvider), metaDataProvider.GetType());
            IEnumerable <RequestHeader> requestHeaders = metaDataProvider.ServerMetaDataHeaders;

            Assert.AreEqual(1, requestHeaders.Count());
            RequestHeader requestHeader = requestHeaders.ElementAt(0);

            Assert.AreEqual("X-GCS-ServerMetaInfo", requestHeader.Name);
        }
Esempio n. 2
0
 public Session(Uri apiEndpoint, IConnection connection, IAuthenticator authenticator,
                MetaDataProvider metaDataProvider)
 {
     if (apiEndpoint == null)
     {
         throw new ArgumentException("apiEndpoint is required");
     }
     if (apiEndpoint.LocalPath != null && apiEndpoint.LocalPath.Length > 0 && !apiEndpoint.LocalPath.Equals("/"))
     {
         throw new ArgumentException("apiEndpoint should not contain a path");
     }
     if (!apiEndpoint.UserInfo.Equals("") ||
         !apiEndpoint.Query.Equals("") ||
         !apiEndpoint.Fragment.Equals(""))
     {
         throw new ArgumentException("apiEndpoint should not contain user info, query or fragment");
     }
     if (connection == null)
     {
         throw new ArgumentException("connection is required");
     }
     if (authenticator == null)
     {
         throw new ArgumentException("authenticator is required");
     }
     if (metaDataProvider == null)
     {
         throw new ArgumentException("metaDataProvider is required");
     }
     _apiEndpoint      = apiEndpoint;
     _connection       = connection;
     _authenticator    = authenticator;
     _metaDataProvider = metaDataProvider;
 }
        public void TestGetServerMetaDataHeadersNoAdditionalHeaders()
        {
            MetaDataProvider metaDataProvider = new MetaDataProvider("Ingenico");

            IEnumerable <RequestHeader> requestHeaders = metaDataProvider.ServerMetaDataHeaders;

            Assert.AreEqual(1, requestHeaders.Count());

            RequestHeader requestHeader = requestHeaders.First();

            AssertServerMetaInfo(metaDataProvider, requestHeader);
        }
        void AssertServerMetaInfo(MetaDataProvider metaDataProvider, RequestHeader requestHeader)
        {
            Assert.AreEqual(requestHeader.Name, "X-GCS-ServerMetaInfo");
            Assert.NotNull(requestHeader.Value);

            byte[] data = Convert.FromBase64String(requestHeader.Value);
            string serverMetaInfoJson = Encoding.UTF8.GetString(data);

            MetaDataProvider.ServerMetaInfo serverMetaInfo = DefaultMarshaller.Instance.Unmarshal <MetaDataProvider.ServerMetaInfo>(serverMetaInfoJson);
            Assert.AreEqual(metaDataProvider.SdkIdentifier, serverMetaInfo.SdkIdentifier);
            Assert.AreEqual("Ingenico", serverMetaInfo.SdkCreator);
            Assert.AreEqual(metaDataProvider.PlatformIdentifier, serverMetaInfo.PlatformIdentifier);
        }
Esempio n. 5
0
 public Session(Uri apiEndpoint, IConnection connection, IAuthenticator authenticator,
                MetaDataProvider metaDataProvider)
 {
     if (apiEndpoint == null)
     {
         throw new ArgumentException("apiEndpoint is required");
     }
     if (apiEndpoint.HasPath())
     {
         throw new ArgumentException("apiEndpoint should not contain a path");
     }
     if (apiEndpoint.HasUserInfoOrQueryOrFragment())
     {
         throw new ArgumentException("apiEndpoint should not contain user info, query or fragment");
     }
     ApiEndpoint      = apiEndpoint;
     Connection       = connection ?? throw new ArgumentException("connection is required");
     Authenticator    = authenticator ?? throw new ArgumentException("authenticator is required");;
     MetaDataProvider = metaDataProvider ?? throw new ArgumentException("metaDataProvider is required");;
 }
        public static void CheckWithAdditionalRequestHeader(string additionalHeaderName, bool isAllowed)
        {
            RequestHeader additionalRequestHeader = new RequestHeader(additionalHeaderName, Guid.NewGuid().ToString());

            MetaDataProviderBuilder builder = new MetaDataProviderBuilder("Ingenico");

            if (isAllowed)
            {
                MetaDataProvider            metaDataProvider = builder.WithAdditionalRequestHeader(additionalRequestHeader).Build();
                IEnumerable <RequestHeader> requestHeaders   = metaDataProvider.ServerMetaDataHeaders;
                Assert.AreEqual(2, requestHeaders.Count());

                RequestHeader requestHeader = requestHeaders.First();
                Assert.AreEqual("X-GCS-ServerMetaInfo", requestHeader.Name);

                requestHeader = requestHeaders.Skip(1).First();
                Assert.AreEqual(requestHeader, additionalRequestHeader);
            }
            else
            {
                Assert.That((() => builder.WithAdditionalRequestHeader(additionalRequestHeader)), Throws.ArgumentException.With.Message.Contains(additionalHeaderName));
            }
        }
 /// <summary>
 /// Sets the <see cref="MetaDataProvider"/> to use.
 /// </summary>
 /// <param name="metaDataProvider">Meta data provider.</param>
 /// <returns>This.</returns>
 public SessionBuilder WithMetaDataProvider(MetaDataProvider metaDataProvider)
 {
     _metaDataProvider = metaDataProvider;
     return(this);
 }
 /// <summary>
 /// Adds an additional request header.
 /// The following names are prohibited in these additional request headers, because these will be set automatically
 /// as needed:
 /// <list>
 /// <item><description>X-GCS-ServerMetaInfo</description></item>
 /// <item><description>X-GCS-ClientMetaInfo</description></item>
 /// <item><description>X-GCS-Idempotence-Key</description></item>
 /// <item><description>Date</description></item>
 /// <item><description>Content-Type</description></item>
 /// <item><description>Authorization</description></item>
 /// </list>
 /// </summary>
 /// <returns>This.</returns>
 public MetaDataProviderBuilder WithAdditionalRequestHeader(RequestHeader additionalRequestHeader)
 {
     MetaDataProvider.ValidateAdditionalRequestHeader(additionalRequestHeader);
     _additionalRequestHeaders.Add(additionalRequestHeader);
     return(this);
 }