/// <inheritdoc />
 public override IList <TestPart> GetTestParts(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     return(new[] { new TestPart()
                    {
                        IsTestContainer = true
                    } });
 }
 public override IList <TestPart> GetTestParts(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     if (IsTest(evaluator, codeElement))
     {
         return(base.GetTestParts(evaluator, codeElement));
     }
     return(EmptyArray <TestPart> .Instance);
 }
        private void InitializeExplorerIfNeeded(IReflectionPolicy reflectionPolicy)
        {
            if (testModelBuilder != null)
            {
                return;
            }

            testModelBuilder = new DefaultTestModelBuilder(reflectionPolicy, (PatternTestModel)TestModel);
            evaluator        = new DefaultPatternEvaluator(testModelBuilder, DeclarativePatternResolver.Instance);
        }
 private static bool HasCodeElementWithPattern <T>(IPatternEvaluator evaluator, IEnumerable <T> elements)
     where T : ICodeElementInfo
 {
     foreach (T element in elements)
     {
         if (evaluator.HasPatterns(element))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Creates a new scope.
        /// </summary>
        /// <param name="evaluator">The pattern evaluator.</param>
        /// <param name="codeElement">The code element associated with the scope, or null if none.</param>
        /// <param name="testBuilder">The test builder in scope.</param>
        /// <param name="testParameterBuilder">The test parameter builder in scope, or null if none.</param>
        /// <param name="testDataContextBuilder">The test data context builder.</param>
        /// <param name="isDeclaration">True if the scope represents the initial point of declaration
        /// of a given test component.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="evaluator"/>,
        /// <paramref name="testBuilder"/> or <paramref name="testDataContextBuilder"/> is null.</exception>
        public DefaultPatternScope(IPatternEvaluator evaluator, ICodeElementInfo codeElement,
            ITestBuilder testBuilder, ITestParameterBuilder testParameterBuilder,
            ITestDataContextBuilder testDataContextBuilder, bool isDeclaration)
        {
            if (evaluator == null)
                throw new ArgumentNullException("evaluator");
            if (testBuilder == null)
                throw new ArgumentNullException("testBuilder");
            if (testDataContextBuilder == null)
                throw new ArgumentNullException("testDataContextBuilder");

            this.evaluator = evaluator;
            this.codeElement = codeElement;
            this.testBuilder = testBuilder;
            this.testParameterBuilder = testParameterBuilder;
            this.testDataContextBuilder = testDataContextBuilder;
            this.isDeclaration = isDeclaration;
        }
        /// <summary>
        /// Infers whether the type is a test type based on its structure.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Returns true if the type any associated patterns, if it has
        /// non-nested type members (subject to <see cref="GetMemberBindingFlags" />)
        /// with patterns, if it has generic parameters with patterns, or if any
        /// of its nested types satisfy the preceding rules.
        /// </para>
        /// </remarks>
        /// <param name="evaluator">The pattern evaluator.</param>
        /// <param name="type">The type.</param>
        /// <returns>True if the type is likely a test type.</returns>
        protected virtual bool InferTestType(IPatternEvaluator evaluator, ITypeInfo type)
        {
            if (evaluator.HasPatterns(type))
            {
                return(true);
            }

            BindingFlags bindingFlags = GetMemberBindingFlags(type);

            if (HasCodeElementWithPattern(evaluator, type.GetMethods(bindingFlags)) ||
                HasCodeElementWithPattern(evaluator, type.GetProperties(bindingFlags)) ||
                HasCodeElementWithPattern(evaluator, type.GetFields(bindingFlags)) ||
                HasCodeElementWithPattern(evaluator, type.GetEvents(bindingFlags)))
            {
                return(true);
            }

            if (type.IsGenericTypeDefinition && HasCodeElementWithPattern(evaluator, type.GenericArguments))
            {
                return(true);
            }

            if (ShouldConsumeConstructors(type) &&
                HasCodeElementWithPattern(evaluator, type.GetConstructors(ConstructorBindingFlags)))
            {
                return(true);
            }

            foreach (ITypeInfo nestedType in type.GetNestedTypes(NestedTypeBindingFlags))
            {
                if (InferTestType(evaluator, nestedType))
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Creates a new scope.
        /// </summary>
        /// <param name="evaluator">The pattern evaluator.</param>
        /// <param name="codeElement">The code element associated with the scope, or null if none.</param>
        /// <param name="testBuilder">The test builder in scope.</param>
        /// <param name="testParameterBuilder">The test parameter builder in scope, or null if none.</param>
        /// <param name="testDataContextBuilder">The test data context builder.</param>
        /// <param name="isDeclaration">True if the scope represents the initial point of declaration
        /// of a given test component.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="evaluator"/>,
        /// <paramref name="testBuilder"/> or <paramref name="testDataContextBuilder"/> is null.</exception>
        public DefaultPatternScope(IPatternEvaluator evaluator, ICodeElementInfo codeElement,
                                   ITestBuilder testBuilder, ITestParameterBuilder testParameterBuilder,
                                   ITestDataContextBuilder testDataContextBuilder, bool isDeclaration)
        {
            if (evaluator == null)
            {
                throw new ArgumentNullException("evaluator");
            }
            if (testBuilder == null)
            {
                throw new ArgumentNullException("testBuilder");
            }
            if (testDataContextBuilder == null)
            {
                throw new ArgumentNullException("testDataContextBuilder");
            }

            this.evaluator              = evaluator;
            this.codeElement            = codeElement;
            this.testBuilder            = testBuilder;
            this.testParameterBuilder   = testParameterBuilder;
            this.testDataContextBuilder = testDataContextBuilder;
            this.isDeclaration          = isDeclaration;
        }
            private bool IsTest(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
            {
                ITypeInfo type = codeElement as ITypeInfo;

                return(type != null && InferTestType(evaluator, type));
            }
Beispiel #9
0
 /// <inheritdoc />
 public virtual IList<TestPart> GetTestParts(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     return EmptyArray<TestPart>.Instance;
 }
 /// <inheritdoc />
 public override IList<TestPart> GetTestParts(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     return new[] { new TestPart() { IsTestContribution = true } };
 }
 private bool IsTestPart(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     return evaluator.HasPatterns(codeElement);
 }
 public override IList<TestPart> GetTestParts(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     if (IsTestPart(evaluator, codeElement))
         return base.GetTestParts(evaluator, codeElement);
     return EmptyArray<TestPart>.Instance;
 }
        private void InitializeExplorerIfNeeded(IReflectionPolicy reflectionPolicy)
        {
            if (testModelBuilder != null)
                return;

            testModelBuilder = new DefaultTestModelBuilder(reflectionPolicy, (PatternTestModel)TestModel);
            evaluator = new DefaultPatternEvaluator(testModelBuilder, DeclarativePatternResolver.Instance);
        }
Beispiel #14
0
 /// <inheritdoc />
 public virtual IList <TestPart> GetTestParts(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     return(EmptyArray <TestPart> .Instance);
 }
 private bool IsTestPart(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     return(evaluator.HasPatterns(codeElement));
 }