示例#1
0
        public string GetParameterDescription(string parameterName)
        {
            ConstructorInfo ctor = TestType.GetConstructors()[_constructorId];

            // TODO: revise, case-insensitive match is ok? (parameter name search is insensitive elsewhere)
            const StringComparison stringComparison = StringComparison.OrdinalIgnoreCase;

            foreach (ParameterInfo parameterInfo in ctor.GetParameters())
            {
                if (string.Equals(parameterInfo.Name, parameterName, stringComparison))
                {
                    return(TestImplementationUtils.GetDescription(parameterInfo));
                }
            }

            foreach (PropertyInfo propertyInfo in TestType.GetProperties())
            {
                if (string.Equals(propertyInfo.Name, parameterName, stringComparison))
                {
                    return(TestImplementationUtils.GetDescription(propertyInfo));
                }
            }

            return(null);
        }
示例#2
0
        public static IList <TestParameter> CreateParameters([NotNull] Type type,
                                                             int constructorId)
        {
            ConstructorInfo constr = type.GetConstructors()[constructorId];

            ParameterInfo[] constructorParameters = constr.GetParameters();
            PropertyInfo[]  properties            = type.GetProperties();

            var testParameterProperties =
                new Dictionary <PropertyInfo, TestParameterAttribute>();

            foreach (PropertyInfo propertyInfo in properties)
            {
                if (!propertyInfo.CanRead || !propertyInfo.CanWrite)
                {
                    continue;
                }

                var testParameterAttribute =
                    ReflectionUtils.GetAttribute <TestParameterAttribute>(
                        propertyInfo);

                if (testParameterAttribute == null)
                {
                    continue;
                }

                var isValid = true;
                foreach (ParameterInfo constructorParameter in constructorParameters)
                {
                    if (string.Equals(constructorParameter.Name, propertyInfo.Name,
                                      StringComparison.InvariantCultureIgnoreCase))
                    {
                        isValid = false;

                        _msg.Warn(GetMessageConstructorParameterExistsAlsoAsProperty(
                                      type, constructorId, constructorParameter));
                    }
                }

                if (isValid)
                {
                    testParameterProperties.Add(propertyInfo, testParameterAttribute);
                }
            }

            var testParameters =
                new List <TestParameter>(constructorParameters.Length +
                                         testParameterProperties.Count);

            foreach (ParameterInfo parameter in constructorParameters)
            {
                var testParameter = new TestParameter(
                    parameter.Name, parameter.ParameterType,
                    TestImplementationUtils.GetDescription(parameter),
                    isConstructorParameter: true);

                object defaultValue;
                if (ReflectionUtils.TryGetDefaultValue(parameter, out defaultValue))
                {
                    testParameter.DefaultValue = defaultValue;
                }

                testParameters.Add(testParameter);
            }

            foreach (KeyValuePair <PropertyInfo, TestParameterAttribute> pair in
                     testParameterProperties)
            {
                PropertyInfo           property  = pair.Key;
                TestParameterAttribute attribute = pair.Value;

                var testParameter = new TestParameter(
                    property.Name, property.PropertyType,
                    TestImplementationUtils.GetDescription(property),
                    isConstructorParameter: false);

                testParameter.DefaultValue = attribute.DefaultValue;

                testParameters.Add(testParameter);
            }

            return(new ReadOnlyList <TestParameter>(testParameters));
        }
示例#3
0
        public string GetTestDescription()
        {
            ConstructorInfo ctor = TestType.GetConstructors()[_constructorId];

            return(TestImplementationUtils.GetDescription(ctor));
        }