Merged dispose-webdriver into main

This commit is contained in:
AaronJamesY 2017-02-12 23:01:05 +00:00
commit 6345a4d1a6
3 changed files with 76 additions and 13 deletions

View file

@ -10,14 +10,13 @@ using BankingBot.Enums;
namespace BankingBot
{
public class BankingClient <T> : IClient
public class BankingClient <T> : IClient, IDisposable
where T : IWebDriver
{
#region Dependencies
readonly ILoginManager loginManager;
readonly IAccountManager accountManager;
protected readonly IBrowserBot BrowserBot;
readonly IBrowserBot browserBot;
#endregion
public ILoginCredentials LoginCredentials { get; private set; }
@ -30,10 +29,9 @@ namespace BankingBot
public BankingClient()
{
BrowserBot = new BrowserBot<T>();
loginManager = new LoginManager(BrowserBot);
accountManager = new AccountManager(BrowserBot);
browserBot = new BrowserBot<T>();
loginManager = new LoginManager(browserBot);
accountManager = new AccountManager(browserBot);
}
#region Actions - Login Manager
@ -67,5 +65,41 @@ namespace BankingBot
}
#endregion
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
browserBot.Dispose();
}
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
// TODO: set large fields to null.
disposedValue = true;
}
}
// TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
// ~BankingClient() {
// // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
// Dispose(false);
// }
// This code added to correctly implement the disposable pattern.
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
// TODO: uncomment the following line if the finalizer is overridden above.
// GC.SuppressFinalize(this);
}
#endregion
}
}

View file

@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BankingBot.Contracts;
using OpenQA.Selenium;
namespace BankingBot
{
public class BrowserBot<T> : IBrowserBot
public class BrowserBot<T> : IBrowserBot, IDisposable
where T : IWebDriver
{
public IWebDriver WebDriver { get; private set; }
@ -17,5 +13,37 @@ namespace BankingBot
{
WebDriver = (IWebDriver)Activator.CreateInstance(typeof(T));
}
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
WebDriver.Quit();
}
disposedValue = true;
}
}
// TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
// ~BrowserBot() {
// // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
// Dispose(false);
// }
// This code added to correctly implement the disposable pattern.
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
// TODO: uncomment the following line if the finalizer is overridden above.
// GC.SuppressFinalize(this);
}
#endregion
}
}

View file

@ -1,8 +1,9 @@
using OpenQA.Selenium;
using System;
namespace BankingBot.Contracts
{
public interface IBrowserBot
public interface IBrowserBot : IDisposable
{
IWebDriver WebDriver { get; }
}