/// <summary> /// Builds a ParameterizedMetodSuite containing individual /// test cases for each set of parameters provided for /// this method. /// </summary> /// <param name="method">The MethodInfo for which a test is to be built</param> /// <param name="parentSuite">The test suite for which the method is being built</param> /// <returns>A ParameterizedMethodSuite populated with test cases</returns> public Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite) { ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); #if PORTABLE methodSuite.ApplyAttributesToTest(method.AsCustomAttributeProvider()); #else methodSuite.ApplyAttributesToTest(method); #endif foreach (ITestCaseData testcase in testCaseProvider.GetTestCasesFor(method)) { ParameterSet parms = testcase as ParameterSet; if (parms == null) { parms = new ParameterSet(testcase); } TestMethod test = BuildSingleTestMethod(method, parentSuite, parms); methodSuite.Add(test); } return(methodSuite); }
/// <summary> /// Builds a single NUnitTestMethod, either as a child of the fixture /// or as one of a set of test cases under a ParameterizedTestMethodSuite. /// </summary> /// <param name="method">The MethodInfo from which to construct the TestMethod</param> /// <param name="parentSuite">The suite or fixture to which the new test will be added</param> /// <param name="parms">The ParameterSet to be used, or null</param> /// <returns></returns> private TestMethod BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms) { TestMethod testMethod = new TestMethod(method, parentSuite); testMethod.Seed = randomizer.Next(); string prefix = method.ReflectedType.FullName; // Needed to give proper fullname to test in a parameterized fixture. // Without this, the arguments to the fixture are not included. if (parentSuite != null) { prefix = parentSuite.FullName; //testMethod.FullName = prefix + "." + testMethod.Name; } if (CheckTestMethodSignature(testMethod, parms)) { if (parms == null) #if PORTABLE { testMethod.ApplyAttributesToTest(method.AsCustomAttributeProvider()); } #else { testMethod.ApplyAttributesToTest(method); } #endif foreach (ICommandDecorator decorator in method.GetCustomAttributes(typeof(ICommandDecorator), true)) { testMethod.CustomDecorators.Add(decorator); } ExpectedExceptionAttribute[] attributes = (ExpectedExceptionAttribute[])method.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false); if (attributes.Length > 0) { ExpectedExceptionAttribute attr = attributes[0]; string handlerName = attr.Handler; if (handlerName != null && GetExceptionHandler(testMethod.FixtureType, handlerName) == null) { MarkAsNotRunnable( testMethod, string.Format("The specified exception handler {0} was not found", handlerName)); } testMethod.CustomDecorators.Add(new ExpectedExceptionDecorator(attr.ExceptionData)); } } if (parms != null) { // NOTE: After the call to CheckTestMethodSignature, the Method // property of testMethod may no longer be the same as the // original MethodInfo, so we reassign it here. method = testMethod.Method; if (parms.TestName != null) { testMethod.Name = parms.TestName; testMethod.FullName = prefix + "." + parms.TestName; } else if (parms.OriginalArguments != null) { string name = MethodHelper.GetDisplayName(method, parms.OriginalArguments); testMethod.Name = name; testMethod.FullName = prefix + "." + name; } parms.ApplyToTest(testMethod); } return(testMethod); }