1 // ***********************************************************************
2 // Copyright (c) 2012 Charlie Poole
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
29 using System.Collections.Generic;
30 using NUnit.Framework.Interfaces;
31 using NUnit.Framework.Internal.Commands;
32 using NUnit.Framework.Internal.Execution;
34 namespace NUnit.Framework.Internal
37 /// The TestMethod class represents a Test implemented as a method.
39 public class TestMethod : Test
44 /// The ParameterSet used to create this test method
46 internal TestCaseParameters parms;
53 /// Initializes a new instance of the <see cref="TestMethod"/> class.
55 /// <param name="method">The method to be used as a test.</param>
56 public TestMethod(IMethodInfo method) : base (method) { }
59 /// Initializes a new instance of the <see cref="TestMethod"/> class.
61 /// <param name="method">The method to be used as a test.</param>
62 /// <param name="parentSuite">The suite or fixture to which the new test will be added</param>
63 public TestMethod(IMethodInfo method, Test parentSuite) : base(method )
65 // Needed to give proper fullname to test in a parameterized fixture.
66 // Without this, the arguments to the fixture are not included.
67 if (parentSuite != null)
68 FullName = parentSuite.FullName + "." + Name;
75 internal bool HasExpectedResult
77 get { return parms != null && parms.HasExpectedResult; }
80 internal object ExpectedResult
82 get { return parms != null ? parms.ExpectedResult : null; }
85 internal object[] Arguments
87 get { return parms != null ? parms.Arguments : null; }
92 #region Test Overrides
95 /// Overridden to return a TestCaseResult.
97 /// <returns>A TestResult for this test.</returns>
98 public override TestResult MakeTestResult()
100 return new TestCaseResult(this);
104 /// Gets a bool indicating whether the current test
105 /// has any descendant tests.
107 public override bool HasChildren
109 get { return false; }
113 /// Returns a TNode representing the current result after
114 /// adding it as a child of the supplied parent node.
116 /// <param name="parentNode">The parent node.</param>
117 /// <param name="recursive">If true, descendant results are included</param>
118 /// <returns></returns>
119 public override TNode AddToXml(TNode parentNode, bool recursive)
121 TNode thisNode = parentNode.AddElement(XmlElementName);
123 PopulateTestNode(thisNode, recursive);
125 thisNode.AddAttribute("seed", this.Seed.ToString());
131 /// Gets this test's child tests
133 /// <value>A list of child tests</value>
134 public override IList<ITest> Tests
136 get { return new ITest[0]; }
140 /// Gets the name used for the top-level element in the
141 /// XML representation of this test
143 public override string XmlElementName
145 get { return "test-case"; }
149 /// Returns the name of the method
151 public override string MethodName
153 get { return Method.Name; }