Ejemplo n.º 1
0
        // This method builds a list of nodes that can be used to
        // run setup and teardown according to the NUnit specs.
        // We need to execute setup and teardown methods one level
        // at a time. However, we can't discover them by reflection
        // one level at a time, because that would cause overridden
        // methods to be called twice, once on the base class and
        // once on the derived class.
        //
        // For that reason, we start with a list of all setup and
        // teardown methods, found using a single reflection call,
        // and then descend through the inheritance hierarchy,
        // adding each method to the appropriate level as we go.
        private static SetUpTearDownNode BuildList(Type fixtureType, IList <MethodInfo> setUpMethods, IList <MethodInfo> tearDownMethods)
        {
            // Create lists of methods for this level only.
            // Note that FindAll can't be used because it's not
            // available on all the platforms we support.
            var mySetUpMethods    = SelectMethodsByDeclaringType(fixtureType, setUpMethods);
            var myTearDownMethods = SelectMethodsByDeclaringType(fixtureType, tearDownMethods);

            var node = new SetUpTearDownNode(mySetUpMethods, myTearDownMethods);

            var baseType = fixtureType.BaseType;

            if (baseType != typeof(object) && baseType != null)
            {
                var next = BuildList(baseType, setUpMethods, tearDownMethods);
                if (next.HasMethods)
                {
                    if (!node.HasMethods)
                    {
                        return(next);
                    }
                }
                node.Next = next;
            }

            return(node);
        }
        /// <summary>
        /// Construct a SetUpTearDownList.
        /// </summary>
        /// <param name="fixtureType">The Type of the fixture to which the list applies</param>
        /// <param name="setUpType">The Type of the attribute used to mark setup methods</param>
        /// <param name="tearDownType">The Type of the attribute used to mark teardown methods</param>
        /// <returns></returns>
        public SetUpTearDownList(Type fixtureType, Type setUpType, Type tearDownType)
        {
            var setUpMethods = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true);
            var tearDownMethods = Reflect.GetMethodsWithAttribute(fixtureType, tearDownType, true);

            _topLevelNode = BuildList(fixtureType, setUpMethods, tearDownMethods);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Construct a SetUpTearDownList.
        /// </summary>
        /// <param name="fixtureType">The Type of the fixture to which the list applies</param>
        /// <param name="setUpType">The Type of the attribute used to mark setup methods</param>
        /// <param name="tearDownType">The Type of the attribute used to mark teardown methods</param>
        /// <returns></returns>
        public SetUpTearDownList(Type fixtureType, Type setUpType, Type tearDownType)
        {
            var setUpMethods    = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true);
            var tearDownMethods = Reflect.GetMethodsWithAttribute(fixtureType, tearDownType, true);

            _topLevelNode = BuildList(fixtureType, setUpMethods, tearDownMethods);
        }
        // This method builds a list of nodes that can be used to 
        // run setup and teardown according to the NUnit specs.
        // We need to execute setup and teardown methods one level
        // at a time. However, we can't discover them by reflection
        // one level at a time, because that would cause overridden
        // methods to be called twice, once on the base class and
        // once on the derived class.
        // 
        // For that reason, we start with a list of all setup and
        // teardown methods, found using a single reflection call,
        // and then descend through the inheritance hierarchy,
        // adding each method to the appropriate level as we go.
        private static SetUpTearDownNode BuildList(Type fixtureType, IList<MethodInfo> setUpMethods, IList<MethodInfo> tearDownMethods)
        {
            // Create lists of methods for this level only.
            // Note that FindAll can't be used because it's not
            // available on all the platforms we support.
            var mySetUpMethods = SelectMethodsByDeclaringType(fixtureType, setUpMethods);
            var myTearDownMethods = SelectMethodsByDeclaringType(fixtureType, tearDownMethods);

            var node = new SetUpTearDownNode(mySetUpMethods, myTearDownMethods);

            var baseType = fixtureType.BaseType;
            if (baseType != typeof(object) && baseType != null)
            {
                var next = BuildList(baseType, setUpMethods, tearDownMethods);
                if (next.HasMethods)
                    if (!node.HasMethods)
                        return next;
                node.Next = next;
            }

            return node;
        }