@@ -14,6 +14,7 @@ public class ConfigureOptionsTests : VerifyBase
1414 private MockFileSystem ? _fileSystem ;
1515 private FileSystemRuntimeConfigLoader ? _runtimeConfigLoader ;
1616 private const string TEST_RUNTIME_CONFIG_FILE = "test-update-runtime-setting.json" ;
17+ private const string TEST_DATASOURCE_HEALTH_NAME = "My Data Source" ;
1718
1819 [ TestInitialize ]
1920 public void TestInitialize ( )
@@ -955,6 +956,102 @@ public void TestFailureWhenAddingSetSessionContextToMySQLDatabase()
955956 }
956957
957958 /// <summary>
959+ /// Tests adding data-source.health.name to a config that doesn't have a health section.
960+ /// This method verifies that the health.name can be added to a data source configuration
961+ /// that doesn't previously have a health section.
962+ /// Command: dab configure --data-source.health.name "My Data Source"
963+ /// </summary>
964+ [ TestMethod ]
965+ public void TestAddDataSourceHealthName ( )
966+ {
967+ // Arrange
968+ SetupFileSystemWithInitialConfig ( INITIAL_CONFIG ) ;
969+
970+ ConfigureOptions options = new (
971+ dataSourceHealthName : TEST_DATASOURCE_HEALTH_NAME ,
972+ config : TEST_RUNTIME_CONFIG_FILE
973+ ) ;
974+
975+ // Act
976+ bool isSuccess = TryConfigureSettings ( options , _runtimeConfigLoader ! , _fileSystem ! ) ;
977+
978+ // Assert
979+ Assert . IsTrue ( isSuccess ) ;
980+ string updatedConfig = _fileSystem ! . File . ReadAllText ( TEST_RUNTIME_CONFIG_FILE ) ;
981+ Assert . IsTrue ( RuntimeConfigLoader . TryParseConfig ( updatedConfig , out RuntimeConfig ? config ) ) ;
982+ Assert . IsNotNull ( config . DataSource ) ;
983+ Assert . IsNotNull ( config . DataSource . Health ) ;
984+ Assert . AreEqual ( TEST_DATASOURCE_HEALTH_NAME , config . DataSource . Health . Name ) ;
985+ Assert . IsTrue ( config . DataSource . Health . Enabled ) ; // Default value
986+ }
987+
988+ /// <summary>
989+ /// Tests updating data-source.health.name on a config that already has a health section.
990+ /// This method verifies that the health.name can be updated while preserving other health settings.
991+ /// Command: dab configure --data-source.health.name "Updated Name"
992+ /// </summary>
993+ [ DataTestMethod ]
994+ [ DataRow ( "New Name" , DisplayName = "Update health name with a simple string" ) ]
995+ [ DataRow ( "This is the value" , DisplayName = "Update health name with the example from the issue" ) ]
996+ public void TestUpdateDataSourceHealthName ( string healthName )
997+ {
998+ // Arrange - Config with existing health section
999+ string configWithHealth = @"
1000+ {
1001+ ""$schema"": ""test"",
1002+ ""data-source"": {
1003+ ""database-type"": ""mssql"",
1004+ ""connection-string"": ""testconnectionstring"",
1005+ ""health"": {
1006+ ""enabled"": false,
1007+ ""threshold-ms"": 2000
1008+ }
1009+ },
1010+ ""runtime"": {
1011+ ""rest"": {
1012+ ""enabled"": true,
1013+ ""path"": ""/api""
1014+ },
1015+ ""graphql"": {
1016+ ""enabled"": true,
1017+ ""path"": ""/graphql"",
1018+ ""allow-introspection"": true
1019+ },
1020+ ""host"": {
1021+ ""mode"": ""development"",
1022+ ""cors"": {
1023+ ""origins"": [],
1024+ ""allow-credentials"": false
1025+ },
1026+ ""authentication"": {
1027+ ""provider"": ""StaticWebApps""
1028+ }
1029+ }
1030+ },
1031+ ""entities"": {}
1032+ }" ;
1033+ SetupFileSystemWithInitialConfig ( configWithHealth ) ;
1034+
1035+ ConfigureOptions options = new (
1036+ dataSourceHealthName : healthName ,
1037+ config : TEST_RUNTIME_CONFIG_FILE
1038+ ) ;
1039+
1040+ // Act
1041+ bool isSuccess = TryConfigureSettings ( options , _runtimeConfigLoader ! , _fileSystem ! ) ;
1042+
1043+ // Assert
1044+ Assert . IsTrue ( isSuccess ) ;
1045+ string updatedConfig = _fileSystem ! . File . ReadAllText ( TEST_RUNTIME_CONFIG_FILE ) ;
1046+ Assert . IsTrue ( RuntimeConfigLoader . TryParseConfig ( updatedConfig , out RuntimeConfig ? config ) ) ;
1047+ Assert . IsNotNull ( config . DataSource ) ;
1048+ Assert . IsNotNull ( config . DataSource . Health ) ;
1049+ Assert . AreEqual ( healthName , config . DataSource . Health . Name ) ;
1050+ // Verify existing health settings are preserved
1051+ Assert . IsFalse ( config . DataSource . Health . Enabled ) ;
1052+ Assert . AreEqual ( 2000 , config . DataSource . Health . ThresholdMs ) ;
1053+ }
1054+
9581055 /// Tests that running "dab configure --runtime.mcp.description {value}" on a config with various values results
9591056 /// in runtime config update. Takes in updated value for mcp.description and
9601057 /// validates whether the runtime config reflects those updated values
0 commit comments