@@ -24,14 +24,17 @@ public class FunctionMetadataManagerTests
24
24
private Mock < IFunctionMetadataProvider > _mockFunctionMetadataProvider ;
25
25
private FunctionMetadataManager _testFunctionMetadataManager ;
26
26
private HttpWorkerOptions _defaultHttpWorkerOptions ;
27
+ private Mock < IScriptHostManager > _mockScriptHostManager ;
27
28
28
29
public FunctionMetadataManagerTests ( )
29
30
{
30
31
_mockFunctionMetadataProvider = new Mock < IFunctionMetadataProvider > ( ) ;
31
32
string functionsPath = Path . Combine ( Environment . CurrentDirectory , @"..\..\..\..\..\sample\node" ) ;
32
33
_defaultHttpWorkerOptions = new HttpWorkerOptions ( ) ;
33
34
_scriptJobHostOptions . RootScriptPath = functionsPath ;
34
- _testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) ,
35
+
36
+ _mockScriptHostManager = new Mock < IScriptHostManager > ( ) ;
37
+ _testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) , _mockScriptHostManager ,
35
38
_mockFunctionMetadataProvider . Object , new List < IFunctionProvider > ( ) , new OptionsWrapper < HttpWorkerOptions > ( _defaultHttpWorkerOptions ) , MockNullLoggerFactory . CreateLoggerFactory ( ) ) ;
36
39
}
37
40
@@ -40,6 +43,7 @@ public FunctionMetadataManagerTests()
40
43
[ InlineData ( null ) ]
41
44
public void IsScriptFileDetermined_ScriptFile_Emtpy_False ( string scriptFile )
42
45
{
46
+ _mockScriptHostManager . Raise ( m => m . HostInitializing += null , new EventArgs ( ) ) ;
43
47
FunctionMetadata functionMetadata = GetTestFunctionMetadata ( scriptFile ) ;
44
48
Assert . False ( _testFunctionMetadataManager . IsScriptFileDetermined ( functionMetadata ) ) ;
45
49
}
@@ -57,8 +61,11 @@ public void FunctionMetadataManager_Verify_FunctionErrors(string scriptFile)
57
61
mockFunctionMetadataProvider . Setup ( m => m . GetFunctionMetadata ( false ) ) . Returns ( functionMetadataCollection . ToImmutableArray ( ) ) ;
58
62
mockFunctionMetadataProvider . Setup ( m => m . FunctionErrors ) . Returns ( mockFunctionErrors ) ;
59
63
60
- FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) ,
64
+ var managerMock = new Mock < IScriptHostManager > ( ) ;
65
+ FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) , managerMock ,
61
66
mockFunctionMetadataProvider . Object , new List < IFunctionProvider > ( ) , new OptionsWrapper < HttpWorkerOptions > ( _defaultHttpWorkerOptions ) , MockNullLoggerFactory . CreateLoggerFactory ( ) ) ;
67
+
68
+ managerMock . Raise ( m => m . HostInitializing += null , new EventArgs ( ) ) ;
62
69
Assert . Empty ( testFunctionMetadataManager . LoadFunctionMetadata ( ) ) ;
63
70
64
71
Assert . True ( testFunctionMetadataManager . Errors . Count == 1 ) ;
@@ -87,8 +94,12 @@ public void FunctionMetadataManager_Verify_FunctionErrors_FromFunctionProviders(
87
94
mockFunctionProvider . Setup ( m => m . GetFunctionMetadataAsync ( ) ) . ReturnsAsync ( functionMetadataCollection . ToImmutableArray ( ) ) ;
88
95
mockFunctionProvider . Setup ( m => m . FunctionErrors ) . Returns ( mockFunctionErrors . ToImmutableDictionary ( ) ) ;
89
96
90
- FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) ,
97
+ var managerMock = new Mock < IScriptHostManager > ( ) ;
98
+ FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) , managerMock ,
91
99
mockFunctionMetadataProvider . Object , new List < IFunctionProvider > ( ) { mockFunctionProvider . Object } , new OptionsWrapper < HttpWorkerOptions > ( _defaultHttpWorkerOptions ) , MockNullLoggerFactory . CreateLoggerFactory ( ) ) ;
100
+
101
+ managerMock . Raise ( m => m . HostInitializing += null , new EventArgs ( ) ) ;
102
+
92
103
testFunctionMetadataManager . LoadFunctionMetadata ( ) ;
93
104
94
105
Assert . Equal ( 2 , testFunctionMetadataManager . Errors . Count ) ;
@@ -97,6 +108,25 @@ public void FunctionMetadataManager_Verify_FunctionErrors_FromFunctionProviders(
97
108
Assert . True ( functionErrors . Contains ( "error" ) ) ;
98
109
}
99
110
111
+ [ Fact ]
112
+ public void FunctionMetadataManager_DoesNotError_MissingScriptFile_InWebHostMode ( )
113
+ {
114
+ var mockFunctionMetadataProvider = new Mock < IFunctionMetadataProvider > ( ) ;
115
+ var mockFunctionProvider = new Mock < IFunctionProvider > ( ) ;
116
+
117
+ var testMetadata = GetTestFunctionMetadata ( null ) ;
118
+
119
+ var managerMock = new Mock < IScriptHostManager > ( ) ;
120
+ FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) , managerMock ,
121
+ mockFunctionMetadataProvider . Object , new List < IFunctionProvider > ( ) { mockFunctionProvider . Object } , new OptionsWrapper < HttpWorkerOptions > ( _defaultHttpWorkerOptions ) , MockNullLoggerFactory . CreateLoggerFactory ( ) ) ;
122
+
123
+ Assert . True ( testFunctionMetadataManager . IsScriptFileDetermined ( testMetadata ) ) ;
124
+
125
+ managerMock . Raise ( m => m . HostInitializing += null , new EventArgs ( ) ) ;
126
+
127
+ Assert . False ( testFunctionMetadataManager . IsScriptFileDetermined ( testMetadata ) ) ;
128
+ }
129
+
100
130
[ Fact ]
101
131
public void FunctionMetadataManager_GetsMetadata_FromFunctionProviders ( )
102
132
{
@@ -156,8 +186,12 @@ public void FunctionMetadataManager_ThrowsError_DuplicateFunctions_FromFunctionP
156
186
public void IsScriptFileDetermined_ScriptFile_Emtpy_HttpWorker_Returns_True ( string scriptFile )
157
187
{
158
188
FunctionMetadata functionMetadata = GetTestFunctionMetadata ( scriptFile ) ;
159
- FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) ,
189
+
190
+ var managerMock = new Mock < IScriptHostManager > ( ) ;
191
+
192
+ FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager . GetFunctionMetadataManager ( new OptionsWrapper < ScriptJobHostOptions > ( _scriptJobHostOptions ) , managerMock ,
160
193
_mockFunctionMetadataProvider . Object , new List < IFunctionProvider > ( ) , new OptionsWrapper < HttpWorkerOptions > ( GetTestHttpWorkerOptions ( ) ) , MockNullLoggerFactory . CreateLoggerFactory ( ) ) ;
194
+ managerMock . Raise ( m => m . HostInitializing += null , new EventArgs ( ) ) ;
161
195
162
196
Assert . True ( testFunctionMetadataManager . IsScriptFileDetermined ( functionMetadata ) ) ;
163
197
}
0 commit comments