diff --git a/src/Cli/src/ConfigGenerator.cs b/src/Cli/src/ConfigGenerator.cs index d4442c47d3..3f2e690d94 100644 --- a/src/Cli/src/ConfigGenerator.cs +++ b/src/Cli/src/ConfigGenerator.cs @@ -672,9 +672,9 @@ 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 && + 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..4e33255949 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -175,6 +175,49 @@ public void TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure() Assert.IsTrue(JToken.DeepEquals(JObject.Parse(actualConfig), JObject.Parse(File.ReadAllText(_testRuntimeConfig)))); } + /// + /// Validate update command for stored procedures by verifying the config json generated + /// + [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))); + + // 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); + 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. ///