示例#1
0
        private string?BuildPredicate(QueryArgumentInfo info, object value)
        {
            if (info.EntityPath == null)
            {
                return(null);
            }

            var predicates = new List <(string propertyPath, string @operator, object propertyValue)>();

            if (info?.QueryArgument?.Type == typeof(DateGraphType) && value is DateTime date)
            {
                predicates.Add((info.EntityPath, Operators.GreaterThanEqual, date));
                predicates.Add((info.EntityPath, Operators.LessThan, date.AddDays(1)));
            }
            else
            {
                predicates.Add((info.EntityPath, Operators.Equal, value));
            }

            return(string.Join($" {Operators.And} ", predicates.Select(p =>
            {
                string wrap = info.IsNonNullGraphType ? p.propertyPath : $"np({p.propertyPath})";
                return $"({wrap} {p.@operator} \"{p.propertyValue}\")";
            })));
        }
        private static string BuildPredicate(QueryArgumentInfo info, object value)
        {
            if (info.QueryArgument.Type == typeof(DateGraphType) && value is DateTime date)
            {
                return($"np({info.EntityPropertyPath}) >= \"{date}\" && np({info.EntityPropertyPath}) < \"{date.AddDays(1)}\"");
            }

            return($"np({info.EntityPropertyPath}) == \"{value}\"");
        }
示例#3
0
        public void Include_ShouldKeepArgumentInList()
        {
            // Arrange
            var infoId = new QueryArgumentInfo
            {
                QueryArgumentInfoType = QueryArgumentInfoType.GraphQL,
                QueryArgument         = new QueryArgument(typeof(IntGraphType))
                {
                    Name = "Id"
                },
                IsNonNullGraphType = true,
                GraphQLPath        = "Id",
                EntityPath         = new List <string> {
                    "Id"
                }
            };

            _sut.Add(infoId);
            var infoX = new QueryArgumentInfo
            {
                QueryArgumentInfoType = QueryArgumentInfoType.GraphQL,
                QueryArgument         = new QueryArgument(typeof(IntGraphType))
                {
                    Name = "X"
                },
                IsNonNullGraphType = true,
                GraphQLPath        = "X",
                EntityPath         = new List <string> {
                    "X"
                }
            };

            _sut.Add(infoX);

            // Act
            var list = _sut.Include("Id");

            // Assert
            list.Count.Should().Be(1);
            list[0].Should().Be(infoId);
        }
        private (string Text, object[] Values)? BuildPredicate(QueryArgumentInfo info, object value, PlaceHolderCounter counter)
        {
            if (info.EntityPath == null)
            {
                return(null);
            }

            var values     = new List <object>();
            var predicates = new List <(string @operator, string placeHolder)>();

            if (info.QueryArgument?.Type == typeof(DateGraphType) && value is DateTime date)
            {
                predicates.Add((Operators.GreaterThanEqual, $"@{counter.GetNew()}"));
                predicates.Add((Operators.LessThan, $"@{counter.GetNew()}"));

                values.Add(date);
                values.Add(date.AddDays(1));
            }
            else
            {
                predicates.Add((Operators.Equal, $"@{counter.GetNew()}"));
                values.Add(value);
            }

            var text = string.Join($" {Operators.And} ", predicates.Select(p =>
            {
                if (!info.ParentGraphType.IsListGraphType())
                {
                    string path = string.Join(".", info.EntityPath);
                    string wrap = info.IsNonNullGraphType ? path : $"np({path})";
                    return($"({wrap} {p.@operator} {p.placeHolder})");
                }

                var theRest = string.Join(".", info.EntityPath.Skip(1));
                return($"({info.EntityPath[0]} != null ? {info.EntityPath[0]}.Any({theRest} {p.@operator} {p.placeHolder}) : false)");
            }));

            return(text, values.ToArray());
        }
 private static string BuildSelection(QueryArgumentInfo info)
 {
     return(null);
 }