public DatasetConstraintConfigurator(
            [NotNull] IEnumerable <TestParameterValue> parameterValues)
        {
            Assert.ArgumentNotNull(parameterValues, nameof(parameterValues));

            var constraints = new List <string>();

            foreach (TestParameterValue value in parameterValues)
            {
                if (Equals(value.TestParameterName, QaDatasetConstraintFactory.TableAttribute))
                {
                    Assert.Null(Dataset,
                                "Multiple Attribute " +
                                QaDatasetConstraintFactory.TableAttribute);

                    Dataset = (ObjectDataset)((DatasetTestParameterValue)value).DatasetValue;
                }
                else if (Equals(value.TestParameterName,
                                QaDatasetConstraintFactory.ConstraintAttribute))
                {
                    constraints.Add(value.StringValue);
                }
                else
                {
                    Assert.False(true, "Unexpected attribute");
                }
            }

            Assert.NotNull(Dataset,
                           "Missing Attribute: {0}", QaDatasetConstraintFactory.TableAttribute);

            Constraints = HierarchicalConstraintUtils.GetConstraintHierarchy(constraints);
        }
        protected override object[] Args(
            IOpenDataset datasetContext,
            IList <TestParameter> testParameters,
            out List <TableConstraint> tableParameters)
        {
            object[] objParams = base.Args(datasetContext, testParameters, out tableParameters);
            if (objParams.Length != 2)
            {
                throw new ArgumentException(string.Format("expected 2 parameter, got {0}",
                                                          objParams.Length));
            }

            if (objParams[0] is ITable == false)
            {
                throw new ArgumentException(string.Format("expected ITable, got {0}",
                                                          objParams[0].GetType()));
            }

            if (objParams[1] as IList <string> == null)
            {
                throw new ArgumentException(string.Format("expected IList<string>, got {0}",
                                                          objParams[1].GetType()));
            }

            var objects = new object[2];

            IList <ConstraintNode> nodes =
                HierarchicalConstraintUtils.GetConstraintHierarchy((IList <string>)objParams[1]);

            objects[0] = objParams[0];
            objects[1] = nodes;

            return(objects);
        }
Example #3
0
        protected override object[] Args(IOpenDataset datasetContext,
                                         IList <TestParameter> testParameters,
                                         out List <TableConstraint> tableParameters)
        {
            object[] objParams = base.Args(datasetContext, testParameters, out tableParameters);

            if (objParams.Length != 4)
            {
                throw new ArgumentException(string.Format("expected 4 parameters, got {0}",
                                                          objParams.Length));
            }

            if (!(objParams[0] is IList <ITable>))
            {
                throw new ArgumentException(string.Format("expected IList<ITable>, got {0}",
                                                          objParams[0].GetType()));
            }

            if (!(objParams[1] is string))
            {
                throw new ArgumentException(
                          string.Format("expected string (for relation), got {0}",
                                        objParams[1].GetType()));
            }

            if (objParams[2].GetType() != typeof(JoinType))
            {
                throw new ArgumentException(string.Format("expected JoinType, got {0}",
                                                          objParams[2].GetType()));
            }

            if (!(objParams[3] is IList <string>))
            {
                throw new ArgumentException(string.Format("expected IList<string>, got {0}",
                                                          objParams[3].GetType()));
            }

            var objects = new object[3];

            var tables          = (IList <ITable>)objParams[0];
            var associationName = (string)objParams[1];
            var join            = (JoinType)objParams[2];
            var constraints     = (IList <string>)objParams[3];

            bool applyFilterInDatabase = GetParameterValue <bool>(testParameters,
                                                                  datasetContext,
                                                                  _parameterNameApplyFilterInDatabase);

            bool   useCaseSensitiveQaSql;
            string tableConstraint = CombineTableParameters(tableParameters,
                                                            out useCaseSensitiveQaSql);

            string whereClause = applyFilterInDatabase ? tableConstraint : null;

            ITable queryTable = CreateQueryTable(datasetContext, associationName, tables, join,
                                                 whereClause, out string relationshipClassName);

            IList <string> translatedConstraints = TranslateConstraints(
                constraints,
                associationName, relationshipClassName,
                Assert.NotNull(Condition).ParameterValues.OfType <DatasetTestParameterValue>(),
                datasetContext);

            // assign objects[]
            IList <ConstraintNode> nodes =
                HierarchicalConstraintUtils.GetConstraintHierarchy(translatedConstraints);

            objects[0] = queryTable;
            objects[1] = nodes;
            objects[2] = tables;

            tableParameters = applyFilterInDatabase
                                                  ? new List <TableConstraint>()
                                                  : new List <TableConstraint>
            {
                new TableConstraint(queryTable, tableConstraint,
                                    useCaseSensitiveQaSql)
            };

            return(objects);
        }