Пример #1
0
        public void ParsesToCorrectType(string input, Type expected)
        {
            // Act
            var asts = QueryexBase.Parse(input);

            // Assert
            var actual = Assert.Single(asts);

            Assert.IsType(expected, actual);
        }
Пример #2
0
        /// <summary>
        /// Parses a string representing an expand argument into an <see cref="ExpressionExpand"/>.
        /// The expand argument is a comma separated list of column accesses.
        /// For example "Participant,Lines.Entries"
        /// </summary>
        public static ExpressionExpand Parse(string expand)
        {
            if (string.IsNullOrWhiteSpace(expand))
            {
                return(null);
            }

            var expressions     = QueryexBase.Parse(expand, expectPathsOnly: true);
            var nonColumnAccess = expressions.FirstOrDefault(e => !(e is QueryexColumnAccess));

            if (nonColumnAccess != null)
            {
                throw new QueryException($"Expand parameter cannot contain an expression like {nonColumnAccess}, only column access expressions are allowed.");
            }

            return(new ExpressionExpand(expressions.Cast <QueryexColumnAccess>()));
        }
Пример #3
0
        /// <summary>
        /// Parses a string representing a select argument into an <see cref="ExpressionSelect"/>.
        /// The select argument is a comma separated list of column accesses.
        /// For example: "Line.PostingDate,Value"
        /// </summary>
        public static ExpressionSelect Parse(string select)
        {
            if (string.IsNullOrWhiteSpace(select))
            {
                return(null);
            }

            var expressions     = QueryexBase.Parse(select);
            var nonColumnAccess = expressions.FirstOrDefault(e => e is not QueryexColumnAccess);

            if (nonColumnAccess != null)
            {
                throw new QueryException($"Select parameter cannot contain an expression like {nonColumnAccess}, only column access expressions are allowed.");
            }

            return(new ExpressionSelect(expressions.Cast <QueryexColumnAccess>()));
        }
Пример #4
0
        /// <summary>
        /// Parses a string representing a filter argument into a <see cref="ExpressionFilter"/>. 
        /// The syntax is anything that can be compiled by <see cref="QueryexBase"/> into a single boolean expression.
        /// For example: "(Value * Direction > 1000) and (Agent.Lookup1.Code = 'M')".
        /// </summary>
        public static ExpressionFilter Parse(string filter)
        {
            var expressions = QueryexBase.Parse(filter);

            // Can only contain 0 or 1 atoms
            if (expressions.Skip(1).Any())
            {
                throw new InvalidOperationException("Filter parameter must contain a single expression without top level commas.");
            }

            var filterExpression = expressions.FirstOrDefault();
            if (filterExpression == null)
            {
                return null;
            }

            return new ExpressionFilter(filterExpression);
        }
Пример #5
0
        /// <summary>
        /// Parses a string representing a filter argument into a <see cref="ExpressionHaving"/>.
        /// The filter argument is a boolean expression. The syntax is anything that can be compiled by
        /// <see cref="QueryexBase"/> into a single boolean expression where every column access is contained within an aggregation.
        /// For example: "SUM(Value * Direction) > 1000 and Max(Participant.Lookup1.Code) = 'M'".
        /// </summary>
        public static ExpressionHaving Parse(string having)
        {
            var expressions = QueryexBase.Parse(having);

            // Can only contain 0 or 1 atoms
            if (expressions.Skip(1).Any())
            {
                throw new InvalidOperationException("Having parameter must contain a single expression without top level commas.");
            }

            var havingExpression = expressions.FirstOrDefault();

            if (havingExpression == null)
            {
                return(null);
            }

            return(new ExpressionHaving(havingExpression));
        }