Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Cli/src/ConfigGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 43 additions & 0 deletions src/Cli/test/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,49 @@ public void TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure()
Assert.IsTrue(JToken.DeepEquals(JObject.Parse(actualConfig), JObject.Parse(File.ReadAllText(_testRuntimeConfig))));
}

/// <summary>
/// Validate update command for stored procedures by verifying the config json generated
/// </summary>
[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"": []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since its a stored procedure, why do we even bother to mention key-fields here?

}";

actualSourceObject = JsonSerializer.Serialize(runtimeConfig.Entities["MyEntity"].Source);
Assert.IsTrue(JToken.DeepEquals(JObject.Parse(expectedSourceObject), JObject.Parse(actualSourceObject)));
}

/// <summary>
/// Test the exact config json generated to verify adding a new Entity with default source type and given key-fields.
/// </summary>
Expand Down