Created
October 2, 2016 16:16
-
-
Save angelovstanton/576767424a93ce7a33d13d7d30719ad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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