Ejemplo n.º 1
0
        /// <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);
        }
        private Test BuildParameterizedMethodSuite(IMethodInfo method, IEnumerable<TestMethod> tests)
        {
            ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method);
            methodSuite.ApplyAttributesToTest(method.MethodInfo);

            foreach (TestMethod test in tests)
                methodSuite.Add(test);

            return methodSuite;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a ParameterizedMethodSuite containing individual test cases.
        /// </summary>
        /// <param name="method">The method to be used as a test.</param>
        /// <param name="tests">The list of test cases to include.</param>
        private Test BuildParameterizedMethodSuite(FixtureMethod method, IEnumerable <TestMethod> tests)
        {
            ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method);

            methodSuite.ApplyAttributesToTest(method.Method);

            foreach (TestMethod test in tests)
            {
                methodSuite.Add(test);
            }

            return(methodSuite);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Build a Test from the provided MethodInfo. Depending on
        /// whether the method takes arguments and on the availability
        /// of test case data, this method may return a single test
        /// or a group of tests contained in a ParameterizedMethodSuite.
        /// </summary>
        /// <param name="method">The MethodInfo for which a test is to be built</param>
        /// <param name="parentSuite">The test fixture being populated, or null</param>
        /// <returns>A Test representing one or more method invocations</returns>
        public IEnumerable <Test> BuildFrom(MethodInfo method, ITest parentSuite)
        {
            List <TestMethod> testCases = new List <TestMethod>();
            var name = method.Name; // For Debugging

            List <ITestCaseFactory> sources = new List <ITestCaseFactory>(
                (ITestCaseFactory[])method.GetCustomAttributes(typeof(ITestCaseFactory), false));

            // See if we need to add a CombinatorialAttribute for parameterized data
            var  parameters   = method.GetParameters();
            bool hasParamData = parameters.Any(param => param.IsDefined(typeof(IParameterDataSource), false));

            if (hasParamData)
            {
                bool hasStrategy = sources.Any(source => source is CombiningStrategyAttribute);
                if (!hasStrategy)
                {
                    sources.Add(new CombinatorialAttribute());
                }
            }

            foreach (ITestCaseFactory source in sources)
            {
                foreach (ITestCaseData testCase in source.GetTestCasesFor(method))
                {
                    var parameterSet = testCase as TestCaseParameters;
                    if (parameterSet == null)
                    {
                        parameterSet = new TestCaseParameters(testCase);
                    }

                    testCases.Add(BuildTestMethod(method, parentSuite, parameterSet));
                }
            }

            if (method.GetParameters().Length == 0)
            {
                return(testCases);
            }

            ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method);

            methodSuite.ApplyAttributesToTest(method);

            foreach (TestMethod testCase in testCases)
            {
                methodSuite.Add(testCase);
            }

            return(new [] { methodSuite });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Builds a ParameterizedMethodSuite containing individual test cases.
        /// </summary>
        /// <param name="method">The MethodInfo for which a test is to be built.</param>
        /// <param name="tests">The list of test cases to include.</param>
        /// <returns>A ParameterizedMethodSuite populated with test cases</returns>
        private Test BuildParameterizedMethodSuite(MethodInfo method, IEnumerable<TestMethod> tests)
        {
            ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method);
            methodSuite.ApplyAttributesToTest(method);

            foreach (TestMethod test in tests)
                methodSuite.Add(test);

            return methodSuite;
        }