Exemplo n.º 1
0
        protected static void AddConstructorParameters(
            [NotNull] List <TestParameter> parameters,
            [NotNull] Type qaTestType,
            int constructorIndex,
            [NotNull] IList <int> ignoreParameters)
        {
            ConstructorInfo constr = qaTestType.GetConstructors()[constructorIndex];

            IList <ParameterInfo> constrParams = constr.GetParameters();

            for (var iParam = 0; iParam < constrParams.Count; iParam++)
            {
                if (ignoreParameters.Contains(iParam))
                {
                    continue;
                }

                ParameterInfo constrParam = constrParams[iParam];

                var testParameter = new TestParameter(
                    constrParam.Name, constrParam.ParameterType,
                    TestImplementationUtils.GetDescription(constrParam),
                    isConstructorParameter: true);

                parameters.Add(testParameter);
            }
        }
Exemplo n.º 2
0
        public override 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);
        }
Exemplo n.º 3
0
        private void BindTo([NotNull] TestDescriptor testDescriptor)
        {
            _textBoxName.Text           = testDescriptor.Name;
            _textBoxImplementation.Text = GetImplementation(testDescriptor);

            var testImplementationInfo =
                TestImplementationUtils.GetTestImplementationInfo(testDescriptor);

            _textBoxTestDescription.Text = testImplementationInfo == null
                                                               ? string.Empty
                                                               : testImplementationInfo.GetTestDescription();

            _textBoxCategories.Text = testImplementationInfo == null
                                                          ? string.Empty
                                                          : StringUtils.ConcatenateSorted(
                testImplementationInfo.TestCategories,
                ", ");
            try
            {
                _textBoxSignature.Text = testImplementationInfo == null
                                                                 ? "Unable to create test signature"
                                                                 : TestImplementationUtils.GetTestSignature(
                    testImplementationInfo);
            }
            catch (Exception e)
            {
                _textBoxSignature.Text = string.Format("Unable to get test signature ({0})",
                                                       e.Message);
            }
        }
Exemplo n.º 4
0
        private static string GetDescription([NotNull] QualityCondition condition)
        {
            string description;

            if (string.IsNullOrEmpty(condition.Description))
            {
                TestDescriptor testDescriptor = condition.TestDescriptor;

                ITestImplementationInfo testImplementationInfo =
                    testDescriptor == null
                                                ? null
                                                : TestImplementationUtils.GetTestImplementationInfo(testDescriptor);

                description = testImplementationInfo == null
                                                      ? string.Empty
                                                      : testImplementationInfo.GetTestDescription();
            }
            else
            {
                description = condition.Description;
            }

            if (description == null)
            {
                return(string.Empty);
            }

            description = description.Replace("\r", string.Empty);
            description = description.Replace("\n", Environment.NewLine);

            return(description);
        }
Exemplo n.º 5
0
 internal HtmlTestParameter([NotNull] TestParameter testParameter)
 {
     Name        = testParameter.Name;
     Description = StringUtils.IsNotEmpty(testParameter.Description)
                                       ? testParameter.Description
                                       : null;
     Type = TestImplementationUtils.GetParameterTypeString(testParameter);
 }
Exemplo n.º 6
0
        private XmlElement GetSignatureRow([NotNull] TestFactory testFactory)
        {
            string signature = TestImplementationUtils.GetTestSignature(testFactory);

            XmlElement signatureRow = CreateTableRow();

            signatureRow.AppendChild(CreateTableCell("Signature:"));
            signatureRow.AppendChild(CreateTableCell(signature, 2, "code"));
            return(signatureRow);
        }
Exemplo n.º 7
0
        private string GetParameterDescription([CanBeNull] string parameterName)
        {
            if (parameterName == null || _testDescriptor == null)
            {
                return(null);
            }

            var testFactory = TestImplementationUtils.GetTestImplementationInfo(_testDescriptor);

            return(testFactory?.Parameters
                   .FirstOrDefault(x => x.Name == parameterName)
                   ?.Description);
        }
Exemplo n.º 8
0
        internal HtmlTestDescriptor([NotNull] TestDescriptor testDescriptor)
        {
            Assert.ArgumentNotNull(testDescriptor, nameof(testDescriptor));

            TestFactory testFactory =
                Assert.NotNull(TestDescriptorUtils.GetTestFactory(testDescriptor));

            Name        = testDescriptor.Name;
            Description = StringUtils.IsNotEmpty(testDescriptor.Description)
                                              ? testDescriptor.Description
                                              : null;

            TestDescription = testFactory.GetTestDescription();
            Signature       = TestImplementationUtils.GetTestSignature(testFactory);

            Type testType;

            if (testDescriptor.TestClass != null)
            {
                testType        = testDescriptor.TestClass.GetInstanceType();
                ConstructorId   = testDescriptor.TestConstructorId;
                UsesConstructor = true;
                IsObsolete      = TestDescriptorUtils.IsObsolete(testType, ConstructorId,
                                                                 out _obsoleteMessage);
            }
            else if (testDescriptor.TestFactoryDescriptor != null)
            {
                testType        = testDescriptor.TestFactoryDescriptor.GetInstanceType();
                ConstructorId   = -1;
                UsesConstructor = false;
                IsObsolete      = ReflectionUtils.IsObsolete(testType, out _obsoleteMessage);
            }
            else
            {
                throw new ArgumentException("Invalid test descriptor");
            }

            AssemblyName = Path.GetFileName(testType.Assembly.Location);
            ClassName    = testType.FullName;

            _issueCodes     = IssueCodeUtils.GetIssueCodes(testType).ToList();
            _testCategories = testFactory.TestCategories.OrderBy(c => c).ToList();

            foreach (TestParameter testParameter in testFactory.Parameters)
            {
                var htmlTestParameter = new HtmlTestParameter(testParameter);

                _parameters.Add(htmlTestParameter);
                _testParametersByName.Add(testParameter.Name, htmlTestParameter);
            }
        }
Exemplo n.º 9
0
        private IEnumerable <XmlElement> GetTestParameterRows([NotNull] IncludedTest test)
        {
            TestFactory testFactory = test.TestFactory;

            var rows = new List <XmlElement>();

            if (test is IncludedTestConstructor)
            {
                XmlElement signatureRow = GetSignatureRow(testFactory);
                rows.Add(signatureRow);
                rows.Add(GetTestDescriptionTextRow(test));
            }

            // create Html-Row for Parameter Description title
            XmlElement parameterHeadingRow = CreateTableRow();

            parameterHeadingRow.AppendChild(CreateTableCell("Parameter", "header"));
            parameterHeadingRow.AppendChild(CreateTableCell("Type", "header"));
            parameterHeadingRow.AppendChild(CreateTableCell("Description", "header"));
            rows.Add(parameterHeadingRow);

            foreach (TestParameter testParameter in testFactory.Parameters)
            {
                string parameterDescription =
                    test.TestFactory.GetParameterDescription(testParameter.Name);

                XmlElement parameterRow = CreateTableRow();
                rows.Add(parameterRow);

                parameterRow.AppendChild(CreateTableCell(testParameter.Name));
                parameterRow.AppendChild(
                    CreateTableCell(TestImplementationUtils.GetParameterTypeString(testParameter)));
                parameterRow.AppendChild(
                    CreateTableCell(parameterDescription ?? "<no description>"));
            }

            return(rows);
        }
Exemplo n.º 10
0
        protected static void AddOptionalTestParameters(
            [NotNull] List <TestParameter> parameters,
            [NotNull] Type qaTestType,
            [CanBeNull] IEnumerable <string> ignoredTestParameters = null,
            [CanBeNull] IEnumerable <string> additionalProperties  = null)
        {
            Dictionary <string, TestParameter> attributesByName =
                parameters.ToDictionary(parameter => parameter.Name);

            if (ignoredTestParameters != null)
            {
                foreach (string ignoreAttribute in ignoredTestParameters)
                {
                    attributesByName.Add(ignoreAttribute, null);
                }
            }

            HashSet <string> additionalPropertiesSet =
                additionalProperties != null
                                        ? new HashSet <string>(additionalProperties)
                                        : null;

            foreach (PropertyInfo property in qaTestType.GetProperties())
            {
                MethodInfo setMethod = property.GetSetMethod();

                if (setMethod == null || !setMethod.IsPublic)
                {
                    continue;
                }

                TestParameterAttribute testParameterAttribute = null;
                if (additionalPropertiesSet == null ||
                    !additionalPropertiesSet.Contains(property.Name))
                {
                    testParameterAttribute =
                        ReflectionUtils.GetAttribute <TestParameterAttribute>(property);

                    if (testParameterAttribute == null)
                    {
                        continue;
                    }
                }

                if (attributesByName.ContainsKey(property.Name))
                {
                    continue;
                }

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

                if (testParameterAttribute != null)
                {
                    testParameter.DefaultValue = testParameterAttribute.DefaultValue;
                }
                else
                {
                    object defaultValue;
                    if (ReflectionUtils.TryGetDefaultValue(property, out defaultValue))
                    {
                        testParameter.DefaultValue = defaultValue;
                    }
                }

                parameters.Add(testParameter);
                attributesByName.Add(property.Name, testParameter);
            }
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
0
        public override string GetTestDescription()
        {
            ConstructorInfo ctor = TestType.GetConstructors()[_constructorId];

            return(TestImplementationUtils.GetDescription(ctor));
        }