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
24fc490
commit da4bfe5
Showing
21 changed files
with
506 additions
and
3 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
156 changes: 156 additions & 0 deletions
156
src/Stitching/Stitching.Tests/Middleware/ScalarTests.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,156 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
using Snapshooter.Xunit; | ||
using HotChocolate.Execution; | ||
using HotChocolate.AspNetCore.Tests.Utilities; | ||
using Snapshooter; | ||
using HotChocolate.Types; | ||
using HotChocolate.Language; | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.TestHost; | ||
using HotChocolate.Stitching.Schemas.Contracts; | ||
using HotChocolate.Stitching.Schemas.Customers; | ||
using HotChocolate.AspNetCore; | ||
using HotChocolate.Stitching.Schemas.SpecialCases; | ||
using Moq; | ||
|
||
namespace HotChocolate.Stitching | ||
{ | ||
public class ScalarTests | ||
: StitchingTestBase | ||
{ | ||
public ScalarTests(TestServerFactory testServerFactory) | ||
: base(testServerFactory) | ||
{ | ||
} | ||
|
||
[InlineData("date_field")] | ||
[InlineData("date_time_field")] | ||
[InlineData("string_field")] | ||
[InlineData("id_field")] | ||
[InlineData("byte_field")] | ||
[InlineData("int_field")] | ||
[InlineData("long_field")] | ||
[InlineData("float_field")] | ||
[InlineData("decimal_field")] | ||
[Theory] | ||
public async Task Scalar_Serializes_And_Deserializes_Correctly( | ||
string fieldName) | ||
{ | ||
// arrange | ||
IHttpClientFactory clientFactory = CreateRemoteSchemas(); | ||
|
||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddSingleton(clientFactory); | ||
serviceCollection.AddStitchedSchema(builder => builder | ||
.AddSchemaFromHttp("contract") | ||
.AddSchemaFromHttp("customer")); | ||
|
||
IServiceProvider services = | ||
serviceCollection.BuildServiceProvider(); | ||
|
||
IQueryExecutor executor = services | ||
.GetRequiredService<IQueryExecutor>(); | ||
IExecutionResult result = null; | ||
|
||
// act | ||
using (IServiceScope scope = services.CreateScope()) | ||
{ | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery($@" | ||
query a($contractId: ID!) {{ | ||
contract(contractId: $contractId) {{ | ||
... on LifeInsuranceContract {{ | ||
{fieldName} | ||
}} | ||
}} | ||
}}") | ||
.SetVariableValue( | ||
"contractId", | ||
"TGlmZUluc3VyYW5jZUNvbnRyYWN0LXgx") | ||
.SetServices(scope.ServiceProvider) | ||
.Create(); | ||
|
||
result = await executor.ExecuteAsync(request); | ||
} | ||
|
||
// assert | ||
result.MatchSnapshot(new SnapshotNameExtension(fieldName)); | ||
} | ||
|
||
[Fact] | ||
public async Task Custom_Scalar_Types() | ||
{ | ||
// arrange | ||
IHttpClientFactory clientFactory = CreateRemoteSchemas(); | ||
|
||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddSingleton(clientFactory); | ||
serviceCollection.AddStitchedSchema(builder => builder | ||
.AddSchemaFromHttp("special") | ||
.AddSchemaConfiguration(c => | ||
c.RegisterType<MyCustomScalarType>())); | ||
|
||
IServiceProvider services = | ||
serviceCollection.BuildServiceProvider(); | ||
|
||
IQueryExecutor executor = services | ||
.GetRequiredService<IQueryExecutor>(); | ||
IExecutionResult result = null; | ||
|
||
// act | ||
using (IServiceScope scope = services.CreateScope()) | ||
{ | ||
IReadOnlyQueryRequest request = | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ custom_scalar(bar: \"custom_string\") }") | ||
.SetServices(scope.ServiceProvider) | ||
.Create(); | ||
|
||
result = await executor.ExecuteAsync(request); | ||
} | ||
|
||
// assert | ||
result.MatchSnapshot(); | ||
} | ||
|
||
protected override IHttpClientFactory CreateRemoteSchemas( | ||
Dictionary<string, HttpClient> connections) | ||
{ | ||
TestServer server_contracts = TestServerFactory.Create( | ||
ContractSchemaFactory.ConfigureServices, | ||
app => app.UseGraphQL()); | ||
|
||
TestServer server_customers = TestServerFactory.Create( | ||
CustomerSchemaFactory.ConfigureServices, | ||
app => app.UseGraphQL()); | ||
|
||
TestServer server_special = TestServerFactory.Create( | ||
SpecialCasesSchemaFactory.ConfigureServices, | ||
app => app.UseGraphQL()); | ||
|
||
connections["contract"] = server_contracts.CreateClient(); | ||
connections["customer"] = server_customers.CreateClient(); | ||
connections["special"] = server_special.CreateClient(); | ||
|
||
var httpClientFactory = new Mock<IHttpClientFactory>(); | ||
httpClientFactory.Setup(t => t.CreateClient(It.IsAny<string>())) | ||
.Returns(new Func<string, HttpClient>(n => | ||
{ | ||
if (connections.ContainsKey(n)) | ||
{ | ||
return connections[n]; | ||
} | ||
throw new Exception(); | ||
})); | ||
|
||
return httpClientFactory.Object; | ||
} | ||
|
||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/Stitching/Stitching.Tests/Middleware/__snapshots__/ScalarTests.Custom_Scalar_Types.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 @@ | ||
{ | ||
"Data": { | ||
"custom_scalar": "custom_string" | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...re/__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_byte_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"byte_field": 123 | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...re/__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_date_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"date_field": "2018-05-17" | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_date_time_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"date_time_field": "2018-05-17T08:59:00.000Z" | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_decimal_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"decimal_field": 123.123 | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...e/__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_float_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"float_field": 123.123 | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ware/__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_id_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"id_field": "abc_123" | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...are/__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_int_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"int_field": 123 | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...re/__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_long_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"long_field": 123 | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../__snapshots__/ScalarTests.Scalar_Serializes_And_Deserializes_Correctly_string_field.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 @@ | ||
{ | ||
"Data": { | ||
"contract": { | ||
"string_field": "abc" | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [], | ||
"ContextData": {} | ||
} |
Oops, something went wrong.