public ExpectedExceptionProcessor(TestMethod testMethod, object source)
        {
            this.testMethod = testMethod;

            this.expectedExceptionType = GetExceptionType(source);
            this.expectedExceptionName = GetExceptionName(source);
            this.expectedMessage = GetExpectedMessage(source);
            this.matchType = GetMatchType(source);
            this.userMessage = GetUserMessage(source);

            string handlerName = GetHandler(source);
            if (handlerName == null)
                this.exceptionHandler = GetDefaultExceptionHandler(testMethod.FixtureType);
            else
            {
                MethodInfo handler = GetExceptionHandler(testMethod.FixtureType, handlerName);
                if (handler != null)
                    this.exceptionHandler = handler;
                else
                {
                    testMethod.RunState = RunState.NotRunnable;
                    testMethod.IgnoreReason = string.Format(
                        "The specified exception handler {0} was not found", handlerName);
                }
            }
        }
Example #2
0
        public void setup()
        {
            decorateTestSpecification = Substitute.For<DecorateTestSpecification>();
            nspecTestMethodBuilder = new NSpecTestMethodBuilder();
            decorator = new NSpecTestDecorator(decorateTestSpecification, nspecTestMethodBuilder);

            test = NUnitSubstitute.ForTestMethod();
        }
		private UnitTestResult CreateNewTestResult ( TestMethod test, string currentAssemblyPath )
		{
			return new UnitTestResult ()
			{
				Message = "",
				StackTrace = "",
				Duration = 0,
				Test = CreateUnitTestInfo(test),
				AssemblyPath = currentAssemblyPath
			};
		}
		public UnitTestInfo ( TestMethod testMethod )
		{
			if (testMethod == null)
				throw new ArgumentException();

			MethodName = testMethod.MethodName;
			FullMethodName = testMethod.Method.ToString ();
			ClassName = testMethod.FixtureType.Name;
			FullClassName = testMethod.ClassName;
			Namespace = testMethod.Method.ReflectedType.Namespace;
			FullName = testMethod.TestName.FullName;

			ParamName = ExtractMethodCallParametersString (FullName);
		}
Example #5
0
 private string GetAssemblyPath(TestMethod testMethod)
 {
     var parent = testMethod as Test;
     var assemblyPath = "";
     while (parent != null)
     {
         parent = parent.Parent;
         if (!(parent is TestAssembly)) continue;
         var path = (parent as TestAssembly).TestName.FullName;
         if (!File.Exists(path)) continue;
         assemblyPath = path;
         break;
     }
     return assemblyPath;
 }
Example #6
0
 public virtual NSpecTestMethod Build(TestMethod test)
 {
     return new NSpecTestMethod(test.Method)
                {
                    BuilderException = test.BuilderException,
                    Categories = test.Categories,
                    Description = test.Description,
                    ExceptionProcessor = test.ExceptionProcessor,
                    Fixture = test.Fixture,
                    IgnoreReason = test.IgnoreReason,
                    Parent = test.Parent,
                    Properties = test.Properties,
                    RunState = test.RunState
                };
 }
        public void setup()
        {
            builder = new NSpecTestMethodBuilder();

            test = NUnitSubstitute.ForTestMethod();
            test.BuilderException = new Exception();
            test.Categories = new ArrayList();
            test.Description = "description";
            test.ExceptionProcessor = Substitute.For<ExpectedExceptionProcessor>(test);
            test.Fixture = this;
            test.IgnoreReason = "ignoreReason";
            test.Parent = NUnitSubstitute.ForTest();
            test.Properties = new Hashtable();
            test.RunState = RunState.Runnable;
        }
		public TestDecorator( TestMethod test )
			//: base( (TestName)test.TestName.Clone() )
            : base( test.Method )
		{
			this.test = test;
			this.RunState = test.RunState;
			this.IgnoreReason = test.IgnoreReason;
            this.Description = test.Description;
            this.Categories = new System.Collections.ArrayList( test.Categories );
            if ( test.Properties != null )
            {
                this.Properties = new ListDictionary();
                foreach (DictionaryEntry entry in test.Properties)
                    this.Properties.Add(entry.Key, entry.Value);
            }
        }
Example #9
0
        public UnitTestInfo(TestMethod testMethod) {
            if (testMethod == null)
            { throw new ArgumentException(); }

            MethodName = testMethod.MethodName;
            FullMethodName = testMethod.Method.ToString();
            ClassName = testMethod.FixtureType.Name;
            FullClassName = testMethod.ClassName;
            Namespace = testMethod.Method.ReflectedType.Namespace;
            FullName = testMethod.TestName.FullName;
            ParamName = ExtractMethodCallParametersString(FullName);
            Id = testMethod.TestName.TestID.ToString();

            Categories = testMethod.Categories.Cast<string>().ToArray();

            AssemblyPath = GetAssemblyPath(testMethod);
        }
 private string GetAssemblyPath(TestMethod testMethod)
 {
     Test test = testMethod;
     while (test != null)
     {
         test = test.get_Parent();
         if (test is TestAssembly)
         {
             string path = (test as TestAssembly).get_TestName().get_FullName();
             if (File.Exists(path))
             {
                 return path;
             }
         }
     }
     return "";
 }
 public EditorTestInfo(TestMethod testMethod)
 {
     this.methodName = testMethod.get_MethodName();
     this.fullMethodName = testMethod.get_Method().ToString();
     this.className = testMethod.get_FixtureType().Name;
     this.fullClassName = testMethod.get_ClassName();
     this.Namespace = testMethod.get_Method().ReflectedType.Namespace;
     this.fullName = testMethod.get_TestName().get_FullName();
     this.paramName = ExtractMethodCallParametersString(this.fullName);
     this.id = testMethod.get_TestName().get_TestID().GetHashCode().ToString();
     List<string> list = Enumerable.ToList<string>(Enumerable.Cast<string>(testMethod.get_Categories()));
     if (testMethod.get_Parent().get_Categories().Count > 0)
     {
         list.AddRange(Enumerable.Cast<string>(testMethod.get_Parent().get_Categories()));
     }
     if (testMethod.get_Parent() is ParameterizedMethodSuite)
     {
         list.AddRange(Enumerable.Cast<string>(testMethod.get_Parent().get_Parent().get_Categories()));
     }
     this.categories = list.ToArray();
     this.assemblyPath = this.GetAssemblyPath(testMethod);
     this.isIgnored = testMethod.get_RunState() == 4;
 }
Example #12
0
        /// <summary>
        /// Modify a newly constructed test by checking for ExpectedExceptionAttribute
        /// and setting properties on the test accordingly.
        /// </summary>
        /// <param name="attributes">An array of attributes possibly including NUnit attributes
        /// <param name="test">The test to which the attributes apply</param>
        public static void ApplyExpectedExceptionAttribute(MethodInfo method, TestMethod testMethod)
        {
            Attribute attribute = Reflect.GetAttribute(
                method, NUnitFramework.ExpectedExceptionAttribute, false);

            if (attribute != null)
                testMethod.ExceptionProcessor = new ExpectedExceptionProcessor(testMethod, attribute);
        }
Example #13
0
 public DirectTestMethod(TestMethod other)
     : base(other.Method)
 {
     foreach (var fld in typeof(TestMethod).GetAllFields())
         fld.SetValue(this, fld.GetValue(other));
     if (Tests != null)
         foreach (Test child in Tests)
             child.Parent = this;
 }
 public TestLineTreeViewItem(TestMethod test, int depth, TreeViewItem parent) : base(test, depth, parent)
 {
 }
Example #15
0
        private testcaseType RunTest(TestMethod t)
        {
            TestFilter filter = new NameFilter(t.TestName);
            var result = (t as TestMethod).Run(new TestListener(), filter);

            //result types
            //Ignored, Failure, NotRunnable, Error, Success
            var testCase = new testcaseType
                {
                    name = t.TestName.Name,
                    executed = result.Executed.ToString(),
                    success = result.IsSuccess.ToString(),
                    asserts = result.AssertCount.ToString(CultureInfo.InvariantCulture),
                    time = result.Time.ToString(CultureInfo.InvariantCulture)
                };

            switch (result.ResultState)
            {
                case ResultState.Cancelled:
                    testCase.result = "Cancelled";
                    break;
                case ResultState.Error:
                    var f = new failureType {message = result.Message, stacktrace = result.StackTrace};
                    testCase.Item = f;
                    testCase.result = "Error";
                    break;
                case ResultState.Failure:
                    var fail = new failureType {message = result.Message, stacktrace = result.StackTrace};
                    testCase.Item = fail;
                    testCase.result = "Failure";
                    break;
                case ResultState.Ignored:
                    testCase.result = "Ignored";
                    break;
                case ResultState.Inconclusive:
                    testCase.result = "Inconclusive";
                    break;
                case ResultState.NotRunnable:
                    testCase.result = "NotRunnable";
                    break;
                case ResultState.Skipped:
                    testCase.result = "Skipped";
                    break;
                case ResultState.Success:
                    testCase.result = "Success";
                    break;
            }

            return testCase;
        }
Example #16
0
 public TestMethodThread(TestMethod testMethod)
     : base(testMethod)
 {
     this.testMethod = testMethod;
 }
Example #17
0
 public DynamoRevitTest(TestMethod test)
 {
     _test = test;
     _listener = new RevitTestEventListener(this);
     RunCommand = new DelegateCommand(Run, CanRun);
     _resultType = DynamoRevitTestResultType.Unknown;
     _testName = _test.TestName.Name;
 }
 public ExpectedExceptionProcessor( TestMethod testMethod )
 {
     this.testMethod = testMethod;
 }
Example #19
0
		// TODO: Handle this with a separate ExceptionProcessor object
		public static void ApplyExpectedExceptionAttribute(MethodInfo method, TestMethod testMethod)
		{
			Attribute attribute = Reflect.GetAttribute(
                method, NUnitFramework.ExpectedExceptionAttribute, false );

			if (attribute != null)
			{
				testMethod.ExceptionExpected = true;

				Type expectedExceptionType = GetExceptionType( attribute );
				string expectedExceptionName = GetExceptionName( attribute );
				if ( expectedExceptionType != null )
					testMethod.ExpectedExceptionType = expectedExceptionType;
				else if ( expectedExceptionName != null )
					testMethod.ExpectedExceptionName = expectedExceptionName;
				
				testMethod.ExpectedMessage = GetExpectedMessage( attribute );
				testMethod.MatchType = GetMatchType( attribute );
				testMethod.UserMessage = GetUserMessage( attribute );

				string handlerName = GetHandler( attribute );
				if ( handlerName == null )
					testMethod.ExceptionHandler = GetDefaultExceptionHandler( testMethod.FixtureType );
				else
				{
					MethodInfo handler = GetExceptionHandler( testMethod.FixtureType, handlerName );
					if ( handler != null )
						testMethod.ExceptionHandler = handler;
					else
					{
						testMethod.RunState = RunState.NotRunnable;
						testMethod.IgnoreReason = string.Format( 
							"The specified exception handler {0} was not found", handlerName );
					}
				}
			}
		}
 /// <summary>
 /// The constructor method for the class. Sets the local member variables with the passed in values
 /// </summary>
 /// <param name="testMethod">The NUnit Test Method</param>
 /// <param name="testCaseId">The ID of the matching SpiraTeam test case</param>
 public ExtendedNUnitTestCase(TestMethod testMethod, int testCaseId)
     : base(testMethod.Method)
 {
     this.testMethod = testMethod;
     this.testCaseId = testCaseId;
 }
 public ExpectedExceptionProcessor(TestMethod testMethod)
 {
     this.testMethod = testMethod;
 }
 public void TestStarted(TestMethod testCase)
 {
     currentTestName = testCase.TestName.FullName;
 }
 public void SetTestMethod(TestMethod testMethod)
 {
     this.m_Test.testMethod = testMethod;
 }
		private UnitTestInfo CreateUnitTestInfo (TestMethod test)
		{
			//this shouldn't be initialize by constructor
			//return test.UnitTestInfo ();
			return new UnitTestInfo (test);
		}
 private static bool MarkAsNotRunnable(TestMethod testMethod, string reason)
 {
     testMethod.RunState = RunState.NotRunnable;
     testMethod.IgnoreReason = reason;
     return false;
 }