From dc4ca9ad5298457dfc821d4c90801a3df222a8f9 Mon Sep 17 00:00:00 2001 From: Glen Date: Mon, 2 Dec 2024 12:21:19 +0200 Subject: [PATCH] Added CookieCrumble.TUnit to Fusion-vnext --- .../Fusion-vnext/test/Directory.Build.props | 9 ++ .../Fusion.Execution.Tests/FileResource.cs | 12 -- .../ModuleInitializer.cs | 12 ++ .../OperationPlannerTests.cs | 107 ++---------------- ...Plan_Simple_Operation_1_Source_Schema.snap | 10 ++ ...Plan_Simple_Operation_2_Source_Schema.snap | 17 +++ ...Plan_Simple_Operation_3_Source_Schema.snap | 24 ++++ ...n_3_Source_Schema_And_Single_Variable.snap | 24 ++++ .../__snapshots__/ParsingTests.Test.graphql | 6 - 9 files changed, 104 insertions(+), 117 deletions(-) delete mode 100644 src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/FileResource.cs create mode 100644 src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ModuleInitializer.cs create mode 100644 src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_1_Source_Schema.snap create mode 100644 src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_2_Source_Schema.snap create mode 100644 src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema.snap create mode 100644 src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema_And_Single_Variable.snap delete mode 100644 src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/ParsingTests.Test.graphql diff --git a/src/HotChocolate/Fusion-vnext/test/Directory.Build.props b/src/HotChocolate/Fusion-vnext/test/Directory.Build.props index 16a5e555a9d..7b6055e69a9 100644 --- a/src/HotChocolate/Fusion-vnext/test/Directory.Build.props +++ b/src/HotChocolate/Fusion-vnext/test/Directory.Build.props @@ -7,6 +7,15 @@ true + + + + + + + + + diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/FileResource.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/FileResource.cs deleted file mode 100644 index 59e5ed8de6c..00000000000 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/FileResource.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace HotChocolate.Fusion; - -public static class FileResource -{ - public static string Open(string name) - { - var path = Path.Combine("__resources__", name); - return File.Exists(path) - ? File.ReadAllText(path) - : throw new InvalidOperationException($"The test resource {path} is missing!"); - } -} diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ModuleInitializer.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ModuleInitializer.cs new file mode 100644 index 00000000000..d50f67d0c56 --- /dev/null +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ModuleInitializer.cs @@ -0,0 +1,12 @@ +using System.Runtime.CompilerServices; + +namespace HotChocolate.Fusion; + +internal static class ModuleInitializer +{ + [ModuleInitializer] + public static void Initialize() + { + CookieCrumbleTUnit.Initialize(); + } +} diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs index cf0108a5f5a..31f38aa4ffe 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs @@ -7,7 +7,7 @@ namespace HotChocolate.Fusion; public class OperationPlannerTests { [Test] - public async Task Plan_Simple_Operation_1_Source_Schema() + public void Plan_Simple_Operation_1_Source_Schema() { var compositeSchemaDoc = Utf8GraphQLParser.Parse(FileResource.Open("fusion1.graphql")); var compositeSchema = CompositeSchemaBuilder.Create(compositeSchemaDoc); @@ -34,25 +34,11 @@ fragment Product on Product { var plan = planner.CreatePlan(rewritten, null); // assert - await Assert - .That(plan.Serialize()) - .IsEqualTo( - """ - { - "kind": "Root", - "nodes": [ - { - "kind": "Operation", - "schema": "PRODUCTS", - "document": "{ productById(id: 1) { id name } }" - } - ] - } - """); + plan.Serialize().MatchSnapshot(); } [Test] - public async Task Plan_Simple_Operation_2_Source_Schema() + public void Plan_Simple_Operation_2_Source_Schema() { var compositeSchemaDoc = Utf8GraphQLParser.Parse(FileResource.Open("fusion1.graphql")); var compositeSchema = CompositeSchemaBuilder.Create(compositeSchemaDoc); @@ -80,32 +66,11 @@ fragment Product on Product { var plan = planner.CreatePlan(rewritten, null); // assert - await Assert - .That(plan.Serialize()) - .IsEqualTo( - """ - { - "kind": "Root", - "nodes": [ - { - "kind": "Operation", - "schema": "PRODUCTS", - "document": "{ productById(id: 1) { id name } }", - "nodes": [ - { - "kind": "Operation", - "schema": "SHIPPING", - "document": "{ productById { estimatedDelivery(postCode: \u002212345\u0022) } }" - } - ] - } - ] - } - """); + plan.Serialize().MatchSnapshot(); } [Test] - public async Task Plan_Simple_Operation_3_Source_Schema() + public void Plan_Simple_Operation_3_Source_Schema() { var compositeSchemaDoc = Utf8GraphQLParser.Parse(FileResource.Open("fusion1.graphql")); var compositeSchema = CompositeSchemaBuilder.Create(compositeSchemaDoc); @@ -148,39 +113,11 @@ fragment AuthorCard on UserProfile { var plan = planner.CreatePlan(rewritten, null); // assert - await Assert - .That(plan.Serialize()) - .IsEqualTo( - """ - { - "kind": "Root", - "nodes": [ - { - "kind": "Operation", - "schema": "PRODUCTS", - "document": "{ productById(id: 1) { name } }", - "nodes": [ - { - "kind": "Operation", - "schema": "REVIEWS", - "document": "{ productById { reviews(first: 10) { nodes { body stars author } } } }", - "nodes": [ - { - "kind": "Operation", - "schema": "ACCOUNTS", - "document": "{ userById { displayName } }" - } - ] - } - ] - } - ] - } - """); + plan.Serialize().MatchSnapshot(); } [Test] - public async Task Plan_Simple_Operation_3_Source_Schema_And_Single_Variable() + public void Plan_Simple_Operation_3_Source_Schema_And_Single_Variable() { var compositeSchemaDoc = Utf8GraphQLParser.Parse(FileResource.Open("fusion1.graphql")); var compositeSchema = CompositeSchemaBuilder.Create(compositeSchemaDoc); @@ -223,34 +160,6 @@ fragment AuthorCard on UserProfile { var plan = planner.CreatePlan(rewritten, null); // assert - await Assert - .That(plan.Serialize()) - .IsEqualTo( - """ - { - "kind": "Root", - "nodes": [ - { - "kind": "Operation", - "schema": "PRODUCTS", - "document": "query($id: ID!) { productById(id: $id) { name } }", - "nodes": [ - { - "kind": "Operation", - "schema": "REVIEWS", - "document": "query($first: Int! = 10) { productById { reviews(first: $first) { nodes { body stars author } } } }", - "nodes": [ - { - "kind": "Operation", - "schema": "ACCOUNTS", - "document": "{ userById { displayName } }" - } - ] - } - ] - } - ] - } - """); + plan.Serialize().MatchSnapshot(); } } diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_1_Source_Schema.snap b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_1_Source_Schema.snap new file mode 100644 index 00000000000..806bc9d0564 --- /dev/null +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_1_Source_Schema.snap @@ -0,0 +1,10 @@ +{ + "kind": "Root", + "nodes": [ + { + "kind": "Operation", + "schema": "PRODUCTS", + "document": "{ productById(id: 1) { id name } }" + } + ] +} diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_2_Source_Schema.snap b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_2_Source_Schema.snap new file mode 100644 index 00000000000..471b78c09e2 --- /dev/null +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_2_Source_Schema.snap @@ -0,0 +1,17 @@ +{ + "kind": "Root", + "nodes": [ + { + "kind": "Operation", + "schema": "PRODUCTS", + "document": "{ productById(id: 1) { id name } }", + "nodes": [ + { + "kind": "Operation", + "schema": "SHIPPING", + "document": "{ productById { estimatedDelivery(postCode: \u002212345\u0022) } }" + } + ] + } + ] +} diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema.snap b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema.snap new file mode 100644 index 00000000000..4b3d47f7679 --- /dev/null +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema.snap @@ -0,0 +1,24 @@ +{ + "kind": "Root", + "nodes": [ + { + "kind": "Operation", + "schema": "PRODUCTS", + "document": "{ productById(id: 1) { name } }", + "nodes": [ + { + "kind": "Operation", + "schema": "REVIEWS", + "document": "{ productById { reviews(first: 10) { nodes { body stars author } } } }", + "nodes": [ + { + "kind": "Operation", + "schema": "ACCOUNTS", + "document": "{ userById { displayName } }" + } + ] + } + ] + } + ] +} diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema_And_Single_Variable.snap b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema_And_Single_Variable.snap new file mode 100644 index 00000000000..3beaa618e9a --- /dev/null +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/OperationPlannerTests.Plan_Simple_Operation_3_Source_Schema_And_Single_Variable.snap @@ -0,0 +1,24 @@ +{ + "kind": "Root", + "nodes": [ + { + "kind": "Operation", + "schema": "PRODUCTS", + "document": "query($id: ID!) { productById(id: $id) { name } }", + "nodes": [ + { + "kind": "Operation", + "schema": "REVIEWS", + "document": "query($first: Int! = 10) { productById { reviews(first: $first) { nodes { body stars author } } } }", + "nodes": [ + { + "kind": "Operation", + "schema": "ACCOUNTS", + "document": "{ userById { displayName } }" + } + ] + } + ] + } + ] +} diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/ParsingTests.Test.graphql b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/ParsingTests.Test.graphql deleted file mode 100644 index 1522a3ca4a5..00000000000 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/__snapshots__/ParsingTests.Test.graphql +++ /dev/null @@ -1,6 +0,0 @@ -{ - productById(id: 1) { - id - name - } -} \ No newline at end of file