From 80053e20706b12ea8ab07e93bb62d49b76d87947 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Mon, 29 May 2023 23:50:54 +0530 Subject: [PATCH 01/11] adds logic for including pk in db query, tests for sql db types --- .../GraphQLQueryTests/GraphQLQueryTestBase.cs | 112 ++++++++++++++++++ .../Sql Query Structures/SqlQueryStructure.cs | 14 +-- 2 files changed, 119 insertions(+), 7 deletions(-) diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs index 0a01dfa474..8ae4442782 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs @@ -387,6 +387,118 @@ public virtual async Task MultipleResultJoinQuery() SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("items").ToString()); } + /// + /// + /// + [TestMethod] + public async Task TypenameOnlyListQuery() + { + string graphQLQueryName = "books"; + string graphQLQuery = @"{ + books(first: 3) { + items { + __typename + } + }"; + + string expected = @" + [ + { + ""__typename"": ""book"" + }, + { + ""__typename"": ""book"" + }, + { + ""__typename"": ""book"" + } + ]"; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("items").ToString()); + } + + /// + /// + /// + [TestMethod] + public async Task TypenameOnlyListQueryWithoutItemSelection() + { + string graphQLQueryName = "books"; + string graphQLQuery = @"{ + books{ + __typename + } + }"; + + string expected = @" + { + ""__typename"": ""bookConnection"" + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("books").ToString()); + } + + /// + /// + /// + [TestMethod] + public async Task TypenameOnlyPointQuery() + { + string graphQLQueryName = "book_by_pk"; + string graphQLQuery = @"{ + book_by_pk(id: 3) { + __typename + } + }"; + + string expected = @" + { + ""__typename"": ""book"" + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("book_by_pk").ToString()); + } + + /// + /// + /// + [TestMethod] + public async Task TypenameOnlyNestedPointQuery() + { + string graphQLQueryName = "book_by_pk"; + string graphQLQuery = @"{ + book_by_pk(id: 3) { + __typename + publishers { + __typename + books { + __typename + } + } + } + }"; + + string expected = @" + { + ""__typename"": ""book"", + ""publishers"": { + ""__typename"": ""Publisher"", + ""books"": { + ""__typename"": ""bookConnection"" + } + } + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("book_by_pk").ToString()); + } + /// /// Test One-To-One relationship both directions /// (book -> website placement, website placememnt -> book) diff --git a/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs b/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs index 8a7da187ff..644ff9266b 100644 --- a/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs +++ b/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs @@ -395,19 +395,19 @@ private SqlQueryStructure( AddColumnsForEndCursor(); } - // if the user does a paginated query only requesting hasNextPage - // there will be no elements in Columns - if (!Columns.Any()) - { - AddColumn(PrimaryKey()[0]); - } - if (PaginationMetadata.RequestedHasNextPage) { _limit++; } } + // If there are no columns, add the primary key column + // to prevent failures when executing the database query. + if (!Columns.Any()) + { + AddColumn(PrimaryKey()[0]); + } + ParametrizeColumns(); } From f381da9c7448f3abd8feb9463849f7eef363419f Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 30 May 2023 14:58:43 +0530 Subject: [PATCH 02/11] adds query and mutation tests for SQL DB types --- .../GraphQLMutationTestBase.cs | 101 +++++++++++++++ .../MySqlGraphQLMutationTests.cs | 8 ++ .../PostgreSqlGraphQLMutationTests.cs | 8 ++ .../GraphQLQueryTests/GraphQLQueryTestBase.cs | 120 +++++++++++++++++- .../MySqlGraphQLQueryTests.cs | 9 ++ .../PostgreSqlGraphQLQueryTests.cs | 9 ++ 6 files changed, 248 insertions(+), 7 deletions(-) diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs index c3857d331c..6d612e5435 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs @@ -303,6 +303,107 @@ public async Task UpdateMutation(string dbQuery) SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } + /// + /// Do: Update book in database and return the typename of the entity + /// Check: if the mutation executed successfully and returned the correct typename + /// + [TestMethod] + public async Task UpdateMutationWithOnlyTypenameInSelectionSet() + { + string graphQLMutationName = "updatebook"; + string graphQLMutation = @" + mutation { + updatebook(id: 1, item: { title: ""Even Better Title"", publisher_id: 2345} ) { + __typename + } + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true); + string expected = @" + { + ""__typename"": ""book"" + } + "; + + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + } + + /// + /// Do : Delete a book from database and return the typename of the book entity + /// Check :if the mutation executed successfully and returned the correct typename + /// + [TestMethod] + public async Task DeleteMutationWithOnlyTypename() + { + string graphQLMutationName = "deletebook"; + string graphQLMutation = @" + mutation { + deletebook(id: 1) { + __typename + } + } + "; + + string expected = @" + { + ""__typename"": ""book"" + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + } + + /// + /// Do: Inserts a new book in database and returns the typename of the book entity + /// Check: if the mutation executed successfully and returned the correct typename + /// + [TestMethod] + public async Task InsertMutationWithOnlyTypenameInSelectionSet() + { + string graphQLMutationName = "createbook"; + string graphQLMutation = @" + mutation { + createbook(item: { title: ""Awesome Book"", publisher_id: 1234 }) { + __typename + } + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true); + string expected = @" + { + ""__typename"": ""book"" + } + "; + + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + } + + /// + /// Do: Execute a stored procedure and return the typename of the SP entity + /// Check :if the mutation executed successfully and returned the correct typename + /// + public virtual async Task ExecuteMutationWithOnlyTypenameInSelectionSet() + { + string graphQLMutationName = "executeCountBooks"; + string graphQLMutation = @" + executeCountBooks{ + __typename + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true); + string expected = @" + { + ""__typename"": ""CountBooks"" + } + "; + + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + } + /// /// Do: Update Sales in database and return its updated fields /// Check: The calculated column has successfully been updated after updating the other fields diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/MySqlGraphQLMutationTests.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/MySqlGraphQLMutationTests.cs index 4e7019fb1c..a0b25c8349 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/MySqlGraphQLMutationTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/MySqlGraphQLMutationTests.cs @@ -588,6 +588,14 @@ ORDER BY `id` LIMIT 1 await InsertIntoInsertableComplexView(mySqlQuery); } + /// + [TestMethod] + [Ignore] + public override Task ExecuteMutationWithOnlyTypenameInSelectionSet() + { + throw new NotImplementedException(); + } + #endregion #region Negative Tests diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/PostgreSqlGraphQLMutationTests.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/PostgreSqlGraphQLMutationTests.cs index e957fa668e..a17e565b9f 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/PostgreSqlGraphQLMutationTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/PostgreSqlGraphQLMutationTests.cs @@ -577,6 +577,14 @@ ORDER BY id await InsertIntoInsertableComplexView(postgresQuery); } + /// + [TestMethod] + [Ignore] + public override Task ExecuteMutationWithOnlyTypenameInSelectionSet() + { + throw new NotImplementedException(); + } + #endregion #region Negative Tests diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs index 8ae4442782..f139feb83e 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs @@ -388,7 +388,7 @@ public virtual async Task MultipleResultJoinQuery() } /// - /// + /// List query with only __typename field for each entity item /// [TestMethod] public async Task TypenameOnlyListQuery() @@ -398,6 +398,7 @@ public async Task TypenameOnlyListQuery() books(first: 3) { items { __typename + } } }"; @@ -419,7 +420,7 @@ public async Task TypenameOnlyListQuery() } /// - /// + /// List query with only __typename field without selecting any entity item /// [TestMethod] public async Task TypenameOnlyListQueryWithoutItemSelection() @@ -438,11 +439,35 @@ public async Task TypenameOnlyListQueryWithoutItemSelection() "; JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("books").ToString()); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + } + + /// + /// List query with only __typename field without selecting any entity item on a table + /// with composite primary key + /// + [TestMethod] + public async Task TypenameOnlyListQueryWithoutItemSelectionWithCompositePK() + { + string graphQLQueryName = "stocks"; + string graphQLQuery = @"{ + stocks{ + __typename + } + }"; + + string expected = @" + { + ""__typename"": ""StockConnection"" + } + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: true); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } /// - /// + /// Point query with only __typename field in the selection set /// [TestMethod] public async Task TypenameOnlyPointQuery() @@ -461,11 +486,11 @@ public async Task TypenameOnlyPointQuery() "; JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("book_by_pk").ToString()); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } /// - /// + /// Nested point query with only __typename field at each level /// [TestMethod] public async Task TypenameOnlyNestedPointQuery() @@ -496,7 +521,88 @@ public async Task TypenameOnlyNestedPointQuery() "; JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("book_by_pk").ToString()); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + } + + /// + /// List query with only __typename field on a stored procedure + /// + public virtual async Task TypenameOnlyQueryWithSP() + { + string graphQLQueryName = "executeGetBooks"; + string graphQLQuery = @"{ + executeGetBooks{ + __typename + } + }"; + + string expected = @" + [ + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + }, + { + ""__typename"": ""GetBooks"" + } + ] + "; + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } /// diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs index febd447979..201d6295e1 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System; using System.Threading.Tasks; using Azure.DataApiBuilder.Config; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -491,6 +492,14 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( TestCategory.MYSQL); } + [TestMethod] + [Ignore] + /// + public override Task TypenameOnlyQueryWithSP() + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs index c98e01e6ac..a1b33a0030 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System; using System.Threading.Tasks; using Azure.DataApiBuilder.Config; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -369,6 +370,14 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( TestCategory.POSTGRESQL); } + [TestMethod] + [Ignore] + /// + public override Task TypenameOnlyQueryWithSP() + { + throw new NotImplementedException(); + } + #endregion } } From 748bcb85d9b6a961ec9d05cdf7105c6d92edcab2 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 30 May 2023 15:39:52 +0530 Subject: [PATCH 03/11] adds sp tests in mssql test class --- .../GraphQLMutationTests/MsSqlGraphQLMutationTests.cs | 10 ++++++++++ .../GraphQLQueryTests/MsSqlGraphQLQueryTests.cs | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/MsSqlGraphQLMutationTests.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/MsSqlGraphQLMutationTests.cs index 27eb30ba1d..0fcd3cfaa2 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/MsSqlGraphQLMutationTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/MsSqlGraphQLMutationTests.cs @@ -676,6 +676,16 @@ ORDER BY [id] await InsertIntoInsertableComplexView(msSqlQuery); } + /// + /// Do: Execute a stored procedure and return the typename of the SP entity + /// Check :if the mutation executed successfully and returned the correct typename + /// + [TestMethod] + public async override Task ExecuteMutationWithOnlyTypenameInSelectionSet() + { + await base.ExecuteMutationWithOnlyTypenameInSelectionSet(); + } + #endregion #region Negative Tests diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs index 2d3e69e47d..2a3367fa71 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs @@ -366,6 +366,15 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( TestCategory.MSSQL); } + /// + /// List query with only __typename field on a stored procedure + /// + [TestMethod] + public override async Task TypenameOnlyQueryWithSP() + { + await base.TypenameOnlyQueryWithSP(); + } + #endregion } } From 75cd8aa5b23159ccec0db3ed29423d5b2d82b1e2 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 30 May 2023 18:42:52 +0530 Subject: [PATCH 04/11] adds cosmos tests --- .../CosmosTests/MutationTests.cs | 71 +++++++++++++++++++ src/Service.Tests/CosmosTests/QueryTests.cs | 20 ++++++ 2 files changed, 91 insertions(+) diff --git a/src/Service.Tests/CosmosTests/MutationTests.cs b/src/Service.Tests/CosmosTests/MutationTests.cs index 2028b6f475..c11b694a64 100644 --- a/src/Service.Tests/CosmosTests/MutationTests.cs +++ b/src/Service.Tests/CosmosTests/MutationTests.cs @@ -321,6 +321,77 @@ public async Task UpdateItemWithUnauthorizedWildCardReturnsError() Assert.IsTrue(errorMessage.Contains(DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE)); } + /// + /// Executes a create mutation with only __typename in the selection set. Validates that + /// the right type is returned. + /// + [TestMethod] + public async Task CreateMutationWithOnlyTypenameInSelectionSet() + { + string graphQLMutation = @" + mutation ($item: CreatePlanetInput!) { + createPlanet (item: $item) { + __typename + } + }"; + + // Construct the inputs required for the mutation + string id = Guid.NewGuid().ToString(); + var input = new + { + id, + name = "test_name", + stars = new[] { new { id = "TestStar" } } + }; + JsonElement response = await ExecuteGraphQLRequestAsync("createPlanet", graphQLMutation, new() { { "item", input } }); + + // Validate results + string expected = @"Planet"; + string actual = response.GetProperty("__typename").Deserialize(); + Assert.AreEqual(expected, actual); + } + + /// + /// Executes an update mutation with only __typename in the selection set. Validates that + /// the right type is returned. + /// + [TestMethod] + public async Task UpdateMutationWithOnlyTypenameInSelectionSet() + { + // Create the item with a known id to execute an update mutation against it + string id = Guid.NewGuid().ToString(); + var input = new + { + id, + name = "test_name" + }; + + _ = await ExecuteGraphQLRequestAsync("createPlanet", _createPlanetMutation, new() { { "item", input } }); + + string mutation = @" + mutation ($id: ID!, $partitionKeyValue: String!, $item: UpdatePlanetInput!) { + updatePlanet (id: $id, _partitionKeyValue: $partitionKeyValue, item: $item) { + __typename + } + }"; + + // Construct the inputs required for the update mutation + var update = new + { + id, + name = "new_name", + stars = new[] { new { id = "TestStar" } } + }; + + // Execute the update mutation + JsonElement response = await ExecuteGraphQLRequestAsync("updatePlanet", mutation, variables: new() { { "id", id }, { "partitionKeyValue", id }, { "item", update } }); + + // Validate results + string expected = @"Planet"; + string actual = response.GetProperty("__typename").Deserialize(); + Assert.AreEqual(expected, actual); + } + /// /// Runs once after all tests in this class are executed /// diff --git a/src/Service.Tests/CosmosTests/QueryTests.cs b/src/Service.Tests/CosmosTests/QueryTests.cs index 3d1db9e186..c79360ecc3 100644 --- a/src/Service.Tests/CosmosTests/QueryTests.cs +++ b/src/Service.Tests/CosmosTests/QueryTests.cs @@ -126,6 +126,26 @@ public async Task GetListOfString() CollectionAssert.AreEqual(new[] { "tag1", "tag2" }, tags); } + /// + /// Executes a query with only __typename in the selection set. Validates that + /// the right type is returned. + /// + [TestMethod] + public async Task QueryWithOnlyTypenameInSelectionSet() + { + string id = _idList[0]; + JsonElement response = await ExecuteGraphQLRequestAsync("planet_by_pk", @" + query ($id: ID, $partitionKeyValue: String) { + planet_by_pk (id: $id, _partitionKeyValue: $partitionKeyValue) { + __typename + } + }", new() { { "id", id }, { "partitionKeyValue", id } }); + + string expected = @"Planet"; + string actual = response.GetProperty("__typename").Deserialize(); + Assert.AreEqual(expected, actual); + } + [TestMethod] public async Task GetPaginatedWithVariables() { From 019bab484bd7ade9324d474d8c17e639bb41804f Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 30 May 2023 19:13:53 +0530 Subject: [PATCH 05/11] renaming test names, updating test summaries --- .../CosmosTests/MutationTests.cs | 8 ++--- src/Service.Tests/CosmosTests/QueryTests.cs | 4 +-- .../GraphQLQueryTests/GraphQLQueryTestBase.cs | 30 +++++++++++-------- .../MsSqlGraphQLQueryTests.cs | 8 ++--- .../MySqlGraphQLQueryTests.cs | 2 +- .../PostgreSqlGraphQLQueryTests.cs | 2 +- 6 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Service.Tests/CosmosTests/MutationTests.cs b/src/Service.Tests/CosmosTests/MutationTests.cs index c11b694a64..6c70f460d6 100644 --- a/src/Service.Tests/CosmosTests/MutationTests.cs +++ b/src/Service.Tests/CosmosTests/MutationTests.cs @@ -322,8 +322,8 @@ public async Task UpdateItemWithUnauthorizedWildCardReturnsError() } /// - /// Executes a create mutation with only __typename in the selection set. Validates that - /// the right type is returned. + /// Validates that a create mutation with only __typename in the selection set returns the + /// right type /// [TestMethod] public async Task CreateMutationWithOnlyTypenameInSelectionSet() @@ -352,8 +352,8 @@ public async Task CreateMutationWithOnlyTypenameInSelectionSet() } /// - /// Executes an update mutation with only __typename in the selection set. Validates that - /// the right type is returned. + /// Validates that an update mutation with only __typename in the selection set returns the + /// right type /// [TestMethod] public async Task UpdateMutationWithOnlyTypenameInSelectionSet() diff --git a/src/Service.Tests/CosmosTests/QueryTests.cs b/src/Service.Tests/CosmosTests/QueryTests.cs index c79360ecc3..7c21e342d2 100644 --- a/src/Service.Tests/CosmosTests/QueryTests.cs +++ b/src/Service.Tests/CosmosTests/QueryTests.cs @@ -127,8 +127,8 @@ public async Task GetListOfString() } /// - /// Executes a query with only __typename in the selection set. Validates that - /// the right type is returned. + /// Validates that a query with only __typename in the selection set + /// returns the right type /// [TestMethod] public async Task QueryWithOnlyTypenameInSelectionSet() diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs index f139feb83e..e8bdde4427 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs @@ -388,10 +388,10 @@ public virtual async Task MultipleResultJoinQuery() } /// - /// List query with only __typename field for each entity item + /// Validates that a list query with only __typename field in the items section returns the right types /// [TestMethod] - public async Task TypenameOnlyListQuery() + public async Task ListQueryWithOnlyTypenameInSelectionSet() { string graphQLQueryName = "books"; string graphQLQuery = @"{ @@ -420,10 +420,11 @@ public async Task TypenameOnlyListQuery() } /// - /// List query with only __typename field without selecting any entity item + /// Validates that a list query with only __typename in the selection set + /// returns the right types /// [TestMethod] - public async Task TypenameOnlyListQueryWithoutItemSelection() + public async Task ListQueryWithoutItemSelectionButWithTypename() { string graphQLQueryName = "books"; string graphQLQuery = @"{ @@ -443,11 +444,11 @@ public async Task TypenameOnlyListQueryWithoutItemSelection() } /// - /// List query with only __typename field without selecting any entity item on a table - /// with composite primary key + /// Validates that a list query against a table with composite Pk + /// with only __typename in the selection set returns the right types /// [TestMethod] - public async Task TypenameOnlyListQueryWithoutItemSelectionWithCompositePK() + public async Task ListQueryWithoutItemSelectionButOnlyTypenameAgainstTableWithCompositePK() { string graphQLQueryName = "stocks"; string graphQLQuery = @"{ @@ -467,10 +468,11 @@ public async Task TypenameOnlyListQueryWithoutItemSelectionWithCompositePK() } /// - /// Point query with only __typename field in the selection set + /// Validates that a point query with only __typename field in the selection set + /// returns the right type /// [TestMethod] - public async Task TypenameOnlyPointQuery() + public async Task PointQueryWithTypenameInSelectionSet() { string graphQLQueryName = "book_by_pk"; string graphQLQuery = @"{ @@ -490,10 +492,11 @@ public async Task TypenameOnlyPointQuery() } /// - /// Nested point query with only __typename field at each level + /// Validates that a nested point query with only __typename field in each selection set + /// returns the right types /// [TestMethod] - public async Task TypenameOnlyNestedPointQuery() + public async Task NestedPointQueryWithOnlyTypenameInEachSelectionSet() { string graphQLQueryName = "book_by_pk"; string graphQLQuery = @"{ @@ -525,9 +528,10 @@ public async Task TypenameOnlyNestedPointQuery() } /// - /// List query with only __typename field on a stored procedure + /// Validates that querying a SP with only __typename field in the selection set + /// returns the right type(s) /// - public virtual async Task TypenameOnlyQueryWithSP() + public virtual async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() { string graphQLQueryName = "executeGetBooks"; string graphQLQuery = @"{ diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs index 2a3367fa71..ca35035e87 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs @@ -366,13 +366,11 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( TestCategory.MSSQL); } - /// - /// List query with only __typename field on a stored procedure - /// + /// > [TestMethod] - public override async Task TypenameOnlyQueryWithSP() + public override async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() { - await base.TypenameOnlyQueryWithSP(); + await base.QueryAgainstSPWithOnlyTypenameInSelectionSet(); } #endregion diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs index 201d6295e1..314dc1102f 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs @@ -495,7 +495,7 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( [TestMethod] [Ignore] /// - public override Task TypenameOnlyQueryWithSP() + public override Task QueryAgainstSPWithOnlyTypenameInSelectionSet() { throw new NotImplementedException(); } diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs index a1b33a0030..812baea3a0 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs @@ -373,7 +373,7 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( [TestMethod] [Ignore] /// - public override Task TypenameOnlyQueryWithSP() + public override Task QueryAgainstSPWithOnlyTypenameInSelectionSet() { throw new NotImplementedException(); } From 213cb110cc6c10b88d634b3d3b7f009edf0e337b Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 30 May 2023 20:02:19 +0530 Subject: [PATCH 06/11] updating sp tests to read the right property --- .../SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs | 2 +- .../SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs index 6d612e5435..841348420e 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs @@ -401,7 +401,7 @@ public virtual async Task ExecuteMutationWithOnlyTypenameInSelectionSet() } "; - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("executeCountBooks").ToString()); } /// diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs index e8bdde4427..49e1a65e95 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs @@ -606,7 +606,7 @@ public virtual async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() "; JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("executeGetBooks").ToString()); } /// From d8a44962fcf5372758b784e951cd9e83e72801f7 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 6 Jun 2023 18:46:46 +0530 Subject: [PATCH 07/11] print response in sp to determine the type --- .../GraphQLMutationTests/GraphQLMutationTestBase.cs | 11 +++++++---- .../GraphQLQueryTests/GraphQLQueryTestBase.cs | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs index 841348420e..72d77fdb79 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs @@ -396,12 +396,15 @@ public virtual async Task ExecuteMutationWithOnlyTypenameInSelectionSet() JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true); string expected = @" - { - ""__typename"": ""CountBooks"" - } + [ + { + ""__typename"": ""CountBooks"" + } + ] "; - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("executeCountBooks").ToString()); + System.Console.WriteLine(actual.ToString()); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } /// diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs index 49e1a65e95..599634fc2c 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs @@ -606,7 +606,8 @@ public virtual async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() "; JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("executeGetBooks").ToString()); + System.Console.WriteLine(actual.ToString()); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } /// From 2c6206869d9bb4b9aed1777e3b531199bf0b262e Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 6 Jun 2023 19:18:16 +0530 Subject: [PATCH 08/11] another shot at fixing tests --- .../GraphQLMutationTestBase.cs | 6 +++-- .../GraphQLQueryTests/GraphQLQueryTestBase.cs | 22 +------------------ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs index 72d77fdb79..547017afe8 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs @@ -389,8 +389,10 @@ public virtual async Task ExecuteMutationWithOnlyTypenameInSelectionSet() { string graphQLMutationName = "executeCountBooks"; string graphQLMutation = @" - executeCountBooks{ - __typename + mutation { + executeCountBooks{ + __typename + } } "; diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs index 599634fc2c..dc45810fdd 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs @@ -581,32 +581,12 @@ public virtual async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() { ""__typename"": ""GetBooks"" }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, { ""__typename"": ""GetBooks"" } - ] - "; + ]"; JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); - System.Console.WriteLine(actual.ToString()); SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } From 66eaf1da3ce3fdafb928f9079ac02ccfe4fb5df2 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Tue, 6 Jun 2023 19:59:06 +0530 Subject: [PATCH 09/11] removes console write stmt --- .../SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs index 547017afe8..c03678d354 100644 --- a/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLMutationTests/GraphQLMutationTestBase.cs @@ -405,7 +405,6 @@ public virtual async Task ExecuteMutationWithOnlyTypenameInSelectionSet() ] "; - System.Console.WriteLine(actual.ToString()); SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } From 50504a3f01725e3780b72c31990ea485c9f710ce Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Mon, 3 Jul 2023 16:39:36 +0530 Subject: [PATCH 10/11] adds logic to generate responses in test dynamically --- .../GraphQLQueryTests/GraphQLQueryTestBase.cs | 115 ++++++------------ .../MsSqlGraphQLQueryTests.cs | 5 +- .../MySqlGraphQLQueryTests.cs | 9 -- .../PostgreSqlGraphQLQueryTests.cs | 9 -- src/Service.Tests/SqlTests/SqlTestHelper.cs | 24 ++++ 5 files changed, 64 insertions(+), 98 deletions(-) diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs index 2b6ae7faa4..d2550ac13d 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs @@ -387,38 +387,6 @@ public virtual async Task MultipleResultJoinQuery() SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("items").ToString()); } - /// - /// Validates that a list query with only __typename field in the items section returns the right types - /// - [TestMethod] - public async Task ListQueryWithOnlyTypenameInSelectionSet() - { - string graphQLQueryName = "books"; - string graphQLQuery = @"{ - books(first: 3) { - items { - __typename - } - } - }"; - - string expected = @" - [ - { - ""__typename"": ""book"" - }, - { - ""__typename"": ""book"" - }, - { - ""__typename"": ""book"" - } - ]"; - - JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); - SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("items").ToString()); - } - /// /// Validates that a list query with only __typename in the selection set /// returns the right types @@ -491,6 +459,35 @@ public async Task PointQueryWithTypenameInSelectionSet() SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } + /// + /// Validates that a list query with only __typename field in the items section returns the right types + /// + [TestMethod] + public async Task ListQueryWithOnlyTypenameInSelectionSet() + { + string graphQLQueryName = "books"; + string graphQLQuery = @"{ + books(first: 3) { + items { + __typename + } + } + }"; + + string typename = @" + { + ""__typename"": ""book"" + } + "; + + // Since the first 3 elements are fetched, we expect the response to contain 3 items + // with just the __typename field. + string expected = SqlTestHelper.ConstructGQLTypenameResponseNTimes(typename: typename, times: 3); + + JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); + SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("items").ToString()); + } + /// /// Validates that a nested point query with only __typename field in each selection set /// returns the right types @@ -531,7 +528,7 @@ public async Task NestedPointQueryWithOnlyTypenameInEachSelectionSet() /// Validates that querying a SP with only __typename field in the selection set /// returns the right type(s) /// - public virtual async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() + public async Task QueryAgainstSPWithOnlyTypenameInSelectionSet(string dbQuery) { string graphQLQueryName = "executeGetBooks"; string graphQLQuery = @"{ @@ -540,52 +537,14 @@ public virtual async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() } }"; - string expected = @" - [ - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - }, - { - ""__typename"": ""GetBooks"" - } - ]"; + string typename = @" + { + ""__typename"": ""GetBooks"" + }"; + string bookCountFromDB = await GetDatabaseResultAsync(dbQuery, expectJson: false); + int expectedCount = JsonSerializer.Deserialize>>(bookCountFromDB)[0]["count"]; + string expected = SqlTestHelper.ConstructGQLTypenameResponseNTimes(typename: typename, times: expectedCount); JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false); SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString()); } diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs index 4b68e2a2c5..c1d2f255e1 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/MsSqlGraphQLQueryTests.cs @@ -368,9 +368,10 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( /// > [TestMethod] - public override async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() + public async Task QueryAgainstSPWithOnlyTypenameInSelectionSet() { - await base.QueryAgainstSPWithOnlyTypenameInSelectionSet(); + string dbQuery = "select count(*) as count from books"; + await base.QueryAgainstSPWithOnlyTypenameInSelectionSet(dbQuery); } #endregion diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs index 412db71869..d07c18ad3e 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/MySqlGraphQLQueryTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System; using System.Threading.Tasks; using Azure.DataApiBuilder.Config.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -492,14 +491,6 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( TestCategory.MYSQL); } - [TestMethod] - [Ignore] - /// - public override Task QueryAgainstSPWithOnlyTypenameInSelectionSet() - { - throw new NotImplementedException(); - } - #endregion } } diff --git a/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs b/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs index 4e96c0d307..73d7e7540d 100644 --- a/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs +++ b/src/Service.Tests/SqlTests/GraphQLQueryTests/PostgreSqlGraphQLQueryTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System; using System.Threading.Tasks; using Azure.DataApiBuilder.Config.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -370,14 +369,6 @@ await TestConfigTakesPrecedenceForRelationshipFieldsOverDB( TestCategory.POSTGRESQL); } - [TestMethod] - [Ignore] - /// - public override Task QueryAgainstSPWithOnlyTypenameInSelectionSet() - { - throw new NotImplementedException(); - } - #endregion } } diff --git a/src/Service.Tests/SqlTests/SqlTestHelper.cs b/src/Service.Tests/SqlTests/SqlTestHelper.cs index f4675a436d..2fd72f2f3a 100644 --- a/src/Service.Tests/SqlTests/SqlTestHelper.cs +++ b/src/Service.Tests/SqlTests/SqlTestHelper.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Http; using System.Reflection; +using System.Text; using System.Text.Json; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -305,6 +306,29 @@ public static SqlException CreateSqlException(int number, string message = "") return e; } + /// + /// Helper method to construct GraphQL responses when only __typename is queried + /// + /// A json string of the format { __typename : entity_typename } + /// Number of times to repeat typename in the response + /// An string representation of an array of typename json strings + public static string ConstructGQLTypenameResponseNTimes(string typename, int times) + { + StringBuilder typenameResponseBuilder = new("["); + for (int i = 0; i < times; i++) + { + typenameResponseBuilder.Append(typename); + if (i != times - 1) + { + typenameResponseBuilder.Append(","); + } + + } + + typenameResponseBuilder.Append("]"); + return typenameResponseBuilder.ToString(); + } + /// /// For testing we use a JSON string that represents /// the runtime config that would otherwise be generated From 152bdf3f8b9d60e853a62f7694c36769e1692c8e Mon Sep 17 00:00:00 2001 From: Aniruddh Munde Date: Mon, 3 Jul 2023 13:56:34 -0700 Subject: [PATCH 11/11] Update src/Service.Tests/SqlTests/SqlTestHelper.cs Typo --- src/Service.Tests/SqlTests/SqlTestHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service.Tests/SqlTests/SqlTestHelper.cs b/src/Service.Tests/SqlTests/SqlTestHelper.cs index 2fd72f2f3a..70f69bc3a6 100644 --- a/src/Service.Tests/SqlTests/SqlTestHelper.cs +++ b/src/Service.Tests/SqlTests/SqlTestHelper.cs @@ -311,7 +311,7 @@ public static SqlException CreateSqlException(int number, string message = "") /// /// A json string of the format { __typename : entity_typename } /// Number of times to repeat typename in the response - /// An string representation of an array of typename json strings + /// A string representation of an array of typename json strings public static string ConstructGQLTypenameResponseNTimes(string typename, int times) { StringBuilder typenameResponseBuilder = new("[");