/// <summary>
        /// Initializes a test parameter after it has been added to the containing test.
        /// </summary>
        /// <param name="testParameterScope">The test parameter scope.</param>
        /// <param name="slot">The slot.</param>
        protected virtual void InitializeTestParameter(IPatternScope testParameterScope, ISlotInfo slot)
        {
            int index     = slot.Position;
            var parameter = slot as IParameterInfo;

            if (parameter != null)
            {
                // For generic methods, we offset the position of the parameter
                // by the number of generic method parameters.  That way
                // we can assign each parameter in the method a unique index
                // by reading all parameters left to right, starting with the
                // generic parameters and moving onwards to the method parameters.
                IMethodInfo method = parameter.Member as IMethodInfo;
                if (method != null && method.IsGenericMethodDefinition)
                {
                    index += method.GenericArguments.Count;
                }
            }
            testParameterScope.TestDataContextBuilder.ImplicitDataBindingIndexOffset = index;

            string xmlDocumentation = slot.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                testParameterScope.TestParameterBuilder.AddMetadata(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }

            testParameterScope.TestParameterBuilder.TestParameterActions.BindTestParameterChain.After((state, value) =>
            {
                state.SlotValues.Add(slot, value);
            });

            testParameterScope.Process(slot);
        }
        /// <summary>
        /// Initializes a test for a contract verifier field after it has been added to the test model.
        /// </summary>
        /// <param name="fieldScope">The field scope.</param>
        /// <param name="field">The field.</param>
        protected virtual void InitializeTest(IPatternScope fieldScope, IFieldInfo field)
        {
            string xmlDocumentation = field.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                fieldScope.TestBuilder.AddMetadata(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }

            fieldScope.Process(field);
        }
示例#3
0
        /// <summary>
        /// Initializes a test for an assembly after it has been added to the test model.
        /// </summary>
        /// <param name="assemblyScope">The assembly scope.</param>
        /// <param name="assembly">The assembly.</param>
        protected virtual void InitializeAssemblyTest(IPatternScope assemblyScope, IAssemblyInfo assembly)
        {
            var metadata = new PropertyBag();

            ModelUtils.PopulateMetadataFromAssembly(assembly, metadata);
            foreach (var pair in metadata.Pairs)
            {
                assemblyScope.TestBuilder.AddMetadata(pair.Key, pair.Value);
            }

            assemblyScope.Process(assembly);
        }
示例#4
0
        /// <summary>
        /// Initializes the <see cref="PatternTestDataContext" />.
        /// </summary>
        /// <param name="dataContextScope">The data context scope.</param>
        /// <param name="constructor">The constructor.</param>
        protected virtual void InitializeDataContext(IPatternScope dataContextScope, IConstructorInfo constructor)
        {
            ITypeInfo declaringType = constructor.DeclaringType;

            if (declaringType.IsGenericTypeDefinition)
            {
                dataContextScope.TestDataContextBuilder.ImplicitDataBindingIndexOffset = declaringType.GenericArguments.Count;
            }

            foreach (IParameterInfo parameter in constructor.Parameters)
            {
                dataContextScope.Consume(parameter, false, DefaultConstructorParameterPattern);
            }

            dataContextScope.Process(constructor);
        }
        /// <summary>
        /// Initializes a test for a type after it has been added to the test model.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The members of base types are processed before those of subtypes.
        /// </para>
        /// <para>
        /// The default implementation processes all public members of the type including
        /// the first constructor found, then recurses to process all public and non-public
        /// nested types.  Non-public members other than nested types are ignored.
        /// </para>
        /// </remarks>
        /// <param name="typeScope">The type scope.</param>
        /// <param name="type">The type.</param>
        protected virtual void InitializeTest(IPatternScope typeScope, ITypeInfo type)
        {
            string xmlDocumentation = type.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                typeScope.TestBuilder.AddMetadata(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }

            typeScope.Process(type);

            if (type.IsGenericTypeDefinition)
            {
                foreach (IGenericParameterInfo parameter in type.GenericArguments)
                {
                    typeScope.Consume(parameter, false, DefaultGenericParameterPattern);
                }
            }

            ConsumeMembers(typeScope, type);
            ConsumeConstructors(typeScope, type);
            ConsumeNestedTypes(typeScope, type);
        }
        /// <summary>
        /// Initializes a test for a method after it has been added to the test model.
        /// </summary>
        /// <param name="methodScope">The method scope.</param>
        /// <param name="method">The method.</param>
        protected virtual void InitializeTest(IPatternScope methodScope, IMethodInfo method)
        {
            string xmlDocumentation = method.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                methodScope.TestBuilder.AddMetadata(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }

            methodScope.Process(method);

            if (method.IsGenericMethodDefinition)
            {
                foreach (IGenericParameterInfo parameter in method.GenericArguments)
                {
                    methodScope.Consume(parameter, false, DefaultGenericParameterPattern);
                }
            }

            foreach (IParameterInfo parameter in method.Parameters)
            {
                methodScope.Consume(parameter, false, DefaultMethodParameterPattern);
            }
        }
        /// <summary>
        /// Initializes a test for a method after it has been added to the test model.
        /// </summary>
        /// <param name="methodScope">The method scope.</param>
        /// <param name="method">The method.</param>
        protected virtual void InitializeTest(IPatternScope methodScope, IMethodInfo method)
        {
            string xmlDocumentation = method.GetXmlDocumentation();
            if (xmlDocumentation != null)
                methodScope.TestBuilder.AddMetadata(MetadataKeys.XmlDocumentation, xmlDocumentation);

            methodScope.Process(method);

            if (method.IsGenericMethodDefinition)
            {
                foreach (IGenericParameterInfo parameter in method.GenericArguments)
                    methodScope.Consume(parameter, false, DefaultGenericParameterPattern);
            }

            foreach (IParameterInfo parameter in method.Parameters)
                methodScope.Consume(parameter, false, DefaultMethodParameterPattern);
        }
        /// <summary>
        /// Initializes a test parameter after it has been added to the containing test.
        /// </summary>
        /// <param name="testParameterScope">The test parameter scope.</param>
        /// <param name="slot">The slot.</param>
        protected virtual void InitializeTestParameter(IPatternScope testParameterScope, ISlotInfo slot)
        {
            int index = slot.Position;
            var parameter = slot as IParameterInfo;
            if (parameter != null)
            {
                // For generic methods, we offset the position of the parameter
                // by the number of generic method parameters.  That way
                // we can assign each parameter in the method a unique index
                // by reading all parameters left to right, starting with the
                // generic parameters and moving onwards to the method parameters.
                IMethodInfo method = parameter.Member as IMethodInfo;
                if (method != null && method.IsGenericMethodDefinition)
                    index += method.GenericArguments.Count;
            }
            testParameterScope.TestDataContextBuilder.ImplicitDataBindingIndexOffset = index;

            string xmlDocumentation = slot.GetXmlDocumentation();
            if (xmlDocumentation != null)
                testParameterScope.TestParameterBuilder.AddMetadata(MetadataKeys.XmlDocumentation, xmlDocumentation);

            testParameterScope.TestParameterBuilder.TestParameterActions.BindTestParameterChain.After((state, value) =>
            {
                state.SlotValues.Add(slot, value);
            });

            testParameterScope.Process(slot);
        }
        /// <summary>
        /// Initializes a test for a contract verifier field after it has been added to the test model.
        /// </summary>
        /// <param name="fieldScope">The field scope.</param>
        /// <param name="field">The field.</param>
        protected virtual void InitializeTest(IPatternScope fieldScope, IFieldInfo field)
        {
            string xmlDocumentation = field.GetXmlDocumentation();
            if (xmlDocumentation != null)
                fieldScope.TestBuilder.AddMetadata(MetadataKeys.XmlDocumentation, xmlDocumentation);

            fieldScope.Process(field);
        }
        /// <summary>
        /// Initializes the <see cref="PatternTestDataContext" />.
        /// </summary>
        /// <param name="dataContextScope">The data context scope.</param>
        /// <param name="constructor">The constructor.</param>
        protected virtual void InitializeDataContext(IPatternScope dataContextScope, IConstructorInfo constructor)
        {
            ITypeInfo declaringType = constructor.DeclaringType;
            if (declaringType.IsGenericTypeDefinition)
                dataContextScope.TestDataContextBuilder.ImplicitDataBindingIndexOffset = declaringType.GenericArguments.Count;

            foreach (IParameterInfo parameter in constructor.Parameters)
                dataContextScope.Consume(parameter, false, DefaultConstructorParameterPattern);

            dataContextScope.Process(constructor);
        }
        /// <summary>
        /// Initializes a test for an assembly after it has been added to the test model.
        /// </summary>
        /// <param name="assemblyScope">The assembly scope.</param>
        /// <param name="assembly">The assembly.</param>
        protected virtual void InitializeAssemblyTest(IPatternScope assemblyScope, IAssemblyInfo assembly)
        {
            var metadata = new PropertyBag();
            ModelUtils.PopulateMetadataFromAssembly(assembly, metadata);
            foreach (var pair in metadata.Pairs)
                assemblyScope.TestBuilder.AddMetadata(pair.Key, pair.Value);

            assemblyScope.Process(assembly);
        }