From c27f02a6112b68d0a7ba58304dccbbc3301c9f3c Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 21 Nov 2022 10:41:03 +0530 Subject: [PATCH 1/6] fix update source --- src/Cli/src/ConfigGenerator.cs | 2 +- src/Cli/test/EndToEndTests.cs | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Cli/src/ConfigGenerator.cs b/src/Cli/src/ConfigGenerator.cs index d4442c47d3..382d485daf 100644 --- a/src/Cli/src/ConfigGenerator.cs +++ b/src/Cli/src/ConfigGenerator.cs @@ -674,7 +674,7 @@ private static bool TryGetUpdatedSourceObjectWithOptions( // If given SourceParameter is null, no update is required. // Else updatedSourceParameters will contain the parsed dictionary of parameters. - if (options.SourceParameters is not null && + if (options.SourceParameters is not null && options.SourceParameters.Any() && !TryParseSourceParameterDictionary(options.SourceParameters, out updatedSourceParameters)) { return false; diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index e1865ac45a..a2415e5f9d 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -175,6 +175,47 @@ public void TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure() Assert.IsTrue(JToken.DeepEquals(JObject.Parse(actualConfig), JObject.Parse(File.ReadAllText(_testRuntimeConfig)))); } + /// + /// Test the exact config json generated to verify adding source as stored-procedure. + /// + [TestMethod] + public void TestConfigGeneratedAfterUpdatingEntityWithSourceAsStoredProcedure() + { + string? runtimeConfigJson = AddPropertiesToJson(INITIAL_CONFIG, SINGLE_ENTITY_WITH_STORED_PROCEDURE); + WriteJsonContentToFile(_testRuntimeConfig, runtimeConfigJson); + RuntimeConfig? runtimeConfig = TryGetRuntimeConfig(_testRuntimeConfig); + Assert.IsNotNull(runtimeConfig); + string expectedSourceObject = @"{ + ""type"": ""stored-procedure"", + ""object"": ""s001.book"", + ""parameters"": { + ""param1"": 123, + ""param2"": ""hello"", + ""param3"": true + } + }"; + + string actualSourceObject = JsonSerializer.Serialize(runtimeConfig.Entities["MyEntity"].Source); + Assert.IsTrue(JToken.DeepEquals(JObject.Parse(expectedSourceObject), JObject.Parse(actualSourceObject))); + string[] updateArgs = { "update", "MyEntity", "-c", _testRuntimeConfig, "--source", "dbo.books"}; + Program.Main(updateArgs); + runtimeConfig = TryGetRuntimeConfig(_testRuntimeConfig); + Assert.IsNotNull(runtimeConfig); + expectedSourceObject = @"{ + ""type"": ""stored-procedure"", + ""object"": ""dbo.books"", + ""parameters"": { + ""param1"": 123, + ""param2"": ""hello"", + ""param3"": true + }, + ""key-fields"": [] + }"; + + actualSourceObject = JsonSerializer.Serialize(runtimeConfig.Entities["MyEntity"].Source); + Assert.IsTrue(JToken.DeepEquals(JObject.Parse(expectedSourceObject), JObject.Parse(actualSourceObject))); + } + /// /// Test the exact config json generated to verify adding a new Entity with default source type and given key-fields. /// From fcd761793c9b7f80d017b2a83378bb2d5e6f8785 Mon Sep 17 00:00:00 2001 From: abhishekkumams <102276754+abhishekkumams@users.noreply.github.com> Date: Mon, 21 Nov 2022 10:57:27 +0530 Subject: [PATCH 2/6] Update EndToEndTests.cs --- src/Cli/test/EndToEndTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index a2415e5f9d..96d36ac269 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -176,7 +176,7 @@ public void TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure() } /// - /// Test the exact config json generated to verify adding source as stored-procedure. + /// Test the exact config json is generated to verify updating source as stored-procedure. /// [TestMethod] public void TestConfigGeneratedAfterUpdatingEntityWithSourceAsStoredProcedure() From f8d5c4d09349fa38f3ad877dfbbed163bb3a2cfc Mon Sep 17 00:00:00 2001 From: abhishekkumams <102276754+abhishekkumams@users.noreply.github.com> Date: Mon, 21 Nov 2022 10:58:30 +0530 Subject: [PATCH 3/6] Update EndToEndTests.cs --- src/Cli/test/EndToEndTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index 96d36ac269..bd63b17b44 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -197,6 +197,8 @@ public void TestConfigGeneratedAfterUpdatingEntityWithSourceAsStoredProcedure() string actualSourceObject = JsonSerializer.Serialize(runtimeConfig.Entities["MyEntity"].Source); Assert.IsTrue(JToken.DeepEquals(JObject.Parse(expectedSourceObject), JObject.Parse(actualSourceObject))); + + // args for update command to update the source name from "s001.book" to "dbo.books" string[] updateArgs = { "update", "MyEntity", "-c", _testRuntimeConfig, "--source", "dbo.books"}; Program.Main(updateArgs); runtimeConfig = TryGetRuntimeConfig(_testRuntimeConfig); From 91922df8fc0d6a235cf4fd3cb9e46965f301e6b4 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 21 Nov 2022 11:02:30 +0530 Subject: [PATCH 4/6] fix formatting --- src/Cli/test/EndToEndTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index bd63b17b44..56192db882 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -197,9 +197,9 @@ public void TestConfigGeneratedAfterUpdatingEntityWithSourceAsStoredProcedure() string actualSourceObject = JsonSerializer.Serialize(runtimeConfig.Entities["MyEntity"].Source); Assert.IsTrue(JToken.DeepEquals(JObject.Parse(expectedSourceObject), JObject.Parse(actualSourceObject))); - + // args for update command to update the source name from "s001.book" to "dbo.books" - string[] updateArgs = { "update", "MyEntity", "-c", _testRuntimeConfig, "--source", "dbo.books"}; + string[] updateArgs = { "update", "MyEntity", "-c", _testRuntimeConfig, "--source", "dbo.books" }; Program.Main(updateArgs); runtimeConfig = TryGetRuntimeConfig(_testRuntimeConfig); Assert.IsNotNull(runtimeConfig); From c694ce27b0033582b4beeeb851e58e329dc415a6 Mon Sep 17 00:00:00 2001 From: abhishekkumams <102276754+abhishekkumams@users.noreply.github.com> Date: Mon, 21 Nov 2022 11:11:33 +0530 Subject: [PATCH 5/6] updating comments --- src/Cli/src/ConfigGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/src/ConfigGenerator.cs b/src/Cli/src/ConfigGenerator.cs index 382d485daf..3f2e690d94 100644 --- a/src/Cli/src/ConfigGenerator.cs +++ b/src/Cli/src/ConfigGenerator.cs @@ -672,7 +672,7 @@ private static bool TryGetUpdatedSourceObjectWithOptions( updatedSourceParameters = null; } - // If given SourceParameter is null, no update is required. + // If given SourceParameter is null or is Empty, no update is required. // Else updatedSourceParameters will contain the parsed dictionary of parameters. if (options.SourceParameters is not null && options.SourceParameters.Any() && !TryParseSourceParameterDictionary(options.SourceParameters, out updatedSourceParameters)) From ec276035f8facc66ca08c99c30883dc079e672b1 Mon Sep 17 00:00:00 2001 From: abhishekkumams <102276754+abhishekkumams@users.noreply.github.com> Date: Mon, 21 Nov 2022 11:22:32 +0530 Subject: [PATCH 6/6] Update test summary Co-authored-by: Shyam Sundar J --- src/Cli/test/EndToEndTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index 56192db882..4e33255949 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -176,7 +176,7 @@ public void TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure() } /// - /// Test the exact config json is generated to verify updating source as stored-procedure. + /// Validate update command for stored procedures by verifying the config json generated /// [TestMethod] public void TestConfigGeneratedAfterUpdatingEntityWithSourceAsStoredProcedure()