-
-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b22f09
commit 393bb84
Showing
368 changed files
with
31,156 additions
and
2,073 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
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 |
---|---|---|
|
@@ -303,3 +303,4 @@ tools/** | |
|
||
testoutput/ | ||
artifacts/ | ||
__mismatch__ |
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
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
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
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
253 changes: 253 additions & 0 deletions
253
src/Core/Abstractions.Tests/Execution/QueryRequestBuilderTests.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,253 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using HotChocolate.Utilities; | ||
using Snapshooter.Xunit; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Execution.Tests | ||
{ | ||
public class QueryRequestBuilderTests | ||
{ | ||
[Fact] | ||
public void BuildRequest_OnlyQueryIsSet_RequestHasOnlyQuery() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.Create(); | ||
|
||
// assert | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_Empty_QueryRequestBuilderException() | ||
{ | ||
// arrange | ||
// act | ||
Action action = () => | ||
QueryRequestBuilder.New() | ||
.Create(); | ||
|
||
// assert | ||
Assert.Throws<QueryRequestBuilderException>(action) | ||
.Message.MatchSnapshot(); | ||
} | ||
|
||
[InlineData("")] | ||
[InlineData(null)] | ||
[Theory] | ||
public void SetQuery_NullOrEmpty_ArgumentException(string query) | ||
{ | ||
// arrange | ||
// act | ||
Action action = () => | ||
QueryRequestBuilder.New() | ||
.SetQuery(query) | ||
.Create(); | ||
|
||
// assert | ||
Assert.Equal("query", | ||
Assert.Throws<ArgumentException>(action).ParamName); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndAddVariables_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.AddVariableValue("one", "foo") | ||
.AddVariableValue("two", "bar") | ||
.Create(); | ||
|
||
// assert | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndSetVariables_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.AddVariableValue("one", "foo") | ||
.AddVariableValue("two", "bar") | ||
.SetVariableValues(new Dictionary<string, object> | ||
{ | ||
{ "three", "baz" } | ||
}) | ||
.Create(); | ||
|
||
// assert | ||
// only three should be in the request | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndResetVariables_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.AddVariableValue("one", "foo") | ||
.AddVariableValue("two", "bar") | ||
.SetVariableValues(null) | ||
.Create(); | ||
|
||
// assert | ||
// no variable should be in the request | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndAddProperties_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.AddProperty("one", "foo") | ||
.AddProperty("two", "bar") | ||
.Create(); | ||
|
||
// assert | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndSetProperties_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.AddProperty("one", "foo") | ||
.AddProperty("two", "bar") | ||
.SetProperties(new Dictionary<string, object> | ||
{ | ||
{ "three", "baz" } | ||
}) | ||
.Create(); | ||
|
||
// assert | ||
// only three should be in the request | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndResetProperties_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.AddProperty("one", "foo") | ||
.AddProperty("two", "bar") | ||
.SetProperties(null) | ||
.Create(); | ||
|
||
// assert | ||
// no property should be in the request | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndInitialValue_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.SetInitialValue(new { a = "123" }) | ||
.Create(); | ||
|
||
// assert | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndOperation_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.SetOperation("bar") | ||
.Create(); | ||
|
||
// assert | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndResetOperation_RequestIsCreated() | ||
{ | ||
// arrange | ||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.SetOperation("bar") | ||
.SetOperation(null) | ||
.Create(); | ||
|
||
// assert | ||
// the operation should be null | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_QueryAndServices_RequestIsCreated() | ||
{ | ||
// arrange | ||
var service = new { a = "123" }; | ||
|
||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.SetServices(new DictionaryServiceProvider( | ||
service.GetType(), service)) | ||
.Create(); | ||
|
||
// assert | ||
request.MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public void BuildRequest_SetAll_RequestIsCreated() | ||
{ | ||
// arrange | ||
var service = new { a = "123" }; | ||
|
||
// act | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ foo }") | ||
.SetOperation("bar") | ||
.SetInitialValue(new { a = "456" }) | ||
.AddProperty("one", "foo") | ||
.AddVariableValue("two", "bar") | ||
.SetServices(new DictionaryServiceProvider( | ||
service.GetType(), service)) | ||
.Create(); | ||
|
||
// assert | ||
request.MatchSnapshot(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...snapshots__/QueryRequestBuilderTests.BuildRequest_Empty_QueryRequestBuilderException.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 @@ | ||
You must specify a query before creating a query request. |
8 changes: 8 additions & 0 deletions
8
...snapshots__/QueryRequestBuilderTests.BuildRequest_OnlyQueryIsSet_RequestHasOnlyQuery.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,8 @@ | ||
{ | ||
"Query": "{ foo }", | ||
"OperationName": null, | ||
"VariableValues": null, | ||
"InitialValue": null, | ||
"Properties": null, | ||
"Services": null | ||
} |
11 changes: 11 additions & 0 deletions
11
...shots__/QueryRequestBuilderTests.BuildRequest_QueryAndAddProperties_RequestIsCreated.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 @@ | ||
{ | ||
"Query": "{ foo }", | ||
"OperationName": null, | ||
"VariableValues": null, | ||
"InitialValue": null, | ||
"Properties": { | ||
"one": "foo", | ||
"two": "bar" | ||
}, | ||
"Services": null | ||
} |
11 changes: 11 additions & 0 deletions
11
...pshots__/QueryRequestBuilderTests.BuildRequest_QueryAndAddVariables_RequestIsCreated.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 @@ | ||
{ | ||
"Query": "{ foo }", | ||
"OperationName": null, | ||
"VariableValues": { | ||
"one": "foo", | ||
"two": "bar" | ||
}, | ||
"InitialValue": null, | ||
"Properties": null, | ||
"Services": null | ||
} |
10 changes: 10 additions & 0 deletions
10
...pshots__/QueryRequestBuilderTests.BuildRequest_QueryAndInitialValue_RequestIsCreated.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,10 @@ | ||
{ | ||
"Query": "{ foo }", | ||
"OperationName": null, | ||
"VariableValues": null, | ||
"InitialValue": { | ||
"a": "123" | ||
}, | ||
"Properties": null, | ||
"Services": null | ||
} |
8 changes: 8 additions & 0 deletions
8
...snapshots__/QueryRequestBuilderTests.BuildRequest_QueryAndOperation_RequestIsCreated.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,8 @@ | ||
{ | ||
"Query": "{ foo }", | ||
"OperationName": "bar", | ||
"VariableValues": null, | ||
"InitialValue": null, | ||
"Properties": null, | ||
"Services": null | ||
} |
8 changes: 8 additions & 0 deletions
8
...hots__/QueryRequestBuilderTests.BuildRequest_QueryAndResetOperation_RequestIsCreated.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,8 @@ | ||
{ | ||
"Query": "{ foo }", | ||
"OperationName": null, | ||
"VariableValues": null, | ||
"InitialValue": null, | ||
"Properties": null, | ||
"Services": null | ||
} |
8 changes: 8 additions & 0 deletions
8
...ots__/QueryRequestBuilderTests.BuildRequest_QueryAndResetProperties_RequestIsCreated.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,8 @@ | ||
{ | ||
"Query": "{ foo }", | ||
"OperationName": null, | ||
"VariableValues": null, | ||
"InitialValue": null, | ||
"Properties": null, | ||
"Services": null | ||
} |
Oops, something went wrong.