Beispiel #1
0
        private IList <ITest> CreateTests([NotNull] IOpenDataset datasetContext,
                                          [NotNull] IList <TestParameter> testParameters)
        {
            Assert.ArgumentNotNull(datasetContext, nameof(datasetContext));
            Assert.ArgumentNotNull(testParameters, nameof(testParameters));

            try
            {
                List <TableConstraint> sortedTableParameters;
                object[] constructorArguments = Args(datasetContext,
                                                     testParameters,
                                                     out sortedTableParameters);

                IList <ITest> tests = CreateTestInstances(constructorArguments);

                foreach (ITest test in tests)
                {
                    ApplyTableParameters(test, sortedTableParameters);
                }

                // apply non-constructor arguments
                foreach (TestParameter parameter in testParameters.Where(
                             p => !p.IsConstructorParameter))
                {
                    object value;
                    if (!TryGetArgumentValue(parameter, datasetContext, out value,
                                             out List <TableConstraint> tableConstraints))
                    {
                        // TODO apply the defined DefaultValue?
                        continue;
                    }

                    foreach (ITest test in tests)
                    {
                        int preInvolvedTablesCount = test.InvolvedTables.Count;
                        SetPropertyValue(test, parameter, value);
                        SetNonConstructorConstraints(test, preInvolvedTablesCount,
                                                     tableConstraints);
                    }
                }

                return(tests);
            }
            catch (Exception e)
            {
                QualityCondition condition = Condition;
                if (condition == null)
                {
                    throw new AssertionException(
                              "Unable to create test for undefined condition", e);
                }

                var sb = new StringBuilder();

                sb.AppendFormat("Unable to create test(s) for quality condition {0}",
                                condition.Name);
                sb.AppendLine();
                sb.AppendLine("with parameters:");

                foreach (TestParameterValue value in condition.ParameterValues)
                {
                    string stringValue;
                    try
                    {
                        stringValue = value.StringValue;
                    }
                    catch (Exception e1)
                    {
                        _msg.Debug(
                            string.Format(
                                "Error getting string value for parameter {0} of condition {1}",
                                value.TestParameterName,
                                condition.Name),
                            e1);

                        stringValue = $"<error: {e1.Message} (see log for details)>";
                    }

                    sb.AppendFormat("  {0} : {1}", value.TestParameterName, stringValue);
                    sb.AppendLine();
                }

                sb.AppendFormat("error message: {0}",
                                ExceptionUtils.GetInnermostMessage(e));
                sb.AppendLine();

                throw new InvalidOperationException(sb.ToString(), e);
            }
        }