Skip to content

Commit

Permalink
Reworked ScopedContextData Tests (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jan 25, 2019
1 parent 7b106aa commit f29b552
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 46 deletions.
46 changes: 0 additions & 46 deletions src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs

This file was deleted.

63 changes: 63 additions & 0 deletions src/Core/Core.Tests/Execution/ScopedContextDataTests.cs
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();
}
}
}
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": []
}

0 comments on commit f29b552

Please sign in to comment.