Esempio n. 1
0
		protected virtual void RecordException( Exception exception, TestResult testResult, FailureSite failureSite )
		{
            if (exception is NUnitException)
                exception = exception.InnerException;

            testResult.SetResult(NUnitFramework.GetResultState(exception), exception, failureSite);
		}
Esempio n. 2
0
        protected virtual void RecordException(Exception exception, TestResult testResult)
        {
            if (exception is NUnitException)
            {
                exception = exception.InnerException;
            }

            testResult.SetResult(NUnitFramework.GetResultState(exception), exception);
        }
//		public Test Decorate(Test test, MethodInfo method)
//		{
//			return DecorateTest( test, method );
//		}
//
//		public Test Decorate(Test test, Type fixtureType)
//		{
//			return DecorateTest( test, fixtureType );
//		}

        public Test Decorate(Test test, MemberInfo member)
        {
            Attribute ignoreAttribute = Reflect.GetAttribute(member, NUnitFramework.IgnoreAttribute, false);

            if (ignoreAttribute != null)
            {
                test.RunState     = RunState.Ignored;
                test.IgnoreReason = NUnitFramework.GetIgnoreReason(ignoreAttribute);
            }

            return(test);
        }
Esempio n. 4
0
		protected virtual void RecordException( Exception exception, TestResult testResult, FailureSite failureSite )
		{
            if (exception is NUnitException)
                exception = exception.InnerException;

            // Ensure that once a test is cancelled, it stays cancelled
            ResultState finalResultState = testResult.ResultState == ResultState.Cancelled
                ? ResultState.Cancelled
                : NUnitFramework.GetResultState(exception);

            testResult.SetResult(finalResultState, exception, failureSite);
		}
        public LegacySuite(Type fixtureType) : base(fixtureType)
        {
            PropertyInfo suiteProperty = GetSuiteProperty(fixtureType);

            if (suiteProperty == null)
            {
                throw new ArgumentException("Invalid argument to LegacySuite constructor", "fixtureType");
            }

            this.fixtureSetUp    = NUnitFramework.GetFixtureSetUpMethod(fixtureType);
            this.fixtureTearDown = NUnitFramework.GetFixtureTearDownMethod(fixtureType);

            MethodInfo method = suiteProperty.GetGetMethod(true);

            if (method.GetParameters().Length == 0)
            {
                Type returnType = method.ReturnType;

                if (returnType.FullName == "NUnit.Core.TestSuite")
                {
                    TestSuite suite = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
                    foreach (Test test in suite.Tests)
                    {
                        this.Add(test);
                    }
                }
                else if (typeof(IEnumerable).IsAssignableFrom(returnType))
                {
                    foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0]))
                    {
                        Type type = obj as Type;
                        if (type != null && TestFixtureBuilder.CanBuildFrom(type))
                        {
                            this.Add(TestFixtureBuilder.BuildFrom(type));
                        }
                        else
                        {
                            this.Add(obj);
                        }
                    }
                }
                else
                {
                    this.RunState     = RunState.NotRunnable;
                    this.IgnoreReason = "Suite property must return either TestSuite or IEnumerable";
                }
            }
            else
            {
                this.RunState     = RunState.NotRunnable;
                this.IgnoreReason = "Suite property may not be indexed";
            }
        }
        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. 7
0
        public SetUpFixture(Type type) : base(type)
        {
            this.TestName.Name = type.Namespace;
            if (this.TestName.Name == null)
            {
                this.TestName.Name = "[default namespace]";
            }
            int index = TestName.Name.LastIndexOf('.');

            if (index > 0)
            {
                this.TestName.Name = this.TestName.Name.Substring(index + 1);
            }

            this.fixtureSetUp    = NUnitFramework.GetSetUpMethod(type);
            this.fixtureTearDown = NUnitFramework.GetTearDownMethod(type);
        }
Esempio n. 8
0
        public LegacySuite(Type fixtureType) : base(fixtureType)
        {
            suiteProperty = GetSuiteProperty(fixtureType);

            this.fixtureSetUp    = NUnitFramework.GetFixtureSetUpMethod(fixtureType);
            this.fixtureTearDown = NUnitFramework.GetFixtureTearDownMethod(fixtureType);

            MethodInfo method = suiteProperty.GetGetMethod(true);

            if (method.ReturnType.FullName != "NUnit.Core.TestSuite" || method.GetParameters().Length > 0)
            {
                this.RunState     = RunState.NotRunnable;
                this.IgnoreReason = "Invalid suite property method signature";
            }
            else
            {
                TestSuite suite = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
                foreach (Test test in suite.Tests)
                {
                    this.Add(test);
                }
            }
        }
        /// <summary>
        /// Run a test returning the result. Overrides TestMethod
        /// to count assertions.
        /// </summary>
        /// <param name="testResult"></param>
        public override void Run(TestCaseResult testResult)
        {
            base.Run(testResult);

            testResult.AssertCount = NUnitFramework.GetAssertCount();
        }
 public NUnitTestMethod(MethodInfo method) : base(method)
 {
     this.setUpMethod    = NUnitFramework.GetSetUpMethod(this.FixtureType);
     this.tearDownMethod = NUnitFramework.GetTearDownMethod(this.FixtureType);
 }
        protected override void DoOneTimeTearDown(TestResult suiteResult)
        {
            base.DoOneTimeTearDown(suiteResult);

            suiteResult.AssertCount += NUnitFramework.GetAssertCount();
        }
        protected override void DoOneTimeSetUp(TestResult suiteResult)
        {
            base.DoOneTimeSetUp(suiteResult);

            suiteResult.AssertCount = NUnitFramework.GetAssertCount();;
        }
 public NUnitTestFixture(Type fixtureType) : base(fixtureType)
 {
     this.fixtureSetUp    = NUnitFramework.GetFixtureSetUpMethod(fixtureType);
     this.fixtureTearDown = NUnitFramework.GetFixtureTearDownMethod(fixtureType);
 }