Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration tests for sorting #2313

Merged
merged 31 commits into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8065afc
Added missing sorting extension
michaelstaib Sep 11, 2020
b9420b9
Fixed bindings
michaelstaib Sep 11, 2020
85663d7
fixed sorting convention issue
michaelstaib Sep 11, 2020
2453c88
add failing tests
PascalSenn Sep 11, 2020
5fcd583
Merge branch 'pse/fix-sorting-argument-name' into mst/sorting-issue
PascalSenn Sep 11, 2020
345c7fb
Delete qg
PascalSenn Sep 11, 2020
bc20a86
fix tests
PascalSenn Sep 11, 2020
4aa57bd
test: add integration test for sorting
PascalSenn Sep 11, 2020
237e085
feat: add sqllite tests for sorting
PascalSenn Sep 11, 2020
799182c
test: update snapshots
PascalSenn Sep 11, 2020
7822284
test: add sql snapshots
PascalSenn Sep 11, 2020
a030703
Merge branch 'pse/sorting-inmemory-integration-tests' of https://gith…
PascalSenn Sep 11, 2020
4b5335e
Merge branch 'develop' into pse/sorting-inmemory-integration-tests
PascalSenn Sep 11, 2020
c429fd3
Merge branch 'develop' into pse/sorting-inmemory-integration-tests
michaelstaib Sep 17, 2020
c92fd10
Merge branch 'develop' into pse/sorting-inmemory-integration-tests
michaelstaib Sep 17, 2020
2aa229b
Merge branch 'develop' into pse/sorting-inmemory-integration-tests
PascalSenn Sep 23, 2020
e69a207
Merge branch 'develop' into pse/sorting-inmemory-integration-tests
michaelstaib Sep 25, 2020
b1ea6dc
fix format
PascalSenn Sep 26, 2020
aa981a8
Merge branch 'develop' into pse/sorting-inmemory-integration-tests
PascalSenn Sep 26, 2020
f645bd7
Update QueryableSortVisitorBooleanTests.cs
michaelstaib Sep 26, 2020
7aa6e57
Update QueryableSortVisitorBooleanTests.cs
michaelstaib Sep 26, 2020
da238ca
Update QueryableSortVisitorComparableTests.cs
michaelstaib Sep 26, 2020
678c6ad
Update QueryableSortVisitorEnumTests.cs
michaelstaib Sep 26, 2020
27cfc8b
Update QueryableSortVisitorEnumTests.cs
michaelstaib Sep 26, 2020
c4fb6db
Update QueryableSortVisitorStringTests.cs
michaelstaib Sep 26, 2020
44a16c6
Update QueryableSortVisitorBooleanTests.cs
michaelstaib Sep 26, 2020
b955eb2
Update QueryableSortVisitorComparableTests.cs
michaelstaib Sep 26, 2020
56e112a
Update QueryableSortVisitorEnumTests.cs
michaelstaib Sep 26, 2020
2f3946e
Update QueryableSortVisitorStringTests.cs
michaelstaib Sep 26, 2020
c04a1c2
Update QueryableSortVisitorObjectTests.cs
michaelstaib Sep 26, 2020
ecca136
Merge branch 'develop' into pse/sorting-inmemory-integration-tests
michaelstaib Sep 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/HotChocolate/Data/HotChocolate.Data.sln
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Filters.S
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Sorting.Tests", "test\Data.Sorting.Tests\HotChocolate.Data.Sorting.Tests.csproj", "{A7269FAC-8C91-46BA-B292-221E8DE32BD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Sorting.InMemory.Tests", "test\Data.Sorting.InMemory.Tests\HotChocolate.Data.Sorting.InMemory.Tests.csproj", "{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Sorting.SqlLite.Tests", "test\Data.Sorting.SqlLite.Tests\HotChocolate.Data.Sorting.SqlLite.Tests.csproj", "{D445A9BB-D068-496A-B261-609799F95915}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -96,6 +100,8 @@ Global
{CCCD4A40-EA4F-4AF7-91A7-3D8DC14D186C} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{9B858A08-741A-4C11-A243-3739C4E57B15} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{A7269FAC-8C91-46BA-B292-221E8DE32BD3} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{D445A9BB-D068-496A-B261-609799F95915} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D68A0AB9-871A-487B-8D12-1A7544D81B9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -350,5 +356,29 @@ Global
{A7269FAC-8C91-46BA-B292-221E8DE32BD3}.Release|x64.Build.0 = Release|Any CPU
{A7269FAC-8C91-46BA-B292-221E8DE32BD3}.Release|x86.ActiveCfg = Release|Any CPU
{A7269FAC-8C91-46BA-B292-221E8DE32BD3}.Release|x86.Build.0 = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x64.ActiveCfg = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x64.Build.0 = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x86.ActiveCfg = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x86.Build.0 = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|Any CPU.Build.0 = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x64.ActiveCfg = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x64.Build.0 = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x86.ActiveCfg = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x86.Build.0 = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|x64.ActiveCfg = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|x64.Build.0 = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|x86.ActiveCfg = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|x86.Build.0 = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|Any CPU.Build.0 = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|x64.ActiveCfg = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|x64.Build.0 = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|x86.ActiveCfg = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ namespace HotChocolate.Data.Filters
public class QueryableFilterVisitorComparableTests
: IClassFixture<SchemaCache>
{
private static readonly Foo[] _fooEntities = new[]{
private static readonly Foo[] _fooEntities = new[]
{
new Foo { BarShort = 12 },
new Foo { BarShort = 14 },
new Foo { BarShort = 13 }};
new Foo { BarShort = 13 }
};

private static readonly FooNullable[] _fooNullableEntities = new[]{
private static readonly FooNullable[] _fooNullableEntities = new[]
{
new FooNullable { BarShort = 12 },
new FooNullable { BarShort = null },
new FooNullable { BarShort = 14 },
new FooNullable { BarShort = 13 }};
new FooNullable { BarShort = 13 }
};

private readonly SchemaCache _cache;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>HotChocolate.Data.Sorting.InMemory.Tests</AssemblyName>
<RootNamespace>HotChocolate.Data</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Data\HotChocolate.Data.csproj" />
<ProjectReference Include="..\..\..\Core\test\Types.Tests\HotChocolate.Types.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Tests;
using Xunit;

namespace HotChocolate.Data.Sorting
{
public class QueryableSortVisitorBooleanTests
: IClassFixture<SchemaCache>
{
private static readonly Foo[] _fooEntities =
{
new Foo { Bar = true },
new Foo { Bar = false }
};

private static readonly FooNullable[] _fooNullableEntities =
{
new FooNullable { Bar = true },
new FooNullable { Bar = null },
new FooNullable { Bar = false }
};

private readonly SchemaCache _cache;

public QueryableSortVisitorBooleanTests(
SchemaCache cache)
{
_cache = cache;
}

[Fact]
public async Task Create_Boolean_OrderBy()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<Foo, FooSortType>(_fooEntities);

// act
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { bar: ASC}){ bar}}")
.Create());

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { bar: DESC}){ bar}}")
.Create());

// assert
res1.MatchSnapshot("ASC");
res2.MatchSnapshot("DESC");
}

[Fact]
public async Task Create_Boolean_OrderBy_Nullable()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<FooNullable, FooNullableSortType>(
_fooNullableEntities);

// act
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { bar: ASC}){ bar}}")
.Create());

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { bar: DESC}){ bar}}")
.Create());

// assert
res1.MatchSnapshot("ASC");
res2.MatchSnapshot("DESC");
}

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 FooSortType
: SortInputType<Foo>
{
}

public class FooNullableSortType
: SortInputType<FooNullable>
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Tests;
using Xunit;

namespace HotChocolate.Data.Sorting
{
public class QueryableSortVisitorComparableTests
: IClassFixture<SchemaCache>
{
private static readonly Foo[] _fooEntities =
{
new Foo { BarShort = 12 },
new Foo { BarShort = 14 },
new Foo { BarShort = 13 }
};

private static readonly FooNullable[] _fooNullableEntities =
{
new FooNullable { BarShort = 12 },
new FooNullable { BarShort = null },
new FooNullable { BarShort = 14 },
new FooNullable { BarShort = 13 }
};

private readonly SchemaCache _cache;

public QueryableSortVisitorComparableTests(
SchemaCache cache)
{
_cache = cache;
}

[Fact]
public async Task Create_Short_OrderBy()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<Foo, FooSortType>(_fooEntities);

// act
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { barShort: ASC}){ barShort}}")
.Create());

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { barShort: DESC}){ barShort}}")
.Create());

// assert
res1.MatchSnapshot("ASC");
res2.MatchSnapshot("DESC");
}

[Fact]
public async Task Create_Short_OrderBy_Nullable()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<FooNullable, FooNullableSortType>(
_fooNullableEntities);

// act
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { barShort: ASC}){ barShort}}")
.Create());

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: { barShort: DESC}){ barShort}}")
.Create());

// assert
res1.MatchSnapshot("ASC");
res2.MatchSnapshot("DESC");
}

public class Foo
{
public int Id { get; set; }

public short BarShort { get; set; }

public int BarInt { get; set; }

public long BarLong { get; set; }

public float BarFloat { get; set; }

public double BarDouble { get; set; }

public decimal BarDecimal { get; set; }
}

public class FooNullable
{
public int Id { get; set; }
public short? BarShort { get; set; }
}

public class FooSortType
: SortInputType<Foo>
{
}

public class FooNullableSortType
: SortInputType<FooNullable>
{
}
}
}