public void RetrieveAccountConfigByIndex()
 {
     configMngr = ConfigManager.Instance;
     Account acc = configMngr.GetAccount(0);
     Assert.IsNotNull(acc);
     Assert.AreEqual(UnitTestConstants.APIUserName, acc.APIUsername);
 }
 public void RetrieveAccountConfigByUsername()
 {
     configMngr = ConfigManager.Instance;
     Account acc = configMngr.GetAccount(UnitTestConstants.APIUserName);
     Assert.IsNotNull(acc);
     Assert.AreEqual(UnitTestConstants.APIUserName, acc.APIUsername);
     Assert.AreEqual(UnitTestConstants.APIPassword, acc.APIPassword);
     Assert.AreEqual(UnitTestConstants.APISignature, acc.APISignature);
     Assert.AreEqual(UnitTestConstants.ApplicationID, acc.ApplicationId);
 }
示例#3
0
        private string GetDefaultAccountName()
        {
            ConfigManager configMgr    = ConfigManager.Instance;
            Account       firstAccount = configMgr.GetAccount(0);

            if (firstAccount == null)
            {
                throw new MissingCredentialException("No accounts configured for API call");
            }
            return(firstAccount.APIUsername);
        }
示例#4
0
        public ICredential GetCredentials(string apiUserName)
        {
            if (apiUserName == null)
            {
                apiUserName = GetDefaultAccountName();
            }

            if (this.cachedCredentials.ContainsKey(apiUserName))
            {
                log.Debug("Returning cached credentials for " + apiUserName);
                return(this.cachedCredentials[apiUserName]);
            }
            else
            {
                ICredential pro = null;

                ConfigManager configMgr = ConfigManager.Instance;
                Account       acc       = configMgr.GetAccount(apiUserName);
                if (acc == null)
                {
                    throw new MissingCredentialException("Missing credentials for " + apiUserName);
                }
                if (!string.IsNullOrEmpty(acc.APICertificate))
                {
                    CertificateCredential cred = new CertificateCredential();
                    cred.APIUsername        = acc.APIUsername;
                    cred.APIPassword        = acc.APIPassword;
                    cred.CertificateFile    = acc.APICertificate;
                    cred.PrivateKeyPassword = acc.PrivateKeyPassword;
                    cred.ApplicationID      = acc.ApplicationId;

                    cred.CertificateSubject = acc.CertificateSubject;

                    pro = cred;
                }
                else
                {
                    SignatureCredential cred = new SignatureCredential();
                    cred.APIUsername   = acc.APIUsername;
                    cred.APIPassword   = acc.APIPassword;
                    cred.APISignature  = acc.APISignature;
                    cred.ApplicationID = acc.ApplicationId;

                    cred.SignatureSubject = acc.SignatureSubject;

                    pro = cred;
                }
                this.cachedCredentials.Add(apiUserName, pro);
                return(pro);
            }
        }
 public void RetrieveNonExistentAccount()
 {
     configMngr = ConfigManager.Instance;
     Account acc = configMngr.GetAccount("i-do-not-exist_api1.paypal.com");
     Assert.IsNull(acc, "Invalid account name returns null account config");
 }