File: NUnitTestCaseBuilder.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (76 lines) | stat: -rw-r--r-- 2,933 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// ****************************************************************
// This is free software licensed under the NUnit license. You
// may obtain a copy of the license as well as information regarding
// copyright ownership at http://nunit.org/?p=license&r=2.4.
// ****************************************************************

using System;
using System.Reflection;
using System.Collections;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Diagnostics;

namespace NUnit.Core.Builders
{
	public class NUnitTestCaseBuilder : AbstractTestCaseBuilder
	{
		private bool allowOldStyleTests = NUnitFramework.AllowOldStyleTests;

        #region AbstractTestCaseBuilder Overrides
		/// <summary>
		/// Determine if the method is an NUnit test method.
		/// The method must normally be marked with the test
		/// attribute for this to be true. If the test config
		/// file sets AllowOldStyleTests to true, then any 
		/// method beginning "test..." (case-insensitive)
		/// is treated as a test unless it is also marked
		/// as a setup or teardown method.
		/// </summary>
		/// <param name="method">A MethodInfo for the method being used as a test method</param>
		/// <returns>True if the builder can create a test case from this method</returns>
        public override bool CanBuildFrom(MethodInfo method)
        {
            if ( Reflect.HasAttribute( method, NUnitFramework.TestAttribute, false ) )
                return true;

            if (allowOldStyleTests)
            {
                Regex regex = new Regex("^(?i:test)");
                if ( regex.Match(method.Name).Success 
					&& !NUnitFramework.IsSetUpMethod( method )
					&& !NUnitFramework.IsTearDownMethod( method )
					&& !NUnitFramework.IsFixtureSetUpMethod( method )
					&& !NUnitFramework.IsFixtureTearDownMethod( method ) )
						return true;
            }

            return false;
        }

		/// <summary>
		/// Create an NUnitTestMethod
		/// </summary>
		/// <param name="method">A MethodInfo for the method being used as a test method</param>
		/// <returns>A new NUnitTestMethod</returns>
        protected override TestCase MakeTestCase(MethodInfo method)
        {
			return new NUnitTestMethod( method );
        }

		/// <summary>
		/// Set additional properties of the newly created test case based
		/// on its attributes. As implemented, the method sets the test's
		/// RunState,  Description, Categories and Properties.
		/// </summary>
		/// <param name="method">A MethodInfo for the method being used as a test method</param>
		/// <param name="testCase">The test case being constructed</param>
		protected override void SetTestProperties( MethodInfo method, TestCase testCase )
		{
            NUnitFramework.ApplyCommonAttributes( method, testCase );
			NUnitFramework.ApplyExpectedExceptionAttribute( method, (TestMethod)testCase );
		}
		#endregion
    }
}