-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for filtering in combination with paging. (#2317)
- Loading branch information
1 parent
a127779
commit 5b478a9
Showing
38 changed files
with
371 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/HotChocolate/Data/test/Data.Filters.InMemory.Tests/FilteringAndPaging.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Threading.Tasks; | ||
using HotChocolate.Data.Filters; | ||
using HotChocolate.Execution; | ||
using Snapshooter; | ||
using Snapshooter.Xunit; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Data.Filters | ||
{ | ||
public class FilteringAndPaging | ||
{ | ||
private static readonly Foo[] _fooEntities = | ||
{ | ||
new Foo { Bar = true }, | ||
new Foo { Bar = false } | ||
}; | ||
|
||
private readonly SchemaCache _cache = new SchemaCache(); | ||
|
||
[Fact] | ||
public async Task Create_BooleanEqual_Expression() | ||
{ | ||
// arrange | ||
IRequestExecutor tester = _cache.CreateSchema<Foo, FooFilterType>(_fooEntities, true); | ||
|
||
// act | ||
// assert | ||
IExecutionResult res1 = await tester.ExecuteAsync( | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ root(where: { bar: { eq: true}}){ nodes { bar } }}") | ||
.Create()); | ||
|
||
res1.ToJson().MatchSnapshot(new SnapshotNameExtension("true")); | ||
|
||
IExecutionResult res2 = await tester.ExecuteAsync( | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ root(where: { bar: { eq: false}}){ nodes { bar }}}") | ||
.Create()); | ||
|
||
res2.ToJson().MatchSnapshot(new SnapshotNameExtension("false")); | ||
} | ||
|
||
public class Foo | ||
{ | ||
public int Id { get; set; } | ||
|
||
public bool Bar { get; set; } | ||
} | ||
|
||
public class FooNullable | ||
{ | ||
public int Id { get; set; } | ||
|
||
public bool? Bar { get; set; } | ||
} | ||
|
||
public class FooFilterType | ||
: FilterInputType<Foo> | ||
{ | ||
} | ||
|
||
public class FooNullableFilterType | ||
: FilterInputType<FooNullable> | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...InMemory.Tests/__snapshots__/FilteringAndPaging.Create_BooleanEqual_Expression_false.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"data": { | ||
"root": { | ||
"nodes": [ | ||
{ | ||
"bar": false | ||
} | ||
] | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
....InMemory.Tests/__snapshots__/FilteringAndPaging.Create_BooleanEqual_Expression_true.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"data": { | ||
"root": { | ||
"nodes": [ | ||
{ | ||
"bar": true | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/HotChocolate/Data/test/Data.Filters.SqlServer.Tests/FilteringAndPaging.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Threading.Tasks; | ||
using HotChocolate.Data.Filters; | ||
using HotChocolate.Execution; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Data.Filters | ||
{ | ||
public class FilteringAndPaging | ||
{ | ||
private static readonly Foo[] _fooEntities = | ||
{ | ||
new Foo { Bar = true }, | ||
new Foo { Bar = false } | ||
}; | ||
|
||
private readonly SchemaCache _cache = new SchemaCache(); | ||
|
||
[Fact] | ||
public async Task Create_BooleanEqual_Expression() | ||
{ | ||
// arrange | ||
IRequestExecutor tester = _cache.CreateSchema<Foo, FooFilterType>(_fooEntities, true); | ||
|
||
// act | ||
IExecutionResult res1 = await tester.ExecuteAsync( | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ root(where: { bar: { eq: true}}){ nodes { bar } }}") | ||
.Create()); | ||
|
||
IExecutionResult res2 = await tester.ExecuteAsync( | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ root(where: { bar: { eq: false}}){ nodes { bar }}}") | ||
.Create()); | ||
|
||
// assert | ||
res1.MatchSqlSnapshot("true"); | ||
res2.MatchSqlSnapshot("false"); | ||
} | ||
|
||
|
||
public class Foo | ||
{ | ||
public int Id { get; set; } | ||
|
||
public bool Bar { get; set; } | ||
} | ||
|
||
public class FooNullable | ||
{ | ||
public int Id { get; set; } | ||
|
||
public bool? Bar { get; set; } | ||
} | ||
|
||
public class FooFilterType | ||
: FilterInputType<Foo> | ||
{ | ||
} | ||
|
||
public class FooNullableFilterType | ||
: FilterInputType<FooNullable> | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.