@@ -49,7 +49,7 @@ public HostJsonFileConfigurationSourceTests()
49
49
}
50
50
51
51
[ Fact ]
52
- public void MissingHostJson_CreatesHostJson_withDefaultExtensionBundleId ( )
52
+ public void MissingHostJson_GeneratesExpectedDefaultConfigFile ( )
53
53
{
54
54
Assert . False ( File . Exists ( _hostJsonFile ) ) ;
55
55
TestMetricsLogger testMetricsLogger = new TestMetricsLogger ( ) ;
@@ -58,14 +58,17 @@ public void MissingHostJson_CreatesHostJson_withDefaultExtensionBundleId()
58
58
59
59
AreExpectedMetricsGenerated ( testMetricsLogger ) ;
60
60
61
+ // verify actual file content
61
62
Assert . Equal ( _hostJsonWithBundles , File . ReadAllText ( _hostJsonFile ) ) ;
62
63
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 ) ;
65
68
}
66
69
67
70
[ Fact ]
68
- public void MissingHostJson_CreatesHostJson_withWorkFlowExtensionBundleId ( )
71
+ public void MissingHostJson_WorkflowApp_GeneratesExpectedDefaultConfigFile ( )
69
72
{
70
73
var environment = new TestEnvironment ( new Dictionary < string , string >
71
74
{
@@ -79,10 +82,13 @@ public void MissingHostJson_CreatesHostJson_withWorkFlowExtensionBundleId()
79
82
80
83
AreExpectedMetricsGenerated ( testMetricsLogger ) ;
81
84
85
+ // verify actual file content
82
86
Assert . Equal ( _hostJsonWithWorkFlowBundle , File . ReadAllText ( _hostJsonFile ) ) ;
83
87
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 ) ;
86
92
}
87
93
88
94
[ Theory ]
@@ -279,5 +285,21 @@ private bool AreExpectedMetricsGenerated(TestMetricsLogger metricsLogger)
279
285
&& metricsLogger . EventsBegan . Contains ( MetricEventNames . LoadHostConfiguration ) && metricsLogger . EventsEnded . Contains ( MetricEventNames . LoadHostConfiguration )
280
286
&& metricsLogger . EventsBegan . Contains ( MetricEventNames . InitializeHostConfiguration ) && metricsLogger . EventsEnded . Contains ( MetricEventNames . InitializeHostConfiguration ) ;
281
287
}
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
+ }
282
304
}
283
305
}
0 commit comments