Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Last active October 2, 2016 16:26
Show Gist options
  • Select an option

  • Save angelovstanton/26f12047255741f59dfe5e44c446ed62 to your computer and use it in GitHub Desktop.

Select an option

Save angelovstanton/26f12047255741f59dfe5e44c446ed62 to your computer and use it in GitHub Desktop.
public abstract class BaseTestExecutionEngine<TExecutionEngineAttribute>
: ITestExecutionEngine
where TExecutionEngineAttribute : ExecutionEngineAttribute
{
protected IDriver driver;
protected readonly IUnityContainer container;
private bool isDisposed;
public BaseTestExecutionEngine(IUnityContainer container)
{
this.container = container;
}
public void Dispose()
{
if (!this.isDisposed && this.driver != null)
{
this.driver.Quit();
this.isDisposed = true;
}
}
public bool IsSelected(MemberInfo memberInfo)
{
bool isSelectedOnMethodLevel = this.GetExecutionEngineTypeByMethodInfo(memberInfo);
bool isSelectedOnClassLevel = this.GetExecutionEngineType(memberInfo.DeclaringType);
return isSelectedOnMethodLevel || isSelectedOnClassLevel;
}
public abstract void RegisterDependencies(Browsers executionBrowserType);
private bool GetExecutionEngineTypeByMethodInfo(MemberInfo memberInfo)
{
if (memberInfo == null)
{
throw new ArgumentNullException("The test method's info cannot be null.");
}
var executionEngineTypeMethodAttribute =
memberInfo.GetCustomAttribute<ExecutionEngineAttribute>();
if (executionEngineTypeMethodAttribute != null)
{
return true;
}
return false;
}
private bool GetExecutionEngineType(Type currentType)
{
if (currentType == null)
{
throw new ArgumentNullException("The test method's type cannot be null.");
}
var executionEngineClassAttribute =
currentType.GetCustomAttribute<ExecutionEngineAttribute>(true);
if (executionEngineClassAttribute != null)
{
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment