From bf878c00d75c8319c711144c60e29e84d3e9a2d0 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Fri, 25 Jan 2019 15:04:27 +0100 Subject: [PATCH 1/4] Reworked tests --- .../Middleware/ScopedContextDataTests.cs | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs b/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs index 3f8f4e60b62..fd9e1397072 100644 --- a/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs +++ b/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs @@ -11,23 +11,40 @@ public class ScopedContextDataTests public async Task ScopedContextDataIsPassedAllongCorrectly() { // arrange - bool allDataIsPassedAlong = false; - ISchema schema = Schema.Create( - "type Query { nested: Nested } type Nested { foo: String }", - c => c.Use(next => context => - { - if (context.ScopedContextData.ContainsKey("field")) - { - allDataIsPassedAlong = true; - context.Result = "123"; - } - else + @" + type Query { + root: Level1 + } + + type Level1 { + a: Level2 + b: Level2 + } + + type Level2 { - context.ScopedContextData = context.ScopedContextData.Add("field", "abc"); - context.Result = new { foo = "123"}; + 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; })); @@ -37,10 +54,10 @@ public async Task ScopedContextDataIsPassedAllongCorrectly() // act IExecutionResult result = await executor.ExecuteAsync( - new QueryRequest("{ nested { foo } }")); + new QueryRequest("{ nested { a { foo } b { foo } } }")); // assert - Assert.True(allDataIsPassedAlong); + result.Snapshot(); } } } From 186427fc07b60bdd6911456d5f49bfdf8d258f52 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Fri, 25 Jan 2019 15:06:08 +0100 Subject: [PATCH 2/4] Fixed test --- .../Core.Tests/Execution/Middleware/ScopedContextDataTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs b/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs index fd9e1397072..54c51b8d4e1 100644 --- a/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs +++ b/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs @@ -54,7 +54,7 @@ type Level2 // act IExecutionResult result = await executor.ExecuteAsync( - new QueryRequest("{ nested { a { foo } b { foo } } }")); + new QueryRequest("{ root { a { foo } b { foo } } }")); // assert result.Snapshot(); From 83d2a98b01769040c441588e5387fce16a334433 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Fri, 25 Jan 2019 15:08:50 +0100 Subject: [PATCH 3/4] Added snapshot --- .../ScopedContextDataIsPassedAllongCorrectly.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/Core/Core.Tests/__snapshots__/ScopedContextDataIsPassedAllongCorrectly.json diff --git a/src/Core/Core.Tests/__snapshots__/ScopedContextDataIsPassedAllongCorrectly.json b/src/Core/Core.Tests/__snapshots__/ScopedContextDataIsPassedAllongCorrectly.json new file mode 100644 index 00000000000..926f22753fa --- /dev/null +++ b/src/Core/Core.Tests/__snapshots__/ScopedContextDataIsPassedAllongCorrectly.json @@ -0,0 +1,14 @@ +{ + "Data": { + "root": { + "a": { + "foo": "./root/a/foo" + }, + "b": { + "foo": "./root/b/foo" + } + } + }, + "Extensions": {}, + "Errors": [] +} From 95b144858ea30773893fbcb54bfa293ccdeec5c6 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Fri, 25 Jan 2019 15:09:17 +0100 Subject: [PATCH 4/4] moved test class --- .../Execution/{Middleware => }/ScopedContextDataTests.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Core/Core.Tests/Execution/{Middleware => }/ScopedContextDataTests.cs (100%) diff --git a/src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs b/src/Core/Core.Tests/Execution/ScopedContextDataTests.cs similarity index 100% rename from src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.cs rename to src/Core/Core.Tests/Execution/ScopedContextDataTests.cs