private void CheckAccount(Account expectedAccount, bool exists)
        {
            AuthStorageHelper authStorageHelper = AuthStorageHelper.GetAuthStorageHelper();
            TypeInfo          auth     = authStorageHelper.GetType().GetTypeInfo();
            MethodInfo        retrieve = auth.GetDeclaredMethod("RetrievePersistedCredentials");
            var accounts = (Dictionary <string, Account>)retrieve.Invoke(authStorageHelper, null);

            if (!exists)
            {
                Assert.IsFalse(accounts.ContainsKey(expectedAccount.UserName),
                               "Account " + expectedAccount.UserName + " should not have been found");
            }
            else
            {
                Assert.IsTrue(accounts.ContainsKey(expectedAccount.UserName),
                              "Account " + expectedAccount.UserName + " should exist");
                Account account = accounts[expectedAccount.UserName];
                Assert.AreEqual(expectedAccount.LoginUrl, account.LoginUrl);
                Assert.AreEqual(expectedAccount.ClientId, account.ClientId);
                Assert.AreEqual(expectedAccount.CallbackUrl, account.CallbackUrl);
                Assert.AreEqual(expectedAccount.Scopes.Length, account.Scopes.Length);
                Assert.AreEqual(expectedAccount.InstanceUrl, account.InstanceUrl);
                Assert.AreEqual(expectedAccount.AccessToken, expectedAccount.AccessToken);
                Assert.AreEqual(expectedAccount.RefreshToken, expectedAccount.RefreshToken);
            }
        }
        public void TestPersistRetrieveDeleteEncryptionSettings()
        {
            AuthStorageHelper authStorageHelper = AuthStorageHelper.GetAuthStorageHelper();

            TypeInfo   auth    = authStorageHelper.GetType().GetTypeInfo();
            MethodInfo persist = auth.GetDeclaredMethod("PersistEncryptionSettings");
            MethodInfo delete  = auth.GetDeclaredMethod("DeleteEncryptionSettings");

            persist.Invoke(authStorageHelper, new object[] { Password, Salt });
            CheckEncryptionSettings(true);
            delete.Invoke(authStorageHelper, null);
            CheckEncryptionSettings(false);
        }
 public void TestPersistRetrieveDeleteCredentials()
 {
     Account account = new Account("loginUrl", "clientId", "callbackUrl", new string[] { "scopeA", "scopeB" }, "instanceUrl", "identityUrl", "accessToken", "refreshToken");
     account.UserId = "userId";
     account.UserName = "******";
     AuthStorageHelper authStorageHelper = new AuthStorageHelper();
     CheckAccount(account, false);
     TypeInfo auth = authStorageHelper.GetType().GetTypeInfo();
     MethodInfo persist = auth.GetDeclaredMethod("PersistCredentials");
     MethodInfo delete = auth.GetDeclaredMethods("DeletePersistedCredentials").First(method => method.GetParameters().Count() == 1);
     persist.Invoke(authStorageHelper, new object[] { account });
     CheckAccount(account, true);
     delete.Invoke(authStorageHelper, new object[] { account.UserId });
     CheckAccount(account, false);
 }
        public void TestPersistRetrieveDeleteCredentials()
        {
            Account account = new Account("loginUrl", "clientId", "callbackUrl", new string[] { "scopeA", "scopeB" }, "instanceUrl", "identityUrl", "accessToken", "refreshToken");

            account.UserId   = "userId";
            account.UserName = "******";
            AuthStorageHelper authStorageHelper = new AuthStorageHelper();

            CheckAccount(account, false);
            TypeInfo   auth    = authStorageHelper.GetType().GetTypeInfo();
            MethodInfo persist = auth.GetDeclaredMethod("PersistCredentials");
            MethodInfo delete  = auth.GetDeclaredMethods("DeletePersistedCredentials").First(method => method.GetParameters().Count() == 1);

            persist.Invoke(authStorageHelper, new object[] { account });
            CheckAccount(account, true);
            delete.Invoke(authStorageHelper, new object[] { account.UserId });
            CheckAccount(account, false);
        }
        private void CheckEncryptionSettings(bool exists)
        {
            AuthStorageHelper authStorageHelper = AuthStorageHelper.GetAuthStorageHelper();
            TypeInfo          auth        = authStorageHelper.GetType().GetTypeInfo();
            MethodInfo        tryRetrieve = auth.GetDeclaredMethod("TryRetrieveEncryptionSettings");
            var parameters = new object[] { null, null };
            var success    = (bool)tryRetrieve.Invoke(authStorageHelper, parameters);

            if (!exists)
            {
                Assert.IsFalse(success, "Encryption settings should not exist");
            }
            else
            {
                Assert.IsTrue(success, "Encryption settings should exist");
                Assert.AreEqual(Password, parameters[0]);
                Assert.AreEqual(Salt, parameters[1]);
            }
        }
 private void CheckAccount(Account expectedAccount, bool exists)
 {
     AuthStorageHelper authStorageHelper = new AuthStorageHelper();
     TypeInfo auth = authStorageHelper.GetType().GetTypeInfo();
     MethodInfo retrieve = auth.GetDeclaredMethod("RetrievePersistedCredentials");
     var accounts = (Dictionary<string, Account>) retrieve.Invoke(authStorageHelper, null);
     if (!exists)
     {
         Assert.IsFalse(accounts.ContainsKey(expectedAccount.UserId), "Account " + expectedAccount.UserId + " should not have been found");
     }
     else
     {
         Assert.IsTrue(accounts.ContainsKey(expectedAccount.UserId),  "Account " + expectedAccount.UserId + " should exist");
         Account account = accounts[expectedAccount.UserId];
         Assert.AreEqual(expectedAccount.LoginUrl, account.LoginUrl);
         Assert.AreEqual(expectedAccount.ClientId, account.ClientId);
         Assert.AreEqual(expectedAccount.CallbackUrl, account.CallbackUrl);
         Assert.AreEqual(expectedAccount.Scopes.Length, account.Scopes.Length);
         Assert.AreEqual(expectedAccount.InstanceUrl, account.InstanceUrl);
         Assert.AreEqual(expectedAccount.AccessToken, expectedAccount.AccessToken);
         Assert.AreEqual(expectedAccount.RefreshToken, expectedAccount.RefreshToken);
     }
 }