@@ -35,37 +35,63 @@ public WebFunctionsManagerTests()
35
35
36
36
_hostConfig = new ScriptHostConfiguration
37
37
{
38
- RootScriptPath = @"x:\root\site\wwwroot " ,
38
+ RootScriptPath = @"x:\root" ,
39
39
IsSelfHost = false ,
40
40
RootLogPath = @"x:\root\LogFiles\Application\Functions" ,
41
- TestDataPath = @"x:\root\data\functions\sampledata "
41
+ TestDataPath = @"x:\root\data"
42
42
} ;
43
43
_hostConfig . HostConfig . HostId = "testhostid123" ;
44
44
45
45
HostNameProvider . Reset ( ) ;
46
46
}
47
47
48
- [ Fact ]
49
- public async Task ReadFunctionsMetadataSucceeds ( )
48
+ [ Theory ]
49
+ [ InlineData ( true ) ]
50
+ [ InlineData ( false ) ]
51
+ public async Task ReadFunctionsMetadataSucceeds ( bool testDataCapEnabled )
50
52
{
51
- // Setup
52
- var fileSystem = CreateFileSystem ( _hostConfig ) ;
53
- var loggerProvider = new TestLoggerProvider ( ) ;
54
- var loggerFactory = new LoggerFactory ( ) ;
55
- loggerFactory . AddProvider ( loggerProvider ) ;
56
-
57
- var contentBuilder = new StringBuilder ( ) ;
58
- var httpClient = CreateHttpClient ( contentBuilder ) ;
59
- var webManager = new WebFunctionsManager ( _hostConfig , loggerFactory ) ;
60
-
61
- FileUtility . Instance = fileSystem ;
62
- var functions = await webManager . GetFunctionsMetadata ( ) ;
63
- var jsFunctions = functions . Where ( funcMetadata => funcMetadata . Language == ScriptType . Javascript . ToString ( ) ) . ToList ( ) ;
64
- var pytonFunctions = functions . Where ( funcMetadata => funcMetadata . Language == ScriptType . Python . ToString ( ) ) . ToList ( ) ;
65
-
66
- Assert . Equal ( 3 , functions . Count ( ) ) ;
67
- Assert . Equal ( 2 , jsFunctions . Count ( ) ) ;
68
- Assert . Equal ( 1 , pytonFunctions . Count ( ) ) ;
53
+ var env = new Dictionary < string , string > ( ) ;
54
+ if ( ! testDataCapEnabled )
55
+ {
56
+ env . Add ( EnvironmentSettingNames . TestDataCapEnabled , "0" ) ;
57
+ }
58
+ var envScope = new TestScopedEnvironmentVariable ( env ) ;
59
+ using ( envScope )
60
+ {
61
+ // Setup
62
+ var fileSystem = CreateFileSystem ( _hostConfig ) ;
63
+ var loggerProvider = new TestLoggerProvider ( ) ;
64
+ var loggerFactory = new LoggerFactory ( ) ;
65
+ loggerFactory . AddProvider ( loggerProvider ) ;
66
+
67
+ var contentBuilder = new StringBuilder ( ) ;
68
+ var httpClient = CreateHttpClient ( contentBuilder ) ;
69
+ var webManager = new WebFunctionsManager ( _hostConfig , loggerFactory ) ;
70
+
71
+ FileUtility . Instance = fileSystem ;
72
+ var metadata = ( await webManager . GetFunctionsMetadata ( ) ) . ToArray ( ) ;
73
+
74
+ Assert . Equal ( 3 , metadata . Count ( ) ) ;
75
+ Assert . Equal ( 2 , metadata . Count ( p => p . Language == ScriptType . Javascript . ToString ( ) ) ) ;
76
+ Assert . Equal ( 1 , metadata . Count ( p => p . Language == ScriptType . Python . ToString ( ) ) ) ;
77
+
78
+ Assert . Equal ( "https://localhost/api/vfs/data/function1.dat" , metadata [ 0 ] . TestDataHref . AbsoluteUri ) ;
79
+ Assert . Equal ( "https://localhost/api/vfs/data/function2.dat" , metadata [ 1 ] . TestDataHref . AbsoluteUri ) ;
80
+ Assert . Equal ( "https://localhost/api/vfs/data/function3.dat" , metadata [ 2 ] . TestDataHref . AbsoluteUri ) ;
81
+
82
+ Assert . Equal ( "Test Data 1" , metadata [ 0 ] . TestData ) ;
83
+ Assert . Equal ( "Test Data 2" , metadata [ 1 ] . TestData ) ;
84
+
85
+ if ( testDataCapEnabled )
86
+ {
87
+ // TestData size is capped by default
88
+ Assert . Null ( metadata [ 2 ] . TestData ) ;
89
+ }
90
+ else
91
+ {
92
+ Assert . Equal ( ScriptConstants . MaxTestDataInlineStringLength + 1 , metadata [ 2 ] . TestData . Length ) ;
93
+ }
94
+ }
69
95
}
70
96
71
97
[ Theory ]
@@ -236,6 +262,10 @@ private static IFileSystem CreateFileSystem(ScriptHostConfiguration hostConfig)
236
262
]
237
263
}" ;
238
264
265
+ string testData1 = "Test Data 1" ;
266
+ string testData2 = "Test Data 2" ;
267
+ string testData3 = TestHelpers . NewRandomString ( ScriptConstants . MaxTestDataInlineStringLength + 1 ) ;
268
+
239
269
fileBase . Setup ( f => f . Exists ( Path . Combine ( rootScriptPath , @"function1\function.json" ) ) ) . Returns ( true ) ;
240
270
fileBase . Setup ( f => f . Exists ( Path . Combine ( rootScriptPath , @"function1\main.py" ) ) ) . Returns ( true ) ;
241
271
fileBase . Setup ( f => f . ReadAllText ( Path . Combine ( rootScriptPath , @"function1\function.json" ) ) ) . Returns ( function1 ) ;
@@ -245,7 +275,7 @@ private static IFileSystem CreateFileSystem(ScriptHostConfiguration hostConfig)
245
275
} ) ;
246
276
fileBase . Setup ( f => f . Open ( Path . Combine ( testDataPath , "function1.dat" ) , It . IsAny < FileMode > ( ) , It . IsAny < FileAccess > ( ) , It . IsAny < FileShare > ( ) ) ) . Returns ( ( ) =>
247
277
{
248
- return new MemoryStream ( Encoding . UTF8 . GetBytes ( function1 ) ) ;
278
+ return new MemoryStream ( Encoding . UTF8 . GetBytes ( testData1 ) ) ;
249
279
} ) ;
250
280
251
281
fileBase . Setup ( f => f . Exists ( Path . Combine ( rootScriptPath , @"function2\function.json" ) ) ) . Returns ( true ) ;
@@ -257,7 +287,7 @@ private static IFileSystem CreateFileSystem(ScriptHostConfiguration hostConfig)
257
287
} ) ;
258
288
fileBase . Setup ( f => f . Open ( Path . Combine ( testDataPath , "function2.dat" ) , It . IsAny < FileMode > ( ) , It . IsAny < FileAccess > ( ) , It . IsAny < FileShare > ( ) ) ) . Returns ( ( ) =>
259
289
{
260
- return new MemoryStream ( Encoding . UTF8 . GetBytes ( function1 ) ) ;
290
+ return new MemoryStream ( Encoding . UTF8 . GetBytes ( testData2 ) ) ;
261
291
} ) ;
262
292
263
293
fileBase . Setup ( f => f . Exists ( Path . Combine ( rootScriptPath , @"function3\function.json" ) ) ) . Returns ( true ) ;
@@ -269,7 +299,7 @@ private static IFileSystem CreateFileSystem(ScriptHostConfiguration hostConfig)
269
299
} ) ;
270
300
fileBase . Setup ( f => f . Open ( Path . Combine ( testDataPath , "function3.dat" ) , It . IsAny < FileMode > ( ) , It . IsAny < FileAccess > ( ) , It . IsAny < FileShare > ( ) ) ) . Returns ( ( ) =>
271
301
{
272
- return new MemoryStream ( Encoding . UTF8 . GetBytes ( function1 ) ) ;
302
+ return new MemoryStream ( Encoding . UTF8 . GetBytes ( testData3 ) ) ;
273
303
} ) ;
274
304
275
305
return fileSystem . Object ;
0 commit comments