11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- using Azure . DataApiBuilder . Service ;
4+ using Azure . DataApiBuilder . Product ;
5+ using Microsoft . Data . SqlClient ;
6+ using static Azure . DataApiBuilder . Product . ProductInfo ;
57
68namespace Cli . Tests ;
79
@@ -104,11 +106,14 @@ public void TestInitForCosmosDBPostgreSql()
104106 [ TestMethod ]
105107 public void TestInitializingRestAndGraphQLGlobalSettings ( )
106108 {
107- string [ ] args = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" , "--rest.path" , "/rest-api" , "--rest.disabled" , "--graphql.path" , "/graphql-api" } ;
109+ string [ ] args = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--connection-string" , SAMPLE_TEST_CONN_STRING , "-- database-type", "mssql" , "--rest.path" , "/rest-api" , "--rest.disabled" , "--graphql.path" , "/graphql-api" } ;
108110 Program . Execute ( args , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
109111
110112 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
111113
114+ SqlConnectionStringBuilder builder = new ( runtimeConfig . DataSource . ConnectionString ) ;
115+ Assert . AreEqual ( DEFAULT_APP_NAME , builder . ApplicationName ) ;
116+
112117 Assert . IsNotNull ( runtimeConfig ) ;
113118 Assert . AreEqual ( DatabaseType . MSSQL , runtimeConfig . DataSource . DatabaseType ) ;
114119 Assert . IsNotNull ( runtimeConfig . Runtime ) ;
@@ -124,7 +129,7 @@ public void TestInitializingRestAndGraphQLGlobalSettings()
124129 [ TestMethod ]
125130 public void TestAddEntity ( )
126131 {
127- string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--host-mode" , "development" , "--database-type" , "mssql" , "--connection-string" , "localhost:5000" , "--auth.provider" , "StaticWebApps" } ;
132+ string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--host-mode" , "development" , "--database-type" , "mssql" , "--connection-string" , SAMPLE_TEST_CONN_STRING , "--auth.provider" , "StaticWebApps" } ;
128133 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
129134
130135 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
@@ -185,7 +190,7 @@ public void TestVerifyAuthenticationOptions()
185190 [ DataRow ( "prod" , HostMode . Production , false ) ]
186191 public void EnsureHostModeEnumIsCaseInsensitive ( string hostMode , HostMode hostModeEnumType , bool expectSuccess )
187192 {
188- string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--host-mode" , hostMode , "--database-type" , "mssql" , "--connection-string" , "localhost:5000" } ;
193+ string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--host-mode" , hostMode , "--database-type" , "mssql" , "--connection-string" , SAMPLE_TEST_CONN_STRING } ;
189194 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
190195
191196 _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ;
@@ -206,7 +211,7 @@ public void EnsureHostModeEnumIsCaseInsensitive(string hostMode, HostMode hostMo
206211 [ TestMethod ]
207212 public void TestAddEntityWithoutIEnumerable ( )
208213 {
209- string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" , "--connection-string" , "localhost:5000" } ;
214+ string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" , "--connection-string" , SAMPLE_TEST_CONN_STRING } ;
210215 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
211216
212217 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) , "Expected to parse the config file." ) ;
@@ -239,7 +244,7 @@ public void TestAddEntityWithoutIEnumerable()
239244 [ TestMethod ]
240245 public Task TestConfigGeneratedAfterAddingEntityWithoutIEnumerables ( )
241246 {
242- string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" , "--connection-string" , "localhost:5000" ,
247+ string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" , "--connection-string" , SAMPLE_TEST_CONN_STRING ,
243248 "--set-session-context" , "true" } ;
244249 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
245250
@@ -261,7 +266,7 @@ public Task TestConfigGeneratedAfterAddingEntityWithoutIEnumerables()
261266 public Task TestConfigGeneratedAfterAddingEntityWithSourceAsStoredProcedure ( )
262267 {
263268 string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" ,
264- "--host-mode" , "Development" , "--connection-string" , "testconnectionstring" , "--set-session-context" , "true" } ;
269+ "--host-mode" , "Development" , "--connection-string" , SAMPLE_TEST_CONN_STRING , "--set-session-context" , "true" } ;
265270 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
266271
267272 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
@@ -302,7 +307,7 @@ public Task TestConfigGeneratedAfterUpdatingEntityWithSourceAsStoredProcedure()
302307 public Task TestAddingStoredProcedureWithRestMethodsAndGraphQLOperations ( )
303308 {
304309 string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" ,
305- "--host-mode" , "Development" , "--connection-string" , "testconnectionstring" , "--set-session-context" , "true" } ;
310+ "--host-mode" , "Development" , "--connection-string" , SAMPLE_TEST_CONN_STRING , "--set-session-context" , "true" } ;
306311 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
307312
308313 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
@@ -324,7 +329,7 @@ public Task TestAddingStoredProcedureWithRestMethodsAndGraphQLOperations()
324329 public Task TestUpdatingStoredProcedureWithRestMethodsAndGraphQLOperations ( )
325330 {
326331 string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" ,
327- "--host-mode" , "Development" , "--connection-string" , "testconnectionstring" , "--set-session-context" , "true" } ;
332+ "--host-mode" , "Development" , "--connection-string" , SAMPLE_TEST_CONN_STRING , "--set-session-context" , "true" } ;
328333 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
329334
330335 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
@@ -352,7 +357,7 @@ public Task TestUpdatingStoredProcedureWithRestMethodsAndGraphQLOperations()
352357 public Task TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType ( )
353358 {
354359 string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" , "--host-mode" , "Development" ,
355- "--connection-string" , "testconnectionstring" , "--set-session-context" , "true" } ;
360+ "--connection-string" , SAMPLE_TEST_CONN_STRING , "--set-session-context" , "true" } ;
356361 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
357362
358363 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
@@ -374,7 +379,7 @@ public Task TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType()
374379 public void TestUpdateEntity ( )
375380 {
376381 string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" ,
377- "mssql" , "--connection-string" , "localhost:5000" } ;
382+ "mssql" , "--connection-string" , SAMPLE_TEST_CONN_STRING } ;
378383 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
379384
380385 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
@@ -476,7 +481,7 @@ public void TestUpdateEntity()
476481 public Task TestUpdatingStoredProcedureWithRestMethods ( )
477482 {
478483 string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--database-type" , "mssql" ,
479- "--host-mode" , "Development" , "--connection-string" , "testconnectionstring" , "--set-session-context" , "true" } ;
484+ "--host-mode" , "Development" , "--connection-string" , SAMPLE_TEST_CONN_STRING , "--set-session-context" , "true" } ;
480485 Program . Execute ( initArgs , _cliLogger ! , _fileSystem ! , _runtimeConfigLoader ! ) ;
481486
482487 Assert . IsTrue ( _runtimeConfigLoader ! . TryLoadConfig ( TEST_RUNTIME_CONFIG_FILE , out RuntimeConfig ? runtimeConfig ) ) ;
@@ -733,7 +738,7 @@ public async Task TestExitOfRuntimeEngineWithInvalidConfig(
733738 public void TestBaseRouteIsConfigurableForSWA ( string authProvider , bool isExceptionExpected )
734739 {
735740 string [ ] initArgs = { "init" , "-c" , TEST_RUNTIME_CONFIG_FILE , "--host-mode" , "development" , "--database-type" , "mssql" ,
736- "--connection-string" , "localhost:5000" , "--auth.provider" , authProvider , "--runtime.base-route" , "base-route" } ;
741+ "--connection-string" , SAMPLE_TEST_CONN_STRING , "--auth.provider" , authProvider , "--runtime.base-route" , "base-route" } ;
737742
738743 if ( ! Enum . TryParse ( authProvider , ignoreCase : true , out EasyAuthType _ ) )
739744 {
0 commit comments