/// <summary>
        /// Initializes a new instance of the <see cref="MethodInvoker"/> class with the supplied
        /// <see cref="IMethodQuery" />.
        /// </summary>
        /// <param name="query">
        /// The <see cref="IMethodQuery"/> that defines which methods are attempted.
        /// </param>
        public MethodInvoker(IMethodQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            this.query = query;
        }
Example #2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ConstructorCustomization"/> class.
            /// </summary>
            /// <param name="targetType">
            /// The <see cref="Type"/> for which <paramref name="query"/> should be used to select the
            /// most appropriate constructor.
            /// </param>
            /// <param name="query">
            /// The query that selects a constructor for <paramref name="targetType"/>.
            /// </param>
            public ConstructorCustomization(Type targetType, IMethodQuery query)
            {
                if (targetType == null)
                    throw new ArgumentNullException("targetType");

                if (query == null)
                    throw new ArgumentNullException("query");

                this.targetType = targetType;
                this.query = query;
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConstructorCustomization"/> class.
        /// </summary>
        /// <param name="targetType">
        /// The <see cref="Type"/> for which <paramref name="query"/> should be used to select the
        /// most appropriate constructor.
        /// </param>
        /// <param name="query">
        /// The query that selects a constructor for <paramref name="targetType"/>.
        /// </param>
        public ConstructorCustomization(Type targetType, IMethodQuery query)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException(nameof(targetType));
            }
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            this.targetType = targetType;
            this.query = query;
        }
 public void QueriesWillMatchParamsArray()
 {
     // Fixture setup
     var expectedQueries = new IMethodQuery[]
     {
         new DelegatingMethodQuery(),
         new DelegatingMethodQuery(),
         new DelegatingMethodQuery()
     };
     var sut = new CompositeMethodQuery(expectedQueries);
     // Exercise system
     var result = sut.Queries;
     // Verify outcome
     Assert.True(expectedQueries.SequenceEqual(result));
     // Teardown
 }
        public void SelectWillReturnResultsInCorrectSequence(Type type)
        {
            // Fixture setup
            IEnumerable<IMethod> modestConstructors = from ci in type.GetConstructors()
                                                      let parameters = ci.GetParameters()
                                                      orderby parameters.Length ascending
                                                      select new ConstructorMethod(ci) as IMethod;

            IEnumerable<IMethod> greedyConstructors = from ci in type.GetConstructors()
                                                      let parameters = ci.GetParameters()
                                                      orderby parameters.Length descending
                                                      select new ConstructorMethod(ci) as IMethod;

            var expectedConstructors = new List<IMethod>();
            expectedConstructors.AddRange(modestConstructors);
            expectedConstructors.AddRange(greedyConstructors);

            var queries = new IMethodQuery[]
            {
                new DelegatingMethodQuery { OnSelectMethods = t => modestConstructors },
                new DelegatingMethodQuery { OnSelectMethods = t => greedyConstructors },
                new DelegatingMethodQuery()
            };

            var sut = new CompositeMethodQuery(queries);
            // Exercise system
            var result = sut.SelectMethods(type);
            // Verify outcome
            Assert.True(expectedConstructors.SequenceEqual(result));
            // Teardown
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NoConstructorsSpecification"/> class.
 /// </summary>
 public NoConstructorsSpecification()
 {
     modestConstructorQuery = new ModestConstructorQuery();
 }