Skip to content

Commit

Permalink
fixed list visitor did not pop instance (#2628)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Nov 21, 2020
1 parent 5d4771a commit de376f2
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 31 deletions.
Expand Up @@ -67,6 +67,7 @@ public abstract class QueryableListOperationHandlerBase
if (context.TryCreateLambda(out LambdaExpression? lambda))
{
context.Scopes.Pop();
Expression instance = context.PopInstance();
Expression expression = HandleListOperation(
context,
field,
Expand All @@ -77,7 +78,7 @@ public abstract class QueryableListOperationHandlerBase
if (context.InMemory)
{
expression = FilterExpressionBuilder.NotNullAndAlso(
context.GetInstance(), expression);
instance, expression);
}
context.GetLevel().Enqueue(expression);
}
Expand Down
Expand Up @@ -13,12 +13,12 @@ public class QueryableFilterVisitorListTests
public void Create_ArraySomeStringEqual_Expression()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ bar: {some: { eq: \"a\" }}}");
ExecutorBuilder? tester = CreateProviderTester(new FooSimpleFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterType());

// act
Func<FooSimple, bool>? func = tester.Build<FooSimple>(value);
Func<FooSimple, bool> func = tester.Build<FooSimple>(value);

// assert
var a = new FooSimple { Bar = new[] { "c", "d", "a" } };
Expand All @@ -32,12 +32,12 @@ public void Create_ArraySomeStringEqual_Expression()
public void Create_ArrayAnyStringEqual_Expression()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ bar: {any: true}}");
ExecutorBuilder? tester = CreateProviderTester(new FooSimpleFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterType());

// act
Func<FooSimple, bool>? func = tester.Build<FooSimple>(value);
Func<FooSimple, bool> func = tester.Build<FooSimple>(value);

// assert
var a = new FooSimple { Bar = new[] { "c", "d", "a" } };
Expand All @@ -54,12 +54,12 @@ public void Create_ArrayAnyStringEqual_Expression()
public void Create_ArraySomeStringEqualWithNull_Expression()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ bar: {some: { eq: \"a\" }}}");
ExecutorBuilder? tester = CreateProviderTester(new FooSimpleFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterType());

// act
Func<FooSimple, bool>? func = tester.Build<FooSimple>(value);
Func<FooSimple, bool> func = tester.Build<FooSimple>(value);

// assert
var a = new FooSimple { Bar = new[] { "c", null, "a" } };
Expand All @@ -76,9 +76,9 @@ public void Create_ArraySomeStringEqualWithNull_Expression()
public void Create_ArraySomeObjectStringEqualWithNull_Expression()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ fooNested: {some: {bar: { eq: \"a\" }}}}");
ExecutorBuilder? tester = CreateProviderTester(new FooFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooFilterType());

// act
Func<Foo, bool>? func = tester.Build<Foo>(value);
Expand Down Expand Up @@ -109,9 +109,9 @@ public void Create_ArraySomeObjectStringEqualWithNull_Expression()
[Fact]
public void Create_ArraySomeObjectStringEqual_Expression()
{
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ fooNested: {some: {bar: { eq: \"a\" }}}}");
ExecutorBuilder? tester = CreateProviderTester(new FooFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooFilterType());

// act
Func<Foo, bool>? func = tester.Build<Foo>(value);
Expand Down Expand Up @@ -155,9 +155,9 @@ public void Create_ArraySomeObjectStringEqual_Expression()
[Fact]
public void Create_ArrayNoneObjectStringEqual_Expression()
{
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ fooNested: {none: {bar: { eq: \"a\" }}}}");
ExecutorBuilder? tester = CreateProviderTester(new FooFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooFilterType());

// act
Func<Foo, bool>? func = tester.Build<Foo>(value);
Expand Down Expand Up @@ -201,9 +201,9 @@ public void Create_ArrayNoneObjectStringEqual_Expression()
public void Create_ArrayAllObjectStringEqual_Expression()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ fooNested: {all: { bar: {eq: \"a\" }}}}");
ExecutorBuilder? tester = CreateProviderTester(new FooFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooFilterType());

// act
Func<Foo, bool>? func = tester.Build<Foo>(value);
Expand Down Expand Up @@ -270,9 +270,9 @@ public void Create_ArrayAllObjectStringEqual_Expression()
public void Create_ArrayAnyObjectStringEqual_Expression()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ fooNested: {any: true}}");
ExecutorBuilder? tester = CreateProviderTester(new FooFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooFilterType());

// act
Func<Foo, bool>? func = tester.Build<Foo>(value);
Expand Down Expand Up @@ -301,9 +301,9 @@ public void Create_ArrayAnyObjectStringEqual_Expression()
public void Create_ArrayNotAnyObjectStringEqual_Expression()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ fooNested: {any: false}}");
ExecutorBuilder? tester = CreateProviderTester(new FooFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooFilterType());

// act
Func<Foo, bool>? func = tester.Build<Foo>(value);
Expand Down Expand Up @@ -334,12 +334,12 @@ public void Create_ArrayNotAnyObjectStringEqual_Expression()
public void Create_ArraySomeStringEqual_Expression_Null()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ bar: {some: { eq: null }}}");
ExecutorBuilder? tester = CreateProviderTester(new FooSimpleFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterType());

// act
Func<FooSimple, bool>? func = tester.Build<FooSimple>(value);
Func<FooSimple, bool> func = tester.Build<FooSimple>(value);

// assert
var a = new FooSimple { Bar = new[] { "c", null, "a" } };
Expand All @@ -353,12 +353,12 @@ public void Create_ArraySomeStringEqual_Expression_Null()
public void Create_ArrayNoneStringEqual_Expression_Null()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ bar: {none: { eq: null }}}");
ExecutorBuilder? tester = CreateProviderTester(new FooSimpleFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterType());

// act
Func<FooSimple, bool>? func = tester.Build<FooSimple>(value);
Func<FooSimple, bool> func = tester.Build<FooSimple>(value);

// assert
var a = new FooSimple { Bar = new[] { "c", "d", "a" } };
Expand All @@ -372,30 +372,133 @@ public void Create_ArrayNoneStringEqual_Expression_Null()
public void Create_ArrayAllStringEqual_Expression_Null()
{
// arrange
IValueNode? value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ bar: {all: { eq: null }}}");
ExecutorBuilder? tester = CreateProviderTester(new FooSimpleFilterType());
ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterType());

// act
Func<FooSimple, bool>? func = tester.Build<FooSimple>(value);
Func<FooSimple, bool> func = tester.Build<FooSimple>(value);

// assert
var a = new FooSimple { Bar = new string[] { null, null, null } };
Assert.True(func(a));

var b = new FooSimple { Bar = new[] { "c", "d", "b" } };
Assert.False(func(b));
}

[Fact]
public void Create_ArraySomeStringEqual_Multiple()
{
// arrange
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ bar: {some: { eq: \"a\" }} otherProperty: {eq:null}}");
ExecutorBuilder tester = CreateProviderTester(new FooSimpleFilterType());

// act
Func<FooSimple, bool> func = tester.Build<FooSimple>(value);

// assert
var a = new FooSimple { Bar = new[] { "c", "d", "a" } };
Assert.True(func(a));

var b = new FooSimple { Bar = new[] { "c", "d", "b" } };
Assert.False(func(b));
}

[Fact]
public void Create_ArraySomeObjectEqual_Multiple()
{
// arrange
IValueNode value = Utf8GraphQLParser.Syntax.ParseValueLiteral(
"{ fooNested: {some: {bar: { eq: \"a\" }}} otherProperty: {eq:null}}");
ExecutorBuilder tester = CreateProviderTester(new FooFilterType());

// act
Func<Foo, bool>? func = tester.Build<Foo>(value);

// assert
var a = new Foo
{
FooNested = new[]
{
new FooNested { Bar = "a" },
new FooNested { Bar = "a" },
new FooNested { Bar = "a" }
}
};
Assert.True(func(a));

var b = new Foo
{
FooNested = new[]
{
new FooNested { Bar = "c" },
new FooNested { Bar = "a" },
new FooNested { Bar = "a" }
}
};
Assert.True(func(b));

var c = new Foo
{
FooNested = new[]
{
new FooNested { Bar = "a" },
new FooNested { Bar = "d" },
new FooNested { Bar = "b" }
}
};
Assert.True(func(c));

var d = new Foo
{
FooNested = new[]
{
new FooNested { Bar = "c" },
new FooNested { Bar = "d" },
new FooNested { Bar = "b" }
}
};
Assert.False(func(d));

var e = new Foo
{
FooNested = new[]
{
null,
new FooNested { Bar = null },
new FooNested { Bar = "d" },
new FooNested { Bar = "b" }
}
};
Assert.False(func(e));

var f = new Foo
{
OtherProperty = "ShouldBeNull",
FooNested = new[]
{
new FooNested { Bar = "c" },
new FooNested { Bar = "a" },
new FooNested { Bar = "a" }
}
};
Assert.False(func(f));
}

public class Foo
{
public IEnumerable<FooNested?>? FooNested { get; set; }

public string? OtherProperty { get; set; }
}

public class FooSimple
{
public IEnumerable<string?>? Bar { get; set; }

public string? OtherProperty { get; set; }
}

public class FooNested
Expand Down

0 comments on commit de376f2

Please sign in to comment.