public void ExecuteForClassInitializeThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome() { // Arrange. var tai = new TestAssemblyInfo(typeof(DummyTestClass).Assembly); var constructorInfo = typeof(DummyTestClass).GetConstructors().Single(); var classAttribute = new UTF.TestClassAttribute(); var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext"); var tci = new TestClassInfo( type: typeof(DummyTestClass), constructor: constructorInfo, testContextProperty: testContextProperty, classAttribute: classAttribute, parent: tai) { ClassInitializeMethod = typeof(TestMethodRunnerTests).GetMethod( "InitMethodThrowingException", BindingFlags.Static | BindingFlags.NonPublic) }; var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, tci, this.testMethodOptions, () => { throw new Exception("DummyException"); }); var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false); // Act. var results = testMethodRunner.Execute(); // Assert. Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome); StringAssert.Contains(results[0].ErrorMessage, "System.ArgumentException: Value does not fall within the expected range."); }
public TestMethodRunnerTests() { var constructorInfo = typeof(DummyTestClass).GetConstructors().Single(); this.methodInfo = typeof(DummyTestClass).GetMethods().Single(m => m.Name.Equals("DummyTestMethod")); var classAttribute = new UTF.TestClassAttribute(); this.testMethodAttribute = new UTF.TestMethodAttribute(); var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext"); var testAssemblyInfo = new TestAssemblyInfo(typeof(DummyTestClass).Assembly); this.testMethod = new TestMethod("dummyTestName", "dummyClassName", "dummyAssemblyName", false); this.testContextImplementation = new TestContextImplementation(this.testMethod, new StringWriter(), new Dictionary <string, object>()); this.testClassInfo = new TestClassInfo( type: typeof(DummyTestClass), constructor: constructorInfo, testContextProperty: testContextProperty, classAttribute: classAttribute, parent: testAssemblyInfo); this.globaltestMethodOptions = new TestMethodOptions() { Timeout = 3600 * 1000, Executor = this.testMethodAttribute, TestContext = this.testContextImplementation, ExpectedException = null }; var globalTestMethodInfo = new TestMethodInfo( this.methodInfo, this.testClassInfo, this.globaltestMethodOptions); var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, null); this.globalTestMethodRunner = new TestMethodRunner(globalTestMethodInfo, this.testMethod, this.testContextImplementation, false); this.testMethodOptions = new TestMethodOptions() { Timeout = 200, Executor = this.testMethodAttribute, TestContext = this.testContextImplementation, ExpectedException = null }; this.mockReflectHelper = new Mock <ReflectHelper>(); // Reset test hooks DummyTestClass.TestConstructorMethodBody = () => { }; DummyTestClass.TestContextSetterBody = value => { }; DummyTestClass.TestInitializeMethodBody = value => { }; DummyTestClass.TestMethodBody = instance => { }; DummyTestClass.TestCleanupMethodBody = value => { }; }
public TestClassInfoTests() { this.testClassType = typeof(DummyTestClass); this.testClassConstructor = this.testClassType.GetConstructors().First(); this.testContextProperty = this.testClassType.GetProperties().First(); this.testClassAttribute = (UTF.TestClassAttribute) this.testClassType.GetCustomAttributes().First(); this.testAssemblyInfo = new TestAssemblyInfo(); this.testClassInfo = new TestClassInfo( this.testClassType, this.testClassConstructor, this.testContextProperty, this.testClassAttribute, this.testAssemblyInfo); this.testContext = new Mock <UTFExtension.TestContext>().Object; }
public TestMethodRunnerTests() { var constructorInfo = typeof(DummyTestClass).GetConstructors().Single(); this.methodInfo = typeof(DummyTestClass).GetMethods().Single(m => m.Name.Equals("DummyTestMethod")); var classAttribute = new UTF.TestClassAttribute(); this.testMethodAttribute = new UTF.TestMethodAttribute(); var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext"); var testAssemblyInfo = new TestAssemblyInfo(); this.testMethod = new TestMethod("dummyTestName", "dummyClassName", "dummyAssemblyName", false); this.testContextImplementation = new TestContextImplementation(this.testMethod, null, new Dictionary <string, object>()); this.testClassInfo = new TestClassInfo( type: typeof(DummyTestClass), constructor: constructorInfo, testContextProperty: testContextProperty, classAttribute: classAttribute, parent: testAssemblyInfo); var globalTestMethodInfo = new TestMethodInfo( this.methodInfo, timeout: 3600 * 1000, executor: this.testMethodAttribute, expectedException: null, parent: this.testClassInfo, testContext: this.testContextImplementation); this.globalTestMethodRunner = new TestMethodRunner(globalTestMethodInfo, this.testMethod, this.testContextImplementation, false); // Reset test hooks DummyTestClass.TestConstructorMethodBody = () => { }; DummyTestClass.TestContextSetterBody = value => { }; DummyTestClass.TestInitializeMethodBody = value => { }; DummyTestClass.TestMethodBody = instance => { }; DummyTestClass.TestCleanupMethodBody = value => { }; }