示例#1
0
        public void TranslateFilterShouldThrowExceptionIfOuterExpressionIsAndAlsoAndInnerRightExpressionIsNotABinaryExpression()
        {
            var testVariable = bool.Parse(bool.TrueString);
            var ex           = Assert.Throws <NotSupportedException>(() => FilterFormatters.TranslateFilter <Foo>(f => f.Prop2 == null && testVariable));

            Assert.IsTrue(ex.Message.StartsWith("This expression is not a binary expression:"));
        }
示例#2
0
        public void TranslateFilterShouldThrowExceptionForOrElseExpression()
        {
            var testVariable = bool.Parse(bool.TrueString);
            var ex           = Assert.Throws <NotSupportedException>(() => FilterFormatters.TranslateFilter <Foo>(f => f.Prop2 == null || testVariable));

            Assert.IsTrue(ex.Message.StartsWith("Oprerator OrElse is not yet supported."));
        }
示例#3
0
        public static IGremlinQuery OutE <TData>(this IGremlinQuery query, string label,
                                                 Expression <Func <TData, bool> > filter, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
            where TData : class, new()
        {
            IEnumerable <Filter> filters = FilterFormatters.TranslateFilter(filter);

            return(query.OutE(label, filters, comparison));
        }
示例#4
0
        public static IGremlinQuery In <TNode>(this IGremlinQuery query, string label,
                                               Expression <Func <TNode, bool> > filter, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
        {
            IGremlinQuery        newQuery    = query.AddBlock(IN, label);
            IEnumerable <Filter> filters     = FilterFormatters.TranslateFilter(filter);
            IGremlinQuery        filterQuery = newQuery.AddFilterBlock(string.Empty, filters, comparison);

            return(filterQuery);
        }
示例#5
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsConstantEnumExpression()
        {
            var filters = FilterFormatters
                          .TranslateFilter <NodeWithEnums>(f => f.Prop1 == EnumForTesting.Foo)
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual(EnumForTesting.Foo, filters.FirstOrDefault().Value);
        }
示例#6
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsNull()
        {
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(f => f.Prop1 == null)
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual(null, filters.FirstOrDefault().Value);
        }
示例#7
0
        public void TranslateFilterShouldResolvePropertiesEqualBoolean()
        {
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(f => f.Prop4 == true)
                          .OrderBy(f => f.PropertyName)
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop4", filters[0].PropertyName);
            Assert.AreEqual(true, filters[0].Value);
        }
示例#8
0
        public void TranslateFilterShouldResolveBooleanPropertyToDefaultToCompareToFalse()
        {
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(f => !f.Prop4)
                          .OrderBy(f => f.PropertyName)
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop4", filters[0].PropertyName);
            Assert.AreEqual(false, filters[0].Value);
        }
示例#9
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsLocalLongExpression()
        {
            var prop1Value = long.Parse("123"); // This must be a local - do not refactor this to a constant
            var filters    = FilterFormatters
                             .TranslateFilter <NodeWithLongs>(f => f.Prop1 == prop1Value)
                             .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual(123, filters.FirstOrDefault().Value);
        }
示例#10
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsConstantStringExpression()
        {
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(
                f => f.Prop1 == "abc"     // This must be a constant - do not refactor this line
                )
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual("abc", filters.FirstOrDefault().Value);
        }
示例#11
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsAStringFunctionExpression()
        {
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(
                f => f.Prop1 == string.Format("{0}.{1}", "abc", "def").ToUpperInvariant()     // This must be a method call - do not refactor this line
                )
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual("ABC.DEF", filters.FirstOrDefault().Value);
        }
示例#12
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsConstantLongMaxExpression()
        {
            var filters = FilterFormatters
                          .TranslateFilter <NodeWithLongs>(
                f => f.Prop1 == long.MaxValue     // This must be a constant - do not refactor this line
                )
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual(long.MaxValue, filters.FirstOrDefault().Value);
        }
示例#13
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsLocalStringExpression()
        {
            var prop1Value = new string(new[] { 'a', 'b', 'c' }); // This must be a local - do not refactor this to a constant
            var filters    = FilterFormatters
                             .TranslateFilter <Foo>(
                f => f.Prop1 == prop1Value
                )
                             .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual("abc", filters.FirstOrDefault().Value);
        }
示例#14
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsLocalLongMaxExpression()
        {
            var prop1Value = long.Parse(long.MaxValue.ToString(CultureInfo.InvariantCulture)); // This must be a local - do not refactor this to a constant
            var filters    = FilterFormatters
                             .TranslateFilter <NodeWithLongs>(
                f => f.Prop1 == prop1Value
                )
                             .ToArray();

            Assert.Equal(1, filters.Count());
            Assert.Equal("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.Equal(long.MaxValue, filters.FirstOrDefault().Value);
        }
示例#15
0
        public void TranslateFilterShouldResolveTwoPropertiesEqualNullWithBinaryAndAlso()
        {
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(f => f.Prop1 == null && f.Prop2 == null)
                          .OrderBy(f => f.PropertyName)
                          .ToArray();

            Assert.AreEqual(2, filters.Count());
            Assert.AreEqual("Prop1", filters[0].PropertyName);
            Assert.AreEqual(null, filters[0].Value);
            Assert.AreEqual("Prop2", filters[1].PropertyName);
            Assert.AreEqual(null, filters[1].Value);
        }
示例#16
0
        public void TranslateFilterShouldResolveSinglePropertyEqualsAnotherStringPropertyExpression()
        {
            var bar = new Bar {
                Prop1 = "def"
            };
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(
                f => f.Prop1 == bar.Prop1     // This must be a property get - do not refactor this line
                )
                          .ToArray();

            Assert.AreEqual(1, filters.Count());
            Assert.AreEqual("Prop1", filters.FirstOrDefault().PropertyName);
            Assert.AreEqual("def", filters.FirstOrDefault().Value);
        }
示例#17
0
        public void TranslateFilterShouldResolveThreePropertiesEqualOtherStringPropertiesInBooleanAndAlsoChain()
        {
            var bar = new Bar {
                Prop1 = "def", Prop2 = "ghi", Prop3 = "jkl"
            };
            var filters = FilterFormatters
                          .TranslateFilter <Foo>(
                // These must be property gets - do not refactor this line
                f => f.Prop1 == bar.Prop1 && f.Prop2 == bar.Prop2 && f.Prop3 == bar.Prop3
                )
                          .OrderBy(f => f.PropertyName)
                          .ToArray();

            Assert.AreEqual(3, filters.Count());
            Assert.AreEqual("Prop1", filters[0].PropertyName);
            Assert.AreEqual("def", filters[0].Value);
            Assert.AreEqual("Prop2", filters[1].PropertyName);
            Assert.AreEqual("ghi", filters[1].Value);
            Assert.AreEqual("Prop3", filters[2].PropertyName);
            Assert.AreEqual("jkl", filters[2].Value);
        }
        public void TranslateFilterShouldThrowExceptionIfOuterExpressionIsAndAlsoAndInnerRightExpressionIsNotABinaryExpression()
        {
            var testVariable = bool.Parse(bool.TrueString);

            FilterFormatters.TranslateFilter <Foo>(f => f.Prop2 == null && testVariable);
        }
        public void TranslateFilterShouldThrowExceptionForOrElseExpression()
        {
            var testVariable = bool.Parse(bool.TrueString);

            FilterFormatters.TranslateFilter <Foo>(f => f.Prop2 == null || testVariable);
        }