Esempio n. 1
0
        /// <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);
            }

            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;

                string prefix = 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.TestName != null)
                {
                    testMethod.Name     = parms.TestName;
                    testMethod.FullName = prefix + "." + parms.TestName;
                }
                else if (parms.OriginalArguments != null)
                {
                    string name = method.GetDisplayName(parms.OriginalArguments);
                    testMethod.Name     = name;
                    testMethod.FullName = prefix + "." + name;
                }

                parms.ApplyToTest(testMethod);
            }

            return(testMethod);
        }
Esempio n. 2
0
        /// <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);

            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;

                string prefix = 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.TestName != null)
                {
                    testMethod.Name = parms.TestName;
                    testMethod.FullName = prefix + "." + parms.TestName;
                }
                else if (parms.OriginalArguments != null)
                {
                    string name = method.GetDisplayName(parms.OriginalArguments);
                    testMethod.Name = name;
                    testMethod.FullName = prefix + "." + name;
                }

                parms.ApplyToTest(testMethod);
            }

            return testMethod;
        }