diff --git a/BankingBot/ActionManagers/LoginManagers/LloydsLoginManager.cs b/BankingBot/ActionManagers/LoginManagers/LloydsLoginManager.cs index 93b2267..f4acdff 100644 --- a/BankingBot/ActionManagers/LoginManagers/LloydsLoginManager.cs +++ b/BankingBot/ActionManagers/LoginManagers/LloydsLoginManager.cs @@ -4,6 +4,8 @@ using BankingBot.Attributes; using BankingBot.Contracts; using BankingBot.LoginCredentials; using OpenQA.Selenium; +using BankingBot.Responses; +using BankingBot.Enums; namespace BankingBot.ActionManagers.LoginManagers { @@ -24,19 +26,32 @@ namespace BankingBot.ActionManagers.LoginManagers _browserBot = browserBot; } - public void Login(ILoginCredentials credentials) + public Response Login(ILoginCredentials credentials) { + var response = new Response(); var lloydsCreds = (LloydsLoginCredentials)credentials; - LoginStep1(lloydsCreds); + try + { + LoginStep1(lloydsCreds); - if (!_browserBot.WebDriver.Url.Contains(Urls.MemorableInfo)) - throw new Exception("An error occured"); + if (!_browserBot.WebDriver.Url.Contains(Urls.MemorableInfo)) + throw new InvalidOperationException("Invalid login credentials"); - LoginStep2(lloydsCreds); + LoginStep2(lloydsCreds); - if (!_browserBot.WebDriver.Url.Contains(Urls.AccountOverview)) - throw new Exception("An error occured"); + if (!_browserBot.WebDriver.Url.Contains(Urls.AccountOverview)) + throw new InvalidOperationException("Invalid passphrase for account"); + + response.Status = ResponseStatus.Success; + } + catch (Exception ex) + { + response.Exception = ex; + response.Status = ResponseStatus.Error; + } + + return response; } private void LoginStep1(LloydsLoginCredentials credentials) diff --git a/BankingBot/ActionManagers/LoginManagers/LoginManager.cs b/BankingBot/ActionManagers/LoginManagers/LoginManager.cs index ffdab4d..836d3c5 100644 --- a/BankingBot/ActionManagers/LoginManagers/LoginManager.cs +++ b/BankingBot/ActionManagers/LoginManagers/LoginManager.cs @@ -2,6 +2,7 @@ using System.Linq; using BankingBot.Attributes; using BankingBot.Contracts; +using BankingBot.Responses; namespace BankingBot.ActionManagers.LoginManagers { @@ -11,39 +12,12 @@ namespace BankingBot.ActionManagers.LoginManagers : base(browserBot) { } - public void Login(ILoginCredentials credentials) + public Response Login(ILoginCredentials credentials) { - //var provLoginManagerType = GetProviderLoginManagerType(credentials); - //var provLoginManager = (IProviderLoginManager)Activator.CreateInstance(provLoginManagerType, BrowserBot); - //provLoginManager.Login(credentials); - var provLoginManagerType = GetActionTypeFromInterface(credentials, typeof(IProviderLoginManager)); var provLoginManager = (IProviderLoginManager)Activator.CreateInstance(provLoginManagerType, BrowserBot); - provLoginManager.Login(credentials); + + return provLoginManager.Login(credentials); } - - //private Type GetProviderLoginManagerType(ILoginCredentials credentials) - //{ - // // Get all "provider login manager" classes in the assembly - // // (any class that implements IProviderLoginManager) - // var providerLoginManagerTypes = AppDomain.CurrentDomain.GetAssemblies() - // .SelectMany(s => s.GetTypes()) - // .Where(p => - // typeof(IProviderLoginManager).IsAssignableFrom(p) && - // p != typeof(IProviderLoginManager)); - - // var credentialsProvider = credentials.GetProvider(); - // foreach (var type in providerLoginManagerTypes) - // { - // // Get associated provider for each "provider login manager" class - // var provider = ProviderIdentifier.GetProviderFromType(type); - // if (provider == credentialsProvider) - // { - // return type; - // } - // } - - // return null; - //} } } diff --git a/BankingBot/BankingBot.csproj b/BankingBot/BankingBot.csproj index e73adf6..8720ac7 100644 --- a/BankingBot/BankingBot.csproj +++ b/BankingBot/BankingBot.csproj @@ -57,7 +57,9 @@ + + @@ -65,6 +67,7 @@ + diff --git a/BankingBot/Client.cs b/BankingBot/Client.cs index b3b78e8..5809a4b 100644 --- a/BankingBot/Client.cs +++ b/BankingBot/Client.cs @@ -8,6 +8,7 @@ using BankingBot.ActionManagers.LoginManagers; using BankingBot.Models; using OpenQA.Selenium; using BankingBot.ActionManagers.AccountManagers; +using BankingBot.Responses; namespace BankingBot { @@ -38,11 +39,11 @@ namespace BankingBot #region Actions - Login Manager - public void Login(ILoginCredentials credentials) + public Response Login(ILoginCredentials credentials) { - _loginManager.Login(credentials); - LoginCredentials = credentials; + + return _loginManager.Login(credentials); } #endregion diff --git a/BankingBot/Contracts/IClient.cs b/BankingBot/Contracts/IClient.cs index 83a8d90..7e5e1c6 100644 --- a/BankingBot/Contracts/IClient.cs +++ b/BankingBot/Contracts/IClient.cs @@ -1,12 +1,13 @@ using System.Collections; using System.Collections.Generic; using BankingBot.Models; +using BankingBot.Responses; namespace BankingBot.Contracts { public interface IClient { - void Login(ILoginCredentials credentials); + Response Login(ILoginCredentials credentials); decimal GetBalance(); diff --git a/BankingBot/Contracts/ILoginManager.cs b/BankingBot/Contracts/ILoginManager.cs index 18cda3b..a4ecfd7 100644 --- a/BankingBot/Contracts/ILoginManager.cs +++ b/BankingBot/Contracts/ILoginManager.cs @@ -1,7 +1,9 @@ -namespace BankingBot.Contracts +using BankingBot.Responses; + +namespace BankingBot.Contracts { public interface ILoginManager { - void Login(ILoginCredentials credentials); + Response Login(ILoginCredentials credentials); } } \ No newline at end of file diff --git a/BankingBot/Contracts/IProviderLoginManager.cs b/BankingBot/Contracts/IProviderLoginManager.cs index 22479d7..45c4656 100644 --- a/BankingBot/Contracts/IProviderLoginManager.cs +++ b/BankingBot/Contracts/IProviderLoginManager.cs @@ -1,7 +1,9 @@ -namespace BankingBot.Contracts +using BankingBot.Responses; + +namespace BankingBot.Contracts { public interface IProviderLoginManager { - void Login(ILoginCredentials credentials); + Response Login(ILoginCredentials credentials); } } \ No newline at end of file diff --git a/BankingBot/Contracts/IResponse.cs b/BankingBot/Contracts/IResponse.cs index 333d199..2c67ebc 100644 --- a/BankingBot/Contracts/IResponse.cs +++ b/BankingBot/Contracts/IResponse.cs @@ -1,4 +1,5 @@ -using System; +using BankingBot.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,10 +9,8 @@ namespace BankingBot.Contracts { public interface IResponse { - Exception exception { get; } + Exception Exception { get; } - string Message { get; } - - bool IsError { get; } + ResponseStatus Status { get; } } } diff --git a/BankingBot/Enums/ResponseStatus.cs b/BankingBot/Enums/ResponseStatus.cs new file mode 100644 index 0000000..2620a5d --- /dev/null +++ b/BankingBot/Enums/ResponseStatus.cs @@ -0,0 +1,8 @@ +namespace BankingBot.Enums +{ + public enum ResponseStatus + { + Success, + Error + } +} diff --git a/BankingBot/Responses/Response.cs b/BankingBot/Responses/Response.cs index 4b94512..b1410c9 100644 --- a/BankingBot/Responses/Response.cs +++ b/BankingBot/Responses/Response.cs @@ -4,15 +4,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BankingBot.Enums; namespace BankingBot.Responses { public class Response : IResponse { - public Exception exception { get; set; } + public Exception Exception { get; set; } - public string Message { get; set; } - - public bool IsError { get; set; } + public ResponseStatus Status { get; set; } } }