コード例 #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);
        }
コード例 #2
0
        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;
        }
コード例 #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);
        }
コード例 #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 });
        }
コード例 #5
0
        public Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite)
        {
            ParameterizedMethodSuite parameterizedMethodSuite = new ParameterizedMethodSuite(method);

            parameterizedMethodSuite.ApplyCommonAttributes(method);
            foreach (ITestCaseData item in testCaseProvider.GetTestCasesFor(method))
            {
                ParameterSet parameterSet = item as ParameterSet;
                if (parameterSet == null)
                {
                    parameterSet = new ParameterSet(item);
                }
                TestMethod test = BuildSingleTestMethod(method, parentSuite, parameterSet);
                parameterizedMethodSuite.Add(test);
            }
            return(parameterizedMethodSuite);
        }
コード例 #6
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>
        /// <returns>A ParameterizedMethodSuite populated with test cases</returns>
        public static Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite)
        {
            ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method);
            NUnitFramework.ApplyCommonAttributes(method, methodSuite);

            foreach (object source in CoreExtensions.Host.TestCaseProviders.GetTestCasesFor(method, parentSuite))
            {
                ParameterSet parms;

                if (source == null)
                {
                    parms = new ParameterSet();
                    parms.Arguments = new object[] { null };
                }
                else
                    parms = source as ParameterSet;

                if (parms == null)
                {
                    if (source.GetType().GetInterface("NUnit.Framework.ITestCaseData") != null)
                        parms = ParameterSet.FromDataSource(source);
                    else
                    {
                        parms = new ParameterSet();

                        ParameterInfo[] parameters = method.GetParameters();
                        Type sourceType = source.GetType();

                        if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(sourceType))
                            parms.Arguments = new object[] { source };
                        else if (source is object[])
                            parms.Arguments = (object[])source;
                        else if (source is Array)
                        {
                            Array array = (Array)source;
                            if (array.Rank == 1)
                            {
                                parms.Arguments = new object[array.Length];
                                for (int i = 0; i < array.Length; i++)
                                    parms.Arguments[i] = (object)array.GetValue(i);
                            }
                        }
                        else
                            parms.Arguments = new object[] { source };
                    }
                }

                TestMethod test = BuildSingleTestMethod(method, parentSuite, parms);

                methodSuite.Add(test);
            }

            return methodSuite;
        }
コード例 #7
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;
        }
コード例 #8
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>
        /// <returns>A ParameterizedMethodSuite populated with test cases</returns>
        public static Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite)
        {
            ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method);

            NUnitFramework.ApplyCommonAttributes(method, methodSuite);

            if (parentSuite != null)
            {
                if (parentSuite.RunState == RunState.NotRunnable && methodSuite.RunState != RunState.NotRunnable)
                {
                    methodSuite.RunState     = RunState.NotRunnable;
                    methodSuite.IgnoreReason = parentSuite.IgnoreReason;
                }

                if (parentSuite.RunState == RunState.Ignored && methodSuite.RunState != RunState.Ignored && methodSuite.RunState != RunState.NotRunnable)
                {
                    methodSuite.RunState     = RunState.Ignored;
                    methodSuite.IgnoreReason = parentSuite.IgnoreReason;
                }
            }

            foreach (object source in CoreExtensions.Host.TestCaseProviders.GetTestCasesFor(method, parentSuite))
            {
                ParameterSet parms;

                if (source == null)
                {
                    parms           = new ParameterSet();
                    parms.Arguments = new object[] { null };
                }
                else
                {
                    parms = source as ParameterSet;
                }

                if (parms == null)
                {
                    if (source.GetType().GetInterface("NUnit.Framework.ITestCaseData") != null)
                    {
                        parms = ParameterSet.FromDataSource(source);
                    }
                    else
                    {
                        parms = new ParameterSet();

                        ParameterInfo[] parameters = method.GetParameters();
                        Type            sourceType = source.GetType();

                        if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(sourceType))
                        {
                            parms.Arguments = new object[] { source }
                        }
                        ;
                        else if (source is object[])
                        {
                            parms.Arguments = (object[])source;
                        }
                        else if (source is Array)
                        {
                            Array array = (Array)source;
                            if (array.Rank == 1)
                            {
                                parms.Arguments = new object[array.Length];
                                for (int i = 0; i < array.Length; i++)
                                {
                                    parms.Arguments[i] = (object)array.GetValue(i);
                                }
                            }
                        }
                        else
                        {
                            parms.Arguments = new object[] { source }
                        };
                    }
                }

                TestMethod test = BuildSingleTestMethod(method, parentSuite, parms);

                methodSuite.Add(test);
            }

            return(methodSuite);
        }