public void HandleExceptionInBothSetUpAndTearDown()
        {
            Exception e1 = new Exception("Test message for exception thrown from setup");
            Exception e2 = new Exception("Test message for exception thrown from tear down");
            SetupAndTearDownExceptionFixture fixture = new SetupAndTearDownExceptionFixture();

            fixture.SetupException    = e1;
            fixture.TearDownException = e2;
            ITestResult suiteResult = TestBuilder.RunTestFixture(fixture);

            Assert.That(suiteResult.HasChildren, "Fixture test should have child result.");
            ITestResult result = suiteResult.Children.ToArray()[0];

            Assert.AreEqual(ResultState.Error, result.ResultState, "Test should be in error state");
            string expected = string.Format("{0} : {1}", e1.GetType().FullName, e1.Message) + Environment.NewLine
                              + string.Format("TearDown : {0} : {1}", e2.GetType().FullName, e2.Message);

            Assert.AreEqual(expected, result.Message);
            Assert.That(result.StackTrace, Does.Contain("--TearDown"));

            PlatformInconsistency.MonoMethodInfoInvokeLosesStackTrace.SkipOnAffectedPlatform(() =>
            {
                Assert.That(result.StackTrace, Does.Contain(fixture.GetType().FullName)); // Sanity check
            });
        }
        public void HandleExceptionInSetUp()
        {
            Exception e = new Exception("Test message for exception thrown from setup");
            SetupAndTearDownExceptionFixture fixture = new SetupAndTearDownExceptionFixture();

            fixture.SetupException = e;
            ITestResult suiteResult = TestBuilder.RunTestFixture(fixture);

            Assert.IsTrue(suiteResult.HasChildren, "Fixture test should have child result.");
            TestResult result = (TestResult)suiteResult.Children.ToArray()[0];

            Assert.AreEqual(ResultState.Error, result.ResultState, "Test should be in error state");
            string expected = string.Format("{0} : {1}", e.GetType().FullName, e.Message);

            Assert.AreEqual(expected, result.Message);
            Assert.That(result.StackTrace, Does.Contain(fixture.GetType().FullName)); // Sanity check
        }
Exemple #3
0
        public void HandleExceptionInTearDown()
        {
            Exception e = new Exception("Test message for exception thrown from tear down");
            SetupAndTearDownExceptionFixture fixture = new SetupAndTearDownExceptionFixture();

            fixture.tearDownException = e;
            ITestResult suiteResult = TestBuilder.RunTestFixture(fixture);

            Assert.That(suiteResult.HasChildren, "Fixture test should have child result.");
            ITestResult result = suiteResult.Children[0];

            Assert.AreEqual(result.ResultState, ResultState.Error, "Test should be in error state");
            string expected = string.Format("TearDown : {0} : {1}", e.GetType().FullName, e.Message);

            Assert.AreEqual(expected, result.Message);
            Assert.That(result.StackTrace, Does.StartWith("--TearDown"));
            Assert.That(result.StackTrace, Does.Contain(fixture.GetType().FullName)); // Sanity check
        }
Exemple #4
0
        public void HandleExceptionInBothSetUpAndTearDown()
        {
            Exception e1 = new Exception("Test message for exception thrown from setup");
            Exception e2 = new Exception("Test message for exception thrown from tear down");
            SetupAndTearDownExceptionFixture fixture = new SetupAndTearDownExceptionFixture();

            fixture.setupException    = e1;
            fixture.tearDownException = e2;
            ITestResult suiteResult = TestBuilder.RunTestFixture(fixture);

            Assert.That(suiteResult.HasChildren, "Fixture test should have child result.");
            ITestResult result = suiteResult.Children[0];

            Assert.AreEqual(result.ResultState, ResultState.Error, "Test should be in error state");
            string expected = string.Format("{0} : {1}", e1.GetType().FullName, e1.Message) + Env.NewLine
                              + string.Format("TearDown : {0} : {1}", e2.GetType().FullName, e2.Message);

            Assert.AreEqual(expected, result.Message);
            Assert.That(result.StackTrace, Contains.Substring("--TearDown"));
            Assert.That(result.StackTrace, Contains.Substring(fixture.GetType().FullName)); // Sanity check
        }