public void GetDefaultTest() { IAccount a = AccountGateway.GetDefault(); Process.Start(AccountGateway.AccountSettingPath); Assert.IsTrue(a.IsDefault); Console.WriteLine("Account(" + "Default" + ")"); PrintAccount(a); }
public void AddTest() { IAccount a = AccountGateway.Add("test1", "test1", "weibo.com", "*****@*****.**"); IAccount b = AccountGateway.Add("test2", "test2", "weibo.com", "*****@*****.**", true); Process.Start(AccountGateway.AccountSettingPath); IList <IAccount> all = AccountGateway.GetAll(); IAccount actual = null; foreach (IAccount account in all) { if (account.Id == a.Id || account.Id == b.Id) { actual = account; } else { actual = null; } if (actual != null) { if (account.Id == a.Id) { Assert.IsFalse(actual.IsDefault); } else { Assert.IsTrue(actual.IsDefault); } Console.WriteLine("Found Account({0}) {1} default account", actual.Id == a.Id ? "a" : "b", actual.IsDefault ? "is" : "is not"); PrintAccount(account); } } IAccount actual2 = AccountGateway.GetDefault(); Console.WriteLine("Default Account"); PrintAccount(actual2); Assert.AreEqual(b.Id, actual2.Id); }
public void RefreshTest() { IList <Cookie> cookies = new List <Cookie>(); #region Test email host domain //IList<IAccount> accounts = AccountGateway.GetAll(); //foreach (IAccount account in accounts) //{ // account.IsDefault = account.Host == "legacymail.taylorcorp.com"; //} //accounts= AccountGateway.Update(accounts); #endregion #region Test wrong email host domain IAccount a = AccountGateway.GetDefault(); a.Host = "test.test.com"; a = AccountGateway.Update(a); #endregion Process.Start(AccountGateway.AccountSettingPath); try { Authentication.AuthenticationManager.Refresh(); cookies = Authentication.AuthenticationManager.Current.CookieCache; } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(AuthenticationException)); Console.WriteLine(e.Message); } Assert.IsTrue(cookies.Count < 2); #region Test email host domain //foreach (IAccount account in accounts) //{ // account.IsDefault = account.Host == "webmail.taylorcorp.com"; //} //AccountGateway.Update(accounts); #endregion #region Test wrong email host domain a.Host = "webmail.taylorcorp.com"; a = AccountGateway.Update(a); #endregion Process.Start(AccountGateway.AccountSettingPath); Authentication.AuthenticationManager.Refresh(); cookies = Authentication.AuthenticationManager.Current.CookieCache; Console.WriteLine("Count:{0}", cookies.Count); Assert.IsTrue(cookies.Count >= 2); }
protected AuthenticationManager() { Log.Debug("Authentication Manager initialized."); _cookieCache = new List <Cookie>(); _currentAccount = AccountGateway.GetDefault(); if (_currentAccount == null) { throw new AuthenticationException("Message: No default account found in Account Setting."); } try { _cookieCache = Authenticate(_currentAccount); } catch (AuthenticationException e) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Authentication Exception, are you using a valid login?"); sb.AppendLine(" Msg: " + e.Message); sb.AppendLine(" Note: You must use a valid login / password for authentication."); string message = sb.ToString(); Log.Error(message); throw new AuthenticationException(message); } catch (SecurityException e) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Security Exception"); sb.AppendLine(" Msg: " + e.Message); sb.AppendLine(" Note: The application may not be trusted if run from a network share."); string message = sb.ToString(); Log.Error(message); throw new AuthenticationException(message); } catch (WebException e) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Web Exception"); sb.AppendLine(" Status: " + e.Status); sb.AppendLine(" Reponse: " + e.Response); sb.AppendLine(" Msg: " + e.Message); string message = sb.ToString(); Log.Error(message); throw new AuthenticationException(message); } catch (Exception ex) { if (ex is AuthenticationException) { throw; } Log.ErrorFormat("Message: Authentication failed to email host ({0}). {1}", _currentAccount.Host, ex.Message); throw new AuthenticationException(string.Format("Authentication failed to email host ({0})", _currentAccount.Host)); } if (_cookieCache.Count < 2) { string message = "Login failed. Is the login / password correct?"; Log.Error(message); throw new AuthenticationException(message); } }