/// <summary> /// Builds a single TestMethod /// </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="parameterSet">The ParameterSet to be used, or null</param> /// <returns></returns> private TestMethod BuildTestMethod(MethodInfo method, ITest parentSuite, TestCaseParameters parameterSet) { 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, parameterSet)) { testMethod.ApplyAttributesToTest(method.ReflectedType); testMethod.ApplyAttributesToTest(method); foreach (ICommandWrapper decorator in method.GetCustomAttributes(typeof(ICommandWrapper), true)) { testMethod.CustomDecorators.Add(decorator); } } // NOTE: In the case of a generic method, testMethod.Method // may be changed in the call to CheckTestMethodSignature. // This is just -in case some future change tries to use it. method = testMethod.Method; if (parameterSet != null) { if (parameterSet.TestName != null) { testMethod.Name = parameterSet.TestName; testMethod.FullName = prefix + "." + parameterSet.TestName; } else if (parameterSet.OriginalArguments != null) { string name = MethodHelper.GetDisplayName(method, parameterSet.OriginalArguments); testMethod.Name = name; testMethod.FullName = prefix + "." + name; } parameterSet.ApplyToTest(testMethod); } if (parentSuite.RunState == RunState.NotRunnable || parentSuite.RunState == RunState.Skipped) { testMethod.RunState = parentSuite.RunState; var reasonKey = PropertyNames.SkipReason; testMethod.Properties.Set(reasonKey, parentSuite.Properties.Get(reasonKey)); } return(testMethod); }
public TestMethod BuildTestMethod(IMethodInfo method, Test?parentSuite, TestCaseParameters?parms) { var testMethod = new TestMethod(method, parentSuite) { Seed = _randomizer.Next() }; CheckTestMethodAttributes(testMethod); CheckTestMethodSignature(testMethod, parms); if (parms == null || parms.Arguments.Length == 0) { testMethod.ApplyAttributesToTest(method.MethodInfo); } // NOTE: After the call to CheckTestMethodSignature, the Method // property of testMethod may no longer be the same as the // original MethodInfo, so we don't use it here. string prefix = testMethod.Method.TypeInfo.FullName; // Needed to give proper full name to test in a parameterized fixture. // Without this, the arguments to the fixture are not included. if (parentSuite != null) { prefix = parentSuite.FullName; } if (parms != null) { parms.ApplyToTest(testMethod); if (parms.TestName != null) { // The test is simply for efficiency testMethod.Name = parms.TestName.Contains("{") ? new TestNameGenerator(parms.TestName).GetDisplayName(testMethod, parms.OriginalArguments) : parms.TestName; } else if (parms.ArgDisplayNames != null) { testMethod.Name = testMethod.Name + '(' + string.Join(", ", parms.ArgDisplayNames) + ')'; } else { testMethod.Name = _nameGenerator.GetDisplayName(testMethod, parms.OriginalArguments); } } else { testMethod.Name = _nameGenerator.GetDisplayName(testMethod, null); } testMethod.FullName = prefix + "." + testMethod.Name; return(testMethod); }
/// <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> public TestMethod BuildTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms) { var testMethod = new TestMethod(method, parentSuite) { 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; } if (CheckTestMethodSignature(testMethod, parms)) { if (parms == null || parms.Arguments == null) { testMethod.ApplyAttributesToTest(method); } } 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); }
/// <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> public TestMethod BuildTestMethod(IMethodInfo method, Test parentSuite, TestCaseParameters parms) { var testMethod = new TestMethod(method, parentSuite) { Seed = _randomizer.Next() }; CheckTestMethodSignature(testMethod, parms); if (parms == null || parms.Arguments == null) testMethod.ApplyAttributesToTest(method.MethodInfo); // NOTE: After the call to CheckTestMethodSignature, the Method // property of testMethod may no longer be the same as the // original MethodInfo, so we don't use it here. string prefix = testMethod.Method.TypeInfo.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; if (parms != null) { parms.ApplyToTest(testMethod); if (parms.TestName != null) { // The test is simply for efficiency testMethod.Name = parms.TestName.Contains("{") ? new TestNameGenerator(parms.TestName).GetDisplayName(testMethod, parms.OriginalArguments) : parms.TestName; } else { testMethod.Name = _nameGenerator.GetDisplayName(testMethod, parms.OriginalArguments); } } else { testMethod.Name = _nameGenerator.GetDisplayName(testMethod, null); } testMethod.FullName = prefix + "." + testMethod.Name; return testMethod; }
/// <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> public TestMethod BuildTestMethod(MethodInfo method, Test parentSuite, TestCaseParameters parms) { var testMethod = new TestMethod(method, parentSuite) { 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; if (CheckTestMethodSignature(testMethod, parms)) { if (parms == null || parms.Arguments == null) testMethod.ApplyAttributesToTest(method); } 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; }
/// <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 = random.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) { testMethod.ApplyAttributesToTest(method); } 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); }