PageRenderTime 19ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/ParameterizedTestMethodSuite.cs

#
C# | 100 lines | 55 code | 11 blank | 34 comment | 8 complexity | 51a02d8cc7a1999f531ed64f70542b8d MD5 | raw file
  1// ****************************************************************
  2// Copyright 2008, Charlie Poole
  3// This is free software licensed under the NUnit license. You may
  4// obtain a copy of the license at http://nunit.org.
  5// ****************************************************************
  6using System.Reflection;
  7using System.Text;
  8
  9namespace NUnit.Core
 10{
 11    /// <summary>
 12    /// ParameterizedMethodSuite holds a collection of individual
 13    /// TestMethods with their arguments applied.
 14    /// </summary>
 15    public class ParameterizedMethodSuite : TestSuite
 16    {
 17        private bool isTheory;
 18
 19        /// <summary>
 20        /// Construct from a MethodInfo
 21        /// </summary>
 22        /// <param name="method"></param>
 23        public ParameterizedMethodSuite(MethodInfo method)
 24            : base(method.ReflectedType.FullName, method.Name)
 25        {
 26            this.maintainTestOrder = true;
 27            this.isTheory = Reflect.HasAttribute(method, NUnitFramework.TheoryAttribute, true);
 28        }
 29
 30        /// <summary>
 31        /// Gets a string representing the kind of test
 32        /// that this object represents, for use in display.
 33        /// </summary>
 34        public override string TestType
 35        {
 36            get 
 37            { 
 38                return this.isTheory
 39                    ? "Theory"
 40                    : "ParameterizedTest"; 
 41            }
 42        }
 43
 44        /// <summary>
 45        /// Override Run, setting Fixture to that of the Parent.
 46        /// </summary>
 47        /// <param name="listener"></param>
 48        /// <param name="filter"></param>
 49        /// <returns></returns>
 50        public override TestResult Run(EventListener listener, ITestFilter filter)
 51        {
 52            if (this.Parent != null)
 53            {
 54                this.Fixture = this.Parent.Fixture;
 55                TestSuite suite = this.Parent as TestSuite;
 56                if (suite != null)
 57                {
 58                    this.setUpMethods = suite.GetSetUpMethods();
 59                    this.tearDownMethods = suite.GetTearDownMethods();
 60                }
 61            }
 62
 63            // DYNAMIC: Get the parameters, and add the methods here.
 64            
 65            TestResult result = base.Run(listener, filter);
 66			
 67            if (this.isTheory && result.ResultState == ResultState.Inconclusive)
 68                result.SetResult(
 69                    ResultState.Failure,
 70                    this.TestCount == 0
 71                        ? "No test cases were provided"
 72                        : "All test cases were inconclusive",
 73                    null);
 74
 75			this.Fixture = null;
 76			this.setUpMethods = null;
 77			this.tearDownMethods = null;
 78
 79            return result;
 80        }
 81
 82        /// <summary>
 83        /// Override DoOneTimeSetUp to avoid executing any
 84        /// TestFixtureSetUp method for this suite
 85        /// </summary>
 86        /// <param name="suiteResult"></param>
 87        protected override void DoOneTimeSetUp(TestResult suiteResult)
 88        {
 89        }
 90
 91        /// <summary>
 92        /// Override DoOneTimeTearDown to avoid executing any
 93        /// TestFixtureTearDown method for this suite.
 94        /// </summary>
 95        /// <param name="suiteResult"></param>
 96        protected override void DoOneTimeTearDown(TestResult suiteResult)
 97        {
 98        }
 99    }
100}