Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created October 2, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovstanton/576767424a93ce7a33d13d7d30719ad8 to your computer and use it in GitHub Desktop.
Save angelovstanton/576767424a93ce7a33d13d7d30719ad8 to your computer and use it in GitHub Desktop.
[TestClass]
public class BaseTest
{
private readonly TestExecutionProvider currentTestExecutionProvider;
private IDriver driver;
private readonly IUnityContainer container;
private TestContext testContextInstance;
public BaseTest()
{
this.container = UnityContainerFactory.GetContainer();
this.container.RegisterInstance<IUnityContainer>(this.container);
this.currentTestExecutionProvider = new TestExecutionProvider();
this.InitializeTestExecutionBehaviorObservers(
this.currentTestExecutionProvider, this.container);
}
public IDriver Driver
{
get
{
return driver;
}
}
public IUnityContainer Container
{
get
{
return container;
}
}
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
public string TestName
{
get
{
return this.TestContext.TestName;
}
}
[TestInitialize]
public void CoreTestInit()
{
var memberInfo = GetCurrentExecutionMethodInfo();
this.currentTestExecutionProvider.PreTestInit(
(TestOutcome)this.TestContext.CurrentTestOutcome,
this.TestContext.TestName,
memberInfo);
this.driver = this.container.Resolve<IDriver>();
this.TestInit();
this.currentTestExecutionProvider.PostTestInit(
(TestOutcome)this.TestContext.CurrentTestOutcome,
this.TestContext.TestName,
memberInfo);
}
[TestCleanup]
public void CoreTestCleanup()
{
var memberInfo = GetCurrentExecutionMethodInfo();
this.currentTestExecutionProvider.PreTestCleanup(
(TestOutcome)this.TestContext.CurrentTestOutcome,
this.TestContext.TestName,
memberInfo);
this.TestCleanup();
this.currentTestExecutionProvider.PostTestCleanup(
(TestOutcome)this.TestContext.CurrentTestOutcome,
this.TestContext.TestName,
memberInfo);
}
public virtual void TestInit()
{
}
public virtual void TestCleanup()
{
}
public virtual void InitializeTestExecutionBehaviorObservers(
TestExecutionProvider testExecutionProvider,
IUnityContainer container)
{
var executionEngine = new ExecutionEngineBehaviorObserver(container);
var videoRecording =
new VideoBehaviorObserver(new MsExpressionEncoderVideoRecorder());
executionEngine.Subscribe(testExecutionProvider);
videoRecording.Subscribe(testExecutionProvider);
}
private MethodInfo GetCurrentExecutionMethodInfo()
{
var memberInfo = this.GetType().GetMethod(this.TestContext.TestName);
return memberInfo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment