Пример #1
0
        /// <summary>
        /// Build a TestSuite from type provided.
        /// </summary>
        /// <param name="type">The type of the fixture to be used</param>
        /// <returns>A TestSuite</returns>
        public Test BuildFrom(Type type)
        {
            TestSuite suite = new LegacySuite(type);

            if (suite.RunState == RunState.NotRunnable)
            {
                string reason = null;
                if (!IsValidFixtureType(type, ref reason))
                {
                    suite.RunState = RunState.NotRunnable;
                    suite.Properties.Set(PropertyNames.SkipReason, reason);
                }
            }

            PropertyInfo suiteProperty = GetSuiteProperty(type);
            MethodInfo   method        = suiteProperty.GetGetMethod(true);

            if (method.GetParameters().Length > 0)
            {
                suite.RunState = RunState.NotRunnable;
                suite.Properties.Set(PropertyNames.SkipReason, "Suite property may not be indexed");
            }
            // TODO: Stop checking for name
            else if (method.ReturnType.FullName == "NUnit.Framework.Internal.TestSuite")
            {
                TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
                foreach (Test test in s.Tests)
                {
                    suite.Add(test);
                }
            }
            else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType))
            {
                foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0]))
                {
                    Type objType = obj as Type;
                    if (objType != null && _defaultSuiteBuilder.CanBuildFrom(objType))
                    {
                        suite.Add(_defaultSuiteBuilder.BuildFrom(objType));
                    }
                    else
                    {
                        var fixture = _defaultSuiteBuilder.BuildFrom(obj.GetType());
                        if (fixture != null)
                        {
                            fixture.Fixture = obj;
                        }
                        suite.Add(fixture);
                    }
                }
            }
            else
            {
                suite.RunState = RunState.NotRunnable;
                suite.Properties.Set(PropertyNames.SkipReason, "Suite property must return either TestSuite or IEnumerable");
            }

            return(suite);
        }
Пример #2
0
        public Test BuildFrom(Type type)
        {
            TestSuite suite = new LegacySuite(type);

            string reason = null;

            if (!IsValidFixtureType(type, ref reason))
            {
                suite.RunState     = RunState.NotRunnable;
                suite.IgnoreReason = reason;
            }

            PropertyInfo suiteProperty = GetSuiteProperty(type);
            MethodInfo   method        = suiteProperty.GetGetMethod(true);

            if (method.GetParameters().Length > 0)
            {
                suite.RunState     = RunState.NotRunnable;
                suite.IgnoreReason = "Suite property may not be indexed";
            }
            else if (method.ReturnType.FullName == "NUnit.Core.TestSuite")
            {
                TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
                foreach (Test test in s.Tests)
                {
                    suite.Add(test);
                }
            }
            else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType))
            {
                foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0]))
                {
                    Type objType = obj as Type;
                    if (objType != null && TestFixtureBuilder.CanBuildFrom(objType))
                    {
                        suite.Add(TestFixtureBuilder.BuildFrom(objType));
                    }
                    else
                    {
                        suite.Add(obj);
                    }
                }
            }
            else
            {
                suite.RunState     = RunState.NotRunnable;
                suite.IgnoreReason = "Suite property must return either TestSuite or IEnumerable";
            }

            return(suite);
        }
Пример #3
0
		public Test BuildFrom( Type type )
		{
            TestSuite suite = new LegacySuite( type );

            string reason = null;
            if (!IsValidFixtureType(type, ref reason))
            {
                suite.RunState = RunState.NotRunnable;
                suite.IgnoreReason = reason;
            }

            PropertyInfo suiteProperty = GetSuiteProperty(type);
            MethodInfo method = suiteProperty.GetGetMethod(true);

            if (method.GetParameters().Length > 0)
            {
                suite.RunState = RunState.NotRunnable;
                suite.IgnoreReason = "Suite property may not be indexed";
            }
            else if (method.ReturnType.FullName == "NUnit.Core.TestSuite")
            {
                TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
                foreach (Test test in s.Tests)
                    suite.Add(test);
            }
            else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType))
            {
                foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0]))
                {
                    Type objType = obj as Type;
                    if (objType != null && TestFixtureBuilder.CanBuildFrom(objType))
                        suite.Add(TestFixtureBuilder.BuildFrom(objType));
                    else
                        suite.Add(obj);
                }
            }
            else
            {
                suite.RunState = RunState.NotRunnable;
                suite.IgnoreReason = "Suite property must return either TestSuite or IEnumerable";
            }

            return suite;
        }
        /// <summary>
        /// Build a TestSuite from type provided.
        /// </summary>
        /// <param name="type">The type of the fixture to be used</param>
        /// <returns>A TestSuite</returns>
        public Test BuildFrom( Type type )
        {
            TestSuite suite = new LegacySuite( type );

            if (suite.RunState == RunState.NotRunnable)
            {
                string reason = null;
                if (!IsValidFixtureType(type, ref reason))
                {
                    suite.RunState = RunState.NotRunnable;
                    suite.Properties.Set(PropertyNames.SkipReason, reason);
                }
            }

            PropertyInfo suiteProperty = GetSuiteProperty(type);
            MethodInfo method = suiteProperty.GetGetMethod(true);

            if (method.GetParameters().Length > 0)
            {
                suite.RunState = RunState.NotRunnable;
                suite.Properties.Set(PropertyNames.SkipReason, "Suite property may not be indexed");
            }
            // TODO: Stop checking for name
            else if (method.ReturnType.FullName == "NUnit.Framework.Internal.TestSuite")
            {
                TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
                foreach (Test test in s.Tests)
                    suite.Add(test);
            }
            else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType))
            {
                foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0]))
                {
                    Type objType = obj as Type;
                    if (objType != null && _defaultSuiteBuilder.CanBuildFrom(objType))
                        suite.Add(_defaultSuiteBuilder.BuildFrom(objType));
                    else
                    {
                        var fixture = _defaultSuiteBuilder.BuildFrom(obj.GetType());
                        if (fixture != null)
                            fixture.Fixture = obj;
                        suite.Add(fixture);
                    }
                }
            }
            else
            {
                suite.RunState = RunState.NotRunnable;
                suite.Properties.Set(PropertyNames.SkipReason, "Suite property must return either TestSuite or IEnumerable");
            }

            return suite;
        }