-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from graphql-dotnet/test-runner
Make tests runnable from Visual Studio
- Loading branch information
Showing
9 changed files
with
133 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Threading.Tasks; | ||
using GraphQL.Conventions.Tests.Templates; | ||
using GraphQL.Conventions.Tests.Templates.Extensions; | ||
using GraphQL.Conventions.Web; | ||
|
||
namespace GraphQL.Conventions.Tests.Web | ||
{ | ||
public class RequestHandlerTests : TestBase | ||
{ | ||
[Test] | ||
public async Task Can_Run_Query() | ||
{ | ||
var request = Request.New("{ \"query\": \"{ hello }\" }"); | ||
var response = await RequestHandler | ||
.New() | ||
.WithQuery<TestQuery>() | ||
.Generate() | ||
.ProcessRequest(request, null); | ||
|
||
response.ExecutionResult.Data.ShouldHaveFieldWithValue("hello", "World"); | ||
response.Body.ShouldEqual("{\"data\":{\"hello\":\"World\"}}"); | ||
response.Errors.Count.ShouldEqual(0); | ||
response.Warnings.Count.ShouldEqual(0); | ||
} | ||
|
||
[Test] | ||
public async Task Can_Run_Query_And_Report_Validation_Violations_As_Warnings() | ||
{ | ||
var request = Request.New("{ \"query\": \"query test($foo: String) { a: hello b: hello }\" }"); | ||
var response = await RequestHandler | ||
.New() | ||
.WithQuery<TestQuery>() | ||
.WithoutValidation(true) | ||
.Generate() | ||
.ProcessRequest(request, null); | ||
|
||
response.Body.ShouldEqual("{\"data\":{\"a\":\"World\",\"b\":\"World\"}}"); | ||
response.Errors.Count.ShouldEqual(0); | ||
response.Warnings.Count.ShouldEqual(1); | ||
response.Warnings[0].ToString().ShouldEqual("GraphQL.Validation.ValidationError: Variable \"$foo\" is never used in operation \"$test\"."); | ||
} | ||
|
||
class TestQuery | ||
{ | ||
public string Hello => "World"; | ||
} | ||
} | ||
} |
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,33 @@ | ||
using GraphQL.Conventions.Tests.Templates; | ||
using GraphQL.Conventions.Tests.Templates.Extensions; | ||
using GraphQL.Conventions.Web; | ||
|
||
namespace GraphQL.Conventions.Tests.Web | ||
{ | ||
public class RequestTests : TestBase | ||
{ | ||
[Test] | ||
public void Can_Instantiate_Request_Object_From_String() | ||
{ | ||
var request = Request.New("{\"query\":\"{}\"}"); | ||
request.IsValid.ShouldEqual(true); | ||
request.QueryString.ShouldEqual("{}"); | ||
request.Variables.ShouldEqual(null); | ||
} | ||
|
||
[Test] | ||
public void Cannot_Instantiate_Request_Object_From_Invalid_String() | ||
{ | ||
var request = Request.New("\"invalid_query\":\"{}\""); | ||
request.IsValid.ShouldEqual(false); | ||
} | ||
|
||
[Test] | ||
public void Cannot_Derive_Query_From_Invalid_String() | ||
{ | ||
var request = Request.New("{\"invalid_query\":\"{}\"}"); | ||
request.IsValid.ShouldEqual(true); | ||
request.QueryString.ShouldEqual(string.Empty); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using System.Collections.Generic; | ||
using GraphQL.Conventions.Tests.Templates; | ||
using GraphQL.Conventions.Tests.Templates.Extensions; | ||
using GraphQL.Conventions.Web; | ||
using GraphQL.Validation; | ||
|
||
namespace GraphQL.Conventions.Tests.Web | ||
{ | ||
public class ResponseTests : TestBase | ||
{ | ||
[Test] | ||
public void Can_Instantiate_Response_Object_From_Execution_Result() | ||
{ | ||
var request = Request.New("{\"query\":\"{}\"}"); | ||
var result = new ExecutionResult(); | ||
result.Data = new Dictionary<string, object>(); | ||
var response = new Response(request, result); | ||
response.HasData.ShouldEqual(true); | ||
response.HasErrors.ShouldEqual(false); | ||
} | ||
|
||
[Test] | ||
public void Can_Instantiate_Response_Object_From_Validation_Result() | ||
{ | ||
var request = Request.New("{\"query\":\"{}\"}"); | ||
var result = new ValidationResult(); | ||
result.Errors.Add(new ExecutionError("Test")); | ||
var response = new Response(request, result); | ||
response.ValidationResult.Errors.Count.ShouldEqual(1); | ||
} | ||
} | ||
} |
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