-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked ScopedContextData Tests (#539)
- Loading branch information
1 parent
7b106aa
commit f29b552
Showing
3 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
46 changes: 0 additions & 46 deletions
46
src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using ChilliCream.Testing; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
public class ScopedContextDataTests | ||
{ | ||
[Fact] | ||
public async Task ScopedContextDataIsPassedAllongCorrectly() | ||
{ | ||
// arrange | ||
ISchema schema = Schema.Create( | ||
@" | ||
type Query { | ||
root: Level1 | ||
} | ||
type Level1 { | ||
a: Level2 | ||
b: Level2 | ||
} | ||
type Level2 | ||
{ | ||
foo: String | ||
} | ||
", | ||
c => c.Use(next => context => | ||
{ | ||
if (context.ScopedContextData | ||
.TryGetValue("field", out object o) | ||
&& o is string s) | ||
{ | ||
s += "/" + context.Field.Name; | ||
} | ||
else | ||
{ | ||
s = "./" + context.Field.Name; | ||
} | ||
|
||
context.ScopedContextData = context.ScopedContextData | ||
.SetItem("field", s); | ||
|
||
context.Result = s; | ||
|
||
return Task.CompletedTask; | ||
})); | ||
|
||
IQueryExecutor executor = schema.MakeExecutable( | ||
b => b.UseDefaultPipeline() | ||
); | ||
|
||
// act | ||
IExecutionResult result = await executor.ExecuteAsync( | ||
new QueryRequest("{ root { a { foo } b { foo } } }")); | ||
|
||
// assert | ||
result.Snapshot(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Core/Core.Tests/__snapshots__/ScopedContextDataIsPassedAllongCorrectly.json
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,14 @@ | ||
{ | ||
"Data": { | ||
"root": { | ||
"a": { | ||
"foo": "./root/a/foo" | ||
}, | ||
"b": { | ||
"foo": "./root/b/foo" | ||
} | ||
} | ||
}, | ||
"Extensions": {}, | ||
"Errors": [] | ||
} |