7
7
using System . IO ;
8
8
using System . IO . Abstractions ;
9
9
using System . Linq ;
10
+ using System . Net ;
10
11
using System . Net . Http ;
11
12
using System . Text ;
12
13
using System . Threading ;
13
14
using System . Threading . Tasks ;
15
+ using Microsoft . AspNetCore . Http ;
14
16
using Microsoft . Azure . WebJobs . Host . Executors ;
17
+ using Microsoft . Azure . WebJobs . Script . Binding ;
15
18
using Microsoft . Azure . WebJobs . Script . Description ;
16
19
using Microsoft . Azure . WebJobs . Script . Management . Models ;
17
20
using Microsoft . Azure . WebJobs . Script . Rpc ;
18
21
using Microsoft . Azure . WebJobs . Script . WebHost ;
19
22
using Microsoft . Azure . WebJobs . Script . WebHost . Extensions ;
20
23
using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
24
+ using Microsoft . CodeAnalysis . VisualBasic . Syntax ;
21
25
using Microsoft . Extensions . Configuration ;
22
26
using Microsoft . Extensions . Logging ;
23
27
using Microsoft . Extensions . Logging . Abstractions ;
@@ -38,6 +42,7 @@ public class WebFunctionsManagerTests : IDisposable
38
42
private readonly ScriptApplicationHostOptions _hostOptions ;
39
43
private readonly WebFunctionsManager _webFunctionsManager ;
40
44
private readonly Mock < IEnvironment > _mockEnvironment ;
45
+ private readonly IFileSystem _fileSystem ;
41
46
42
47
public WebFunctionsManagerTests ( )
43
48
{
@@ -84,6 +89,7 @@ public WebFunctionsManagerTests()
84
89
85
90
var workerOptions = new LanguageWorkerOptions ( ) ;
86
91
FileUtility . Instance = fileSystem ;
92
+ _fileSystem = fileSystem ;
87
93
var languageWorkerOptions = new OptionsWrapper < LanguageWorkerOptions > ( CreateLanguageWorkerConfigSettings ( ) ) ;
88
94
var metadataProvider = new FunctionMetadataProvider ( optionsMonitor , languageWorkerOptions , NullLogger < FunctionMetadataProvider > . Instance ) ;
89
95
var functionsSyncManager = new FunctionsSyncManager ( configurationMock . Object , hostIdProviderMock . Object , optionsMonitor , languageWorkerOptions , loggerFactory . CreateLogger < FunctionsSyncManager > ( ) , httpClient , secretManagerProviderMock . Object , mockWebHostEnvironment . Object , _mockEnvironment . Object , hostNameProvider , metadataProvider ) ;
@@ -101,6 +107,28 @@ public async Task ReadFunctionsMetadataSucceeds()
101
107
Assert . Equal ( 1 , unknownFunctions . Count ( ) ) ;
102
108
}
103
109
110
+ [ Fact ]
111
+ public async Task TryGetFunction_NoMatchingFunction_ReturnsEmpty ( )
112
+ {
113
+ var result = await _webFunctionsManager . TryGetFunction ( "non-function" , null ) ;
114
+ Assert . False ( result . Item1 ) ;
115
+ }
116
+
117
+ [ Fact ]
118
+ public async Task TryGetFunction_NoFunction_ReturnsEmpty ( )
119
+ {
120
+ try
121
+ {
122
+ FileUtility . Instance = CreateEmptyFileSystem ( _hostOptions ) ;
123
+ var action = await _webFunctionsManager . TryGetFunction ( "function1" , null ) ;
124
+ Assert . False ( action . Item1 ) ;
125
+ }
126
+ finally
127
+ {
128
+ FileUtility . Instance = _fileSystem ;
129
+ }
130
+ }
131
+
104
132
[ Theory ]
105
133
[ InlineData ( null , "api" ) ]
106
134
[ InlineData ( "" , "api" ) ]
@@ -177,6 +205,31 @@ private static LanguageWorkerOptions CreateLanguageWorkerConfigSettings()
177
205
} ;
178
206
}
179
207
208
+ private static IFileSystem CreateEmptyFileSystem ( ScriptApplicationHostOptions options )
209
+ {
210
+ string rootPath = options . ScriptPath ;
211
+ string testDataPath = options . TestDataPath ;
212
+
213
+ var fullFileSystem = new FileSystem ( ) ;
214
+ var fileSystem = new Mock < IFileSystem > ( ) ;
215
+ var fileBase = new Mock < FileBase > ( ) ;
216
+ var dirBase = new Mock < DirectoryBase > ( ) ;
217
+
218
+ fileSystem . SetupGet ( f => f . Path ) . Returns ( fullFileSystem . Path ) ;
219
+ fileSystem . SetupGet ( f => f . File ) . Returns ( fileBase . Object ) ;
220
+ fileBase . Setup ( f => f . Exists ( Path . Combine ( rootPath , "host.json" ) ) ) . Returns ( true ) ;
221
+
222
+ var hostJson = new MemoryStream ( Encoding . UTF8 . GetBytes ( @"{ ""durableTask"": { ""HubName"": ""TestHubValue"", ""azureStorageConnectionStringName"": ""DurableStorage"" }}" ) ) ;
223
+ hostJson . Position = 0 ;
224
+ fileBase . Setup ( f => f . Open ( Path . Combine ( rootPath , @"host.json" ) , It . IsAny < FileMode > ( ) , It . IsAny < FileAccess > ( ) , It . IsAny < FileShare > ( ) ) ) . Returns ( hostJson ) ;
225
+
226
+ fileSystem . SetupGet ( f => f . Directory ) . Returns ( dirBase . Object ) ;
227
+
228
+ dirBase . Setup ( d => d . Exists ( options . ScriptPath ) ) . Returns ( true ) ;
229
+ dirBase . Setup ( d => d . EnumerateDirectories ( rootPath ) ) . Returns ( new string [ 0 ] ) ;
230
+ return fileSystem . Object ;
231
+ }
232
+
180
233
private static IFileSystem CreateFileSystem ( ScriptApplicationHostOptions options )
181
234
{
182
235
string rootPath = options . ScriptPath ;
0 commit comments