public void Create_StringNotStartsWith_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("bar_not_starts_with", new StringValueNode("a"))); var fooType = CreateType(new FooFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(Foo), TypeConversion.Default); value.Accept(filter); Func <Foo, bool> func = filter.CreateFilter <Foo>().Compile(); // assert var a = new Foo { Bar = "ab" }; Assert.False(func(a)); var b = new Foo { Bar = "ba" }; Assert.True(func(b)); }
public async Task Create_StringIn_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("bar_in", new ListValueNode(new[] { new StringValueNode("a"), new StringValueNode("c") }))); var fooType = await CreateTypeAsync(new FooFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(Foo), TypeConversion.Default); value.Accept(filter); Func <Foo, bool> func = filter.CreateFilter <Foo>().Compile(); // assert var a = new Foo { Bar = "a" }; Assert.True(func(a)); var b = new Foo { Bar = "b" }; Assert.False(func(b)); }
public void Create_ShortGreaterThan_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("barShort_gt", new IntValueNode("12"))); var fooType = CreateType(new FooFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(Foo), TypeConversion.Default); value.Accept(filter); Func <Foo, bool> func = filter.CreateFilter <Foo>().Compile(); // assert var a = new Foo { BarShort = 11 }; Assert.False(func(a)); var b = new Foo { BarShort = 12 }; Assert.False(func(b)); var c = new Foo { BarShort = 13 }; Assert.True(func(c)); }
public void Create_StringContains_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("bar_contains", new StringValueNode("a"))); FooFilterType fooType = CreateType(new FooFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(Foo), TypeConversion.Default, true); value.Accept(filter); Func <Foo, bool> func = filter.CreateFilter <Foo>().Compile(); // assert var a = new Foo { Bar = "testatest" }; Assert.True(func(a)); var b = new Foo { Bar = "testbtest" }; Assert.False(func(b)); }
public void Sort_NoSortSpecified_ShouldReturnUnalteredSource() { // arrange var value = new ObjectValueNode(); FooSortType sortType = CreateType(new FooSortType()); IQueryable <Foo> a = new[] { new Foo { Bar = "b" }, new Foo { Bar = "a" }, new Foo { Bar = "c" } }.AsQueryable(); // act var filter = new QueryableSortVisitor( sortType, typeof(Foo)); value.Accept(filter); IQueryable <Foo> aFiltered = filter.Sort(a); // assert Assert.Same(a, aFiltered); Assert.Collection(aFiltered, foo => Assert.Equal("b", foo.Bar), foo => Assert.Equal("a", foo.Bar), foo => Assert.Equal("c", foo.Bar) ); }
public void Sort_ComparableDesc_ShouldSortByStringAsc() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("bar", new EnumValueNode(SortOperationKind.Desc)) ); FooSortType sortType = CreateType(new FooSortType()); IQueryable <Foo> a = new[] { new Foo { Bar = "b" }, new Foo { Bar = "a" }, new Foo { Bar = "c" } }.AsQueryable(); // act var filter = new QueryableSortVisitor( sortType, typeof(Foo)); value.Accept(filter); ICollection <Foo> aFiltered = filter.Sort(a).ToList(); // assert Assert.Collection(aFiltered, foo => Assert.Equal("c", foo.Bar), foo => Assert.Equal("b", foo.Bar), foo => Assert.Equal("a", foo.Bar) ); }
public void Create_ArraySomeObjectStringEqualWithNull_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("fooNested_some", new ObjectValueNode( new ObjectFieldNode("bar", new StringValueNode("a") ) ) ) ); var fooType = CreateType(new FooFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(Foo), TypeConversion.Default, true); value.Accept(filter); Func <Foo, bool> func = filter.CreateFilter <Foo>().Compile(); // assert var a = new Foo { FooNested = new[] { new FooNested { Bar = "c" }, null, new FooNested { Bar = "a" } } }; Assert.True(func(a)); var b = new Foo { FooNested = new[] { new FooNested { Bar = "c" }, null, new FooNested { Bar = "b" } } }; Assert.False(func(b)); }
public void Create_ArrayAnyObjectStringEqual_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("fooNested_any", new BooleanValueNode(true) ) ); var fooType = CreateType(new FooFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(Foo), TypeConversion.Default, true); value.Accept(filter); Func <Foo, bool> func = filter.CreateFilter <Foo>().Compile(); // assert var a = new Foo { FooNested = new[] { new FooNested { Bar = "c" }, new FooNested { Bar = "d" }, new FooNested { Bar = "a" } } }; Assert.True(func(a)); var b = new Foo { FooNested = new FooNested[] { } }; Assert.False(func(b)); var c = new Foo { FooNested = null }; Assert.False(func(c)); var d = new Foo { FooNested = new FooNested[] { null } }; Assert.True(func(d)); }
public void Create_ObjectStringEqualDeep_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("foo", new ObjectValueNode( new ObjectFieldNode("fooNested", new ObjectValueNode( new ObjectFieldNode("bar", new StringValueNode("a") ) ) ) ) ) ); var fooType = CreateType(new EvenDeeperFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(EvenDeeper), TypeConversion.Default, true); value.Accept(filter); Func <EvenDeeper, bool> func = filter.CreateFilter <EvenDeeper>().Compile(); // assert var a = new EvenDeeper { Foo = new Foo { FooNested = new FooNested { Bar = "a" } } }; Assert.True(func(a)); var b = new EvenDeeper { Foo = new Foo { FooNested = new FooNested { Bar = "b" } } }; Assert.False(func(b)); }
public void Create_ObjectStringEqualRecursive_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("nested", new ObjectValueNode( new ObjectFieldNode("nested", new ObjectValueNode( new ObjectFieldNode("bar", new StringValueNode("a") ) ) ) ) ) ); var fooType = CreateType(new FilterInputType <Recursive>()); // act var filter = new QueryableFilterVisitor( fooType, typeof(Recursive), TypeConversion.Default, true); value.Accept(filter); Func <Recursive, bool> func = filter.CreateFilter <Recursive>().Compile(); var a = new Recursive { Nested = new Recursive { Nested = new Recursive { Bar = "a" } } }; Assert.True(func(a)); var b = new Recursive { Nested = new Recursive { Nested = new Recursive { Bar = "b" } } }; Assert.False(func(b)); }
public void Create_ArraySomeStringEqualWithNull_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("bar_some", new ObjectValueNode( new ObjectFieldNode("element", new StringValueNode("a") ) ) ) ); var fooType = CreateType(new FooSimpleFilterType()); // act var filter = new QueryableFilterVisitor( fooType, typeof(FooSimple), TypeConversion.Default, true); value.Accept(filter); Func <FooSimple, bool> func = filter.CreateFilter <FooSimple>().Compile(); // assert var a = new FooSimple { Bar = new[] { "c", null, "a" } }; Assert.True(func(a)); var b = new FooSimple { Bar = new[] { "c", null, "b" } }; Assert.False(func(b)); var c = new FooSimple { Bar = null }; Assert.False(func(c)); }
public void Sort_ComparableAsc_ShouldSortByStringWithNullableObjectInRootAsc() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("bar", new ObjectValueNode( new ObjectFieldNode("baz", new EnumValueNode(SortOperationKind.Asc) ) ) )); FooSortType sortType = CreateType(new FooSortType()); IQueryable <Foo> a = new[] { new Foo { Bar = new Bar { Baz = "c" } }, new Foo { Bar = new Bar { Baz = "b" } }, null }.AsQueryable(); // act var filter = new QueryableSortVisitorInMemory( sortType, typeof(Foo)); value.Accept(filter); ICollection <Foo> aFiltered = filter.Sort(a).ToList(); // assert Assert.Collection(aFiltered, foo => Assert.Null(foo), foo => Assert.Equal("b", foo.Bar.Baz), foo => Assert.Equal("c", foo.Bar.Baz) ); }
public void Create_NullableShortNotLowerThanOrEquals_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("barShort_not_lte", new IntValueNode(12))); var fooNullableType = CreateType(new FooNullableFilterType()); // act var filter = new QueryableFilterVisitor( fooNullableType, typeof(FooNullable), TypeConversion.Default); value.Accept(filter); Func <FooNullable, bool> func = filter.CreateFilter <FooNullable>().Compile(); // assert var a = new FooNullable { BarShort = 11 }; Assert.False(func(a)); var b = new FooNullable { BarShort = 12 }; Assert.False(func(b)); var c = new FooNullable { BarShort = 13 }; Assert.True(func(c)); var d = new FooNullable { BarShort = null }; Assert.True(func(d)); }
public void Create_NullableShortIn_Expression() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("barShort_in", new ListValueNode(new[] { new IntValueNode(13), new IntValueNode(14) })) ); var fooNullableType = CreateType(new FooNullableFilterType()); // act var filter = new QueryableFilterVisitor( fooNullableType, typeof(FooNullable), TypeConversion.Default, true); value.Accept(filter); Func <FooNullable, bool> func = filter.CreateFilter <FooNullable>().Compile(); // assert var a = new FooNullable { BarShort = 13 }; Assert.True(func(a)); var b = new FooNullable { BarShort = 12 }; Assert.False(func(b)); var c = new FooNullable { BarShort = null }; Assert.False(func(c)); }
public void Sort_Nullable_ShouldSortNullableProperlyDesc() { // arrange var value = new ObjectValueNode( new ObjectFieldNode("nullableInt", new EnumValueNode(SortOperationKind.Desc) ) ); FooSortType sortType = CreateType(new FooSortType()); IQueryable <Foo> a = new[] { new Foo { Bar = "b" }, new Foo { Bar = "c", NullableInt = 2 }, new Foo { Bar = "a", NullableInt = 1 } }.AsQueryable(); // act var filter = new QueryableSortVisitor( sortType, typeof(Foo)); value.Accept(filter); IQueryable <Foo> aFiltered = filter.Sort(a); // assert Assert.Collection(aFiltered, foo => Assert.Equal("c", foo.Bar), foo => Assert.Equal("a", foo.Bar), foo => Assert.Equal("b", foo.Bar) ); }