Exemplo n.º 1
0
        /// <summary>
        /// Builds the set up tear down list.
        /// </summary>
        /// <param name="setUpMethods">Unsorted array of setup MethodInfos.</param>
        /// <param name="tearDownMethods">Unsorted array of teardown MethodInfos.</param>
        /// <param name="methodValidator">Method validator used before each method execution.</param>
        /// <returns>A list of SetUpTearDownItems</returns>
        protected List <SetUpTearDownItem> BuildSetUpTearDownList(
            IMethodInfo[] setUpMethods,
            IMethodInfo[] tearDownMethods,
            IMethodValidator methodValidator = null)
        {
            Guard.ArgumentNotNull(setUpMethods, nameof(setUpMethods));
            Guard.ArgumentNotNull(tearDownMethods, nameof(tearDownMethods));

            var list = new List <SetUpTearDownItem>();

            Type fixtureType = Test.TypeInfo?.Type;

            if (fixtureType == null)
            {
                return(list);
            }

            while (fixtureType != null && fixtureType != typeof(object))
            {
                var node = BuildNode(fixtureType, setUpMethods, tearDownMethods, methodValidator);
                if (node.HasMethods)
                {
                    list.Add(node);
                }

                fixtureType = fixtureType.GetTypeInfo().BaseType;
            }

            return(list);
        }
Exemplo n.º 2
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="propertyProvider"></param>
 /// <param name="propertyValidator"></param>
 /// <param name="methodProvider"></param>
 /// <param name="methodValidator"></param>
 public ObjectValidator(IPropertyProvider propertyProvider, IPropertyValidator propertyValidator, IMethodProvider methodProvider, IMethodValidator methodValidator)
 {
     this.propertyProvider  = propertyProvider;
     this.propertyValidator = propertyValidator;
     this.methodProvider    = methodProvider;
     this.methodValidator   = methodValidator;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Construct a SetUpTearDownNode
 /// </summary>
 /// <param name="setUpMethods">A list of setup methods for this level</param>
 /// <param name="tearDownMethods">A list teardown methods for this level</param>
 /// <param name="methodValidator">A method validator to validate each method before calling.</param>
 public SetUpTearDownItem(
     IList <IMethodInfo> setUpMethods,
     IList <IMethodInfo> tearDownMethods,
     IMethodValidator methodValidator = null)
 {
     _setUpMethods    = setUpMethods;
     _tearDownMethods = tearDownMethods;
     _methodValidator = methodValidator;
 }
Exemplo n.º 4
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 SetUpTearDownItem BuildNode(
            Type fixtureType,
            IList <IMethodInfo> setUpMethods,
            IList <IMethodInfo> tearDownMethods,
            IMethodValidator methodValidator)
        {
            // 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);

            return(new SetUpTearDownItem(mySetUpMethods, myTearDownMethods, methodValidator));
        }
Exemplo n.º 5
0
 public MethodValidatorTests()
 {
     sut = new DefaultMethodValidator();
 }