/// <summary>
        /// Merges the specified other.
        /// </summary>
        /// <param name="source"> </param>
        /// <param name="target"> </param>
        public void Merge(TestResult source, TestResult target)
        {
            var mergedType = GetType(target);
            var otherType = GetType(source);

            if (mergedType == TestType.Project && otherType == TestType.Project)
            {
                if (string.IsNullOrEmpty(target.FullName) && !string.IsNullOrEmpty(source.FullName))
                {
                    target.Test.TestName.FullName = source.FullName;
                    target.Test.TestName.Name = source.Name;
                }
            }

            if (mergedType != otherType)
                throw new NotSupportedException("Only merging of results with same test type are supported");

            if (!target.IsSuccess && source.IsSuccess)
            {
                target.Success(source.Message);
                target.SetAgentName(source.GetAgentName());
            }

            MergeChildren(source, target);
        }
Esempio n. 2
0
        TestResult CreateTestResultFromExpectation(IExpectation expectation)
        {
            var result = new TestResult(new TestName { Name = expectation.Message });

            if (expectation.IsFail)
                result.Failure(expectation.ToString(), "");
            else if (expectation.IsPass)
                result.Success();
            else if (expectation.IsPending)
                result.Ignore(expectation.ToString(), "");

            return result;
        }
Esempio n. 3
0
        public override void RunTestMethod(TestResult testResult)
        {
            using (var runner = new Runner(Spec))
            {
                var example = runner.Run(() => RunBaseTestMethod(testResult), new TestResultExampleReporter(testResult));

                if (example.IsFail)
                    testResult.Failure(GetTestResultMessageForResultState(testResult, ResultState.Failure, "Failing"), "");

                if (example.IsPass)
                    testResult.Success();

                if (example.IsPending)
                    testResult.Ignore(GetTestResultMessageForResultState(testResult, ResultState.Ignored, "Pending"));
            }
        }
Esempio n. 4
0
 private static void DoTest(Action test, TestResult testResult)
 {
     try
     {
         test();
         testResult.Success();
     }
     catch(ThreadAbortException e)
     {
         Thread.ResetAbort();
         HandleException(e, testResult);
     }
     catch (Exception e)
     {
         HandleException(e, testResult);
     }
 }
        public TestResult CreateTestResult(TestType type, string fullName,
                                           ResultState state = ResultState.Success, 
                                           Func<IEnumerable<TestResult>> children = null, 
                                           string stackTrace = null, 
                                           string description = null,
                                           IList categories = null,
                                           string agentName = null)
        {
            description = description ?? RandomValuesGenerator.GetRandomValue<string>();
            agentName = agentName ?? RandomValuesGenerator.GetRandomValue<string>();
            var splitted = (fullName ?? string.Empty).Split(new[]{'.'}, StringSplitOptions.RemoveEmptyEntries);

            var childResults = children != null ? children() : new TestResult[0];
            var testResult = new TestResult(new TestInfoWrapper
                                                {
                                                    TestName = new TestName
                                                                   {
                                                                       FullName = fullName,
                                                                       Name = splitted.Length > 0 ? splitted[splitted.Length - 1] : string.Empty
                                                                   },
                                                    Categories = categories,
                                                    IsSuite = type != TestType.TestMethod,
                                                    TestCount = type == TestType.TestMethod ? 1 : RandomValuesGenerator.GetRandomValue<int>(),
                                                    TestType = type.ToString()
                                                })
                                 {
                                     AssertCount = 1,
                                     Time = RandomValuesGenerator.GetRandomValue<double>()
                                 };
            if (state != ResultState.Success)
                testResult.SetResult(state,
                                     description,
                                     stackTrace);
            else
                testResult.Success(description);

            testResult.SetAgentName(agentName);

            foreach (var childResult in childResults)
            {
                testResult.AddResult(childResult);
            }

            return testResult;
        }
Esempio n. 6
0
        public static TestResult ApplyToNunitResult(TestResultShim shim, TestResult result)
        {
            switch (shim.Status)
            {
                case TestResultShim.Result.Successs:
                    result.Success();
                    break;
                case TestResultShim.Result.Error:
                    result.SetResult(ResultState.Error, shim.FailureReason, shim.FailureStackTrace, GetNUnitFailureSite(shim.FailureSite));
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            result.Time = shim.ExecutionTime.Seconds;

            return result;
        }
Esempio n. 7
0
        private TestResult NUnitTestResult(IResultSummary concordionResult)
        {
            var testResult = new TestResult(this);

            if (concordionResult.HasExceptions)
            {
                testResult.Error(new NUnitException("Exception in Concordion test: please see Concordion test reports"));
            }
            else if (concordionResult.HasFailures)
            {
                testResult.Failure("Concordion Test Failures: " + concordionResult.FailureCount,
                                   "for stack trace, please see Concordion test reports");
            } else
            {
                testResult.Success();
            }

            return testResult;
        }
Esempio n. 8
0
        public override TestResult Run(EventListener listener, ITestFilter filter)
        {
            // TODO: Implement logic required for filtering.

            listener.TestStarted(this.TestName);
            long startTime = DateTime.Now.Ticks;

            var result = new TestResult(this);

            try
            {
                _engine.ExecuteScriptFile(_scriptPath);
                result.Success();
            }
            catch (AssertionException assertEx)
            {
                result.SetResult(ResultState.Failure, assertEx.Message, assertEx.StackTrace, FailureSite.Test);
            }
            catch (InconclusiveException inconclusiveEx)
            {
                result.SetResult(ResultState.Inconclusive, inconclusiveEx.Message, inconclusiveEx.StackTrace);
            }
            catch (Exception ex)
            {
                result.Error(ex);
            }
            finally
            {
                long stopTime = DateTime.Now.Ticks;
                double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
                result.Time = time;

                listener.TestFinished(result);
            }

            return result;
        }
Esempio n. 9
0
		private void RunTestMethod(TestResult testResult)
		{
		    object fixture = this.method.IsStatic ? null : this.Fixture;

			object result = Reflect.InvokeMethod( this.method, fixture, this.arguments );

            if (this.hasExpectedResult)
                NUnitFramework.Assert.AreEqual(expectedResult, result);

            testResult.Success();
        }
Esempio n. 10
0
        private TestResult NUnitTestResult(ResultSummary concordionResult, string resultPath)
        {
            var testResult = new TestResult(this);

            if (concordionResult.hasExceptions())
            {
                testResult.Error(new NUnitException("Exception in Concordion test: please see Concordion test reports"));
            }
            else if (concordionResult.getFailureCount() > 0)
            {
                testResult.Failure("Concordion Test Failures: " + concordionResult.getFailureCount(),
                                   "for stack trace, please see Concordion test reports");
            } else
            {
                testResult.Success(resultPath);
            }

            return testResult;
        }
Esempio n. 11
0
		private void RunTestCase( TestResult testResult )
		{
            try
            {
                object result = RunTestMethod(testResult);

                if (this.hasExpectedResult)
                    NUnitFramework.Assert.AreEqual(expectedResult, result);

                testResult.Success();

                if (testResult.IsSuccess && exceptionProcessor != null)
                    exceptionProcessor.ProcessNoException(testResult);
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException)
                    Thread.ResetAbort();

                if (exceptionProcessor == null)
                    RecordException(ex, testResult, FailureSite.Test);
                else
                    exceptionProcessor.ProcessException(ex, testResult);
            }
		}
Esempio n. 12
0
		public override TestResult RunTest ()
		{
			var result = new TestResult (TestName);
			var module = GetModule ();
			if (module == null)
				return result;

			Reflect.InvokeMethod (Method, Fixture, new object [] { module });

			result.Success ();
			return result;
		}
		public void SetResult_Success()
		{
			TestSuiteTreeNode node = new TestSuiteTreeNode( testCaseInfo );
			TestResult result = new TestResult( testCaseInfo );

			result.Success();
			node.Result = result;
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node.SelectedImageIndex );
			Assert.AreEqual( "Success", node.StatusText );
		}
Esempio n. 14
0
        private void doTestCase(TestResult testResult)
        {
            object fixture = this.Method.IsStatic ? null : this.Fixture;

            // Ugh... RunTestMethod is publicly overridable, but depends on a whole bunch of internal/private detail, so it's not really very overridable...
            var arguments = Helper.ReadPrivateField<object[]>(this, "arguments");
            var hasExpectedResult = Helper.ReadPrivateField<bool>(this, "hasExpectedResult");
            var expectedResult = Helper.ReadPrivateField<object>(this, "expectedResult");

            object result = Helper.InvokeMethodDirect(this.Method, fixture, arguments);

            if (hasExpectedResult)
                NUnitFramework.Assert.AreEqual(expectedResult, result);

            testResult.Success();
        }
Esempio n. 15
0
 private void TestNonExceptionCondition(TestResult result)
 {
     if (! TestShouldThrowException()) result.Success();
     else result.Failure("The behaviour did not throw an exception", "");
 }
		public void ClearNestedResults()
		{
			TestResult testCaseResult = new TestResult( testCaseInfo );
			testCaseResult.Success();
			TestResult testSuiteResult = new TestResult( fixtureInfo );
			testSuiteResult.AddResult( testCaseResult );
            testSuiteResult.Success();

			TestSuiteTreeNode node1 = new TestSuiteTreeNode( testSuiteResult );
			TestSuiteTreeNode node2 = new TestSuiteTreeNode( testCaseResult );
			node1.Nodes.Add( node2 );

			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node1.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node1.SelectedImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node2.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node2.SelectedImageIndex );

			node1.ClearResults();

			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node1.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node1.SelectedImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node2.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node2.SelectedImageIndex );
		}
Esempio n. 17
0
 private void TestExceptionCondition(TestResult result, Exception ex)
 {
     if (! TestShouldThrowException()) {
         result.Failure("Test or setup failed: "+ex.Message, ex.StackTrace);
     } else {
         if (! ThrownTypeMatchesExpectation(ex)) {
             result.Failure("Expected exception type of "
                            + testClosure.ExpectedExceptionType().Name
                            + " but got " + ex.GetType().Name, "\r\nat\r\n"+ex.StackTrace);
         } else {
             if (! TestExpectsAMessage()) result.Success();
             else {
                 if (ThrownMessageMatchesExpectation(ex)) result.Success();
                 else result.Failure("Expected exception message \r\n\""
                                     + testClosure.ExpectedExceptionMessage()
                                     + "\" but got \r\n\"" + ex.Message, "\"");
             }
         }
     }
 }
Esempio n. 18
0
		public void WhenResultIsCleared_NestedResultsAreAlsoCleared()
		{
			TestResult testCaseResult = new TestResult( testCase );
			testCaseResult.Success();
			TestResult testSuiteResult = new TestResult( testFixture );
			testSuiteResult.AddResult( testCaseResult );
            testSuiteResult.Success();

			TestSuiteTreeNode node1 = new TestSuiteTreeNode( testSuiteResult );
			TestSuiteTreeNode node2 = new TestSuiteTreeNode( testCaseResult );
			node1.Nodes.Add( node2 );

			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node1.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node1.SelectedImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node2.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.SuccessIndex, node2.SelectedImageIndex );

			node1.ClearResults();

			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node1.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node1.SelectedImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node2.ImageIndex );
			Assert.AreEqual( TestSuiteTreeNode.InitIndex, node2.SelectedImageIndex );
		}
Esempio n. 19
0
        private TestResult NUnitTestResult(IResultSummary concordionResult, string resultPath)
        {
            var testResult = new TestResult(this);

            if (concordionResult.HasExceptions)
            {
                var errorDetails = concordionResult.ErrorDetails.First();
                testResult.Error(errorDetails.Exception);
                testResult.SetResult(testResult.ResultState,
                                     resultPath + Environment.NewLine + testResult.Message,
                                     testResult.StackTrace);
            }
            else if (concordionResult.HasFailures)
            {
                var failureDetails = concordionResult.FailureDetails.First();
                testResult.Failure(resultPath + Environment.NewLine + failureDetails.Message, failureDetails.StackTrace);
            } else
            {
                testResult.Success(resultPath);
            }

            return testResult;
        }
        public void ProcessException(Exception exception, TestResult testResult)
        {
            if (exception is NUnitException)
                exception = exception.InnerException;

            if (IsExpectedExceptionType(exception))
            {
                if (IsExpectedMessageMatch(exception))
                {
                    if (exceptionHandler != null)
                        Reflect.InvokeMethod(exceptionHandler, testMethod.Fixture, exception);

                    testResult.Success();
                }
                else
                {
                    testResult.Failure(WrongTextMessage(exception), GetStackTrace(exception));
                }
            }
            else
            {
                switch (NUnitFramework.GetResultState(exception))
                {
                    case ResultState.Failure:
                        testResult.Failure(exception.Message, exception.StackTrace);
                        break;
                    case ResultState.Ignored:
                        testResult.Ignore(exception);
                        break;
                    case ResultState.Inconclusive:
                        testResult.SetResult(ResultState.Inconclusive, exception, FailureSite.Test);
                        break;
                    case ResultState.Success:
                        testResult.Success(exception.Message);
                        break;
                    default:
                        testResult.Failure(WrongTypeMessage(exception), GetStackTrace(exception));
                        break;
                }
            }
		}
Esempio n. 21
0
        public void RunTestMethod(TestResult testResult, out List<string> traceMessages)
        {
            traceMessages = new List<string>();

            var executionContext = new NJasmineTestRunContext(Position, _globalSetup, traceMessages);
            var runner = new NJasmineTestRunner(executionContext);

            SpecificationFixture fixture = this._fixtureFactory();

            fixture.CurrentPosition = new TestPosition(0);
            fixture.Visitor = runner;
            try
            {
                fixture.Run();
            }
            finally
            {
                executionContext.RunAllPerTestTeardowns();
            }
            testResult.Success();
        }