@@ -49,7 +49,7 @@ public HostJsonFileConfigurationSourceTests()
4949 }
5050
5151 [ Fact ]
52- public void MissingHostJson_CreatesHostJson_withDefaultExtensionBundleId ( )
52+ public void MissingHostJson_GeneratesExpectedDefaultConfigFile ( )
5353 {
5454 Assert . False ( File . Exists ( _hostJsonFile ) ) ;
5555 TestMetricsLogger testMetricsLogger = new TestMetricsLogger ( ) ;
@@ -58,14 +58,17 @@ public void MissingHostJson_CreatesHostJson_withDefaultExtensionBundleId()
5858
5959 AreExpectedMetricsGenerated ( testMetricsLogger ) ;
6060
61+ // verify actual file content
6162 Assert . Equal ( _hostJsonWithBundles , File . ReadAllText ( _hostJsonFile ) ) ;
6263
63- var log = _loggerProvider . GetAllLogMessages ( ) . Single ( l => l . FormattedMessage == "No host configuration file found. Creating a default host.json file." ) ;
64- Assert . Equal ( LogLevel . Information , log . Level ) ;
64+ // verify log messages
65+ var logs = _loggerProvider . GetAllLogMessages ( ) ;
66+ Assert . Single ( logs . Where ( l => l . Level == LogLevel . Information && l . FormattedMessage == "No host configuration file found. Creating a default host.json file." ) ) ;
67+ VerifySanitizedHostConfigLog ( logs , ScriptConstants . DefaultExtensionBundleId , ScriptConstants . DefaultExtensionBundleVersion ) ;
6568 }
6669
6770 [ Fact ]
68- public void MissingHostJson_CreatesHostJson_withWorkFlowExtensionBundleId ( )
71+ public void MissingHostJson_WorkflowApp_GeneratesExpectedDefaultConfigFile ( )
6972 {
7073 var environment = new TestEnvironment ( new Dictionary < string , string >
7174 {
@@ -79,10 +82,13 @@ public void MissingHostJson_CreatesHostJson_withWorkFlowExtensionBundleId()
7982
8083 AreExpectedMetricsGenerated ( testMetricsLogger ) ;
8184
85+ // verify actual file content
8286 Assert . Equal ( _hostJsonWithWorkFlowBundle , File . ReadAllText ( _hostJsonFile ) ) ;
8387
84- var log = _loggerProvider . GetAllLogMessages ( ) . Single ( l => l . FormattedMessage == "No host configuration file found. Creating a default host.json file." ) ;
85- Assert . Equal ( LogLevel . Information , log . Level ) ;
88+ // verify log messages
89+ var logs = _loggerProvider . GetAllLogMessages ( ) ;
90+ Assert . Single ( logs . Where ( l => l . Level == LogLevel . Information && l . FormattedMessage == "No host configuration file found. Creating a default host.json file." ) ) ;
91+ VerifySanitizedHostConfigLog ( logs , ScriptConstants . WorkFlowExtensionBundleId , ScriptConstants . LogicAppDefaultExtensionBundleVersion ) ;
8692 }
8793
8894 [ Theory ]
@@ -279,5 +285,21 @@ private bool AreExpectedMetricsGenerated(TestMetricsLogger metricsLogger)
279285 && metricsLogger . EventsBegan . Contains ( MetricEventNames . LoadHostConfiguration ) && metricsLogger . EventsEnded . Contains ( MetricEventNames . LoadHostConfiguration )
280286 && metricsLogger . EventsBegan . Contains ( MetricEventNames . InitializeHostConfiguration ) && metricsLogger . EventsEnded . Contains ( MetricEventNames . InitializeHostConfiguration ) ;
281287 }
288+
289+ private static void VerifySanitizedHostConfigLog ( IList < LogMessage > logs , string expectedBundleId , string expectedBundleVersionSpec )
290+ {
291+ var hostJsonLog = logs . Single ( p => p . EventId . Name == "HostConfigRead" ) ;
292+ Assert . Equal ( LogLevel . Information , hostJsonLog . Level ) ;
293+ string sanitizedJson = ( string ) hostJsonLog . State . ToDictionary ( ) [ "sanitizedJson" ] ;
294+ var jo = JObject . Parse ( sanitizedJson ) ;
295+
296+ Assert . Equal ( 3 , jo . Count ) ;
297+ Assert . Equal ( "2.0" , jo [ "version" ] ) ;
298+ Assert . Equal ( true , jo [ "isDefaultHostConfig" ] ) ;
299+
300+ var bundleConfig = jo [ "extensionBundle" ] ;
301+ Assert . Equal ( expectedBundleId , bundleConfig [ "id" ] ) ;
302+ Assert . Equal ( expectedBundleVersionSpec , bundleConfig [ "version" ] ) ;
303+ }
282304 }
283305}
0 commit comments