@@ -1225,7 +1225,6 @@ public void ValidateFunction_ValidatesHttpRoutes()
1225
1225
{
1226
1226
var httpFunctions = new Dictionary < string , HttpTriggerAttribute > ( ) ;
1227
1227
1228
- // first add an http function
1229
1228
var metadata = new FunctionMetadata ( ) ;
1230
1229
var function = new Mock < FunctionDescriptor > ( MockBehavior . Strict , "test" , null , metadata , null , null , null , null ) ;
1231
1230
var attribute = new HttpTriggerAttribute ( AuthorizationLevel . Function , "get" )
@@ -1234,7 +1233,7 @@ public void ValidateFunction_ValidatesHttpRoutes()
1234
1233
} ;
1235
1234
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1236
1235
1237
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1236
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1238
1237
Assert . Equal ( 1 , httpFunctions . Count ) ;
1239
1238
Assert . True ( httpFunctions . ContainsKey ( "test" ) ) ;
1240
1239
@@ -1245,7 +1244,7 @@ public void ValidateFunction_ValidatesHttpRoutes()
1245
1244
Route = "/foo/bar/baz/"
1246
1245
} ;
1247
1246
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1248
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1247
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1249
1248
Assert . Equal ( 2 , httpFunctions . Count ) ;
1250
1249
Assert . True ( httpFunctions . ContainsKey ( "test2" ) ) ;
1251
1250
@@ -1256,7 +1255,7 @@ public void ValidateFunction_ValidatesHttpRoutes()
1256
1255
Route = "/foo/bar/baz/"
1257
1256
} ;
1258
1257
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1259
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1258
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1260
1259
Assert . Equal ( 3 , httpFunctions . Count ) ;
1261
1260
Assert . True ( httpFunctions . ContainsKey ( "test3" ) ) ;
1262
1261
@@ -1270,7 +1269,7 @@ public void ValidateFunction_ValidatesHttpRoutes()
1270
1269
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1271
1270
var ex = Assert . Throws < InvalidOperationException > ( ( ) =>
1272
1271
{
1273
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1272
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1274
1273
} ) ;
1275
1274
Assert . Equal ( "The route specified conflicts with the route defined by function 'test2'." , ex . Message ) ;
1276
1275
Assert . Equal ( 3 , httpFunctions . Count ) ;
@@ -1284,7 +1283,7 @@ public void ValidateFunction_ValidatesHttpRoutes()
1284
1283
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1285
1284
ex = Assert . Throws < InvalidOperationException > ( ( ) =>
1286
1285
{
1287
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1286
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1288
1287
} ) ;
1289
1288
Assert . Equal ( "The specified route conflicts with one or more built in routes." , ex . Message ) ;
1290
1289
@@ -1297,15 +1296,15 @@ public void ValidateFunction_ValidatesHttpRoutes()
1297
1296
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1298
1297
ex = Assert . Throws < InvalidOperationException > ( ( ) =>
1299
1298
{
1300
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1299
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1301
1300
} ) ;
1302
1301
Assert . Equal ( "The specified route conflicts with one or more built in routes." , ex . Message ) ;
1303
1302
1304
1303
// verify that empty route is defaulted to function name
1305
1304
function = new Mock < FunctionDescriptor > ( MockBehavior . Strict , "test7" , null , metadata , null , null , null , null ) ;
1306
1305
attribute = new HttpTriggerAttribute ( ) ;
1307
1306
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1308
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1307
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1309
1308
Assert . Equal ( 4 , httpFunctions . Count ) ;
1310
1309
Assert . True ( httpFunctions . ContainsKey ( "test7" ) ) ;
1311
1310
Assert . Equal ( "test7" , attribute . Route ) ;
@@ -1383,7 +1382,7 @@ public void ValidateFunction_ThrowsOnDuplicateName()
1383
1382
var attribute = new HttpTriggerAttribute ( AuthorizationLevel . Function , "get" ) ;
1384
1383
function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => attribute ) ;
1385
1384
1386
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1385
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1387
1386
1388
1387
// add a proxy with same name
1389
1388
metadata = new ProxyFunctionMetadata ( null ) ;
@@ -1396,12 +1395,63 @@ public void ValidateFunction_ThrowsOnDuplicateName()
1396
1395
1397
1396
var ex = Assert . Throws < InvalidOperationException > ( ( ) =>
1398
1397
{
1399
- ScriptHost . ValidateFunction ( function . Object , httpFunctions ) ;
1398
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , _testEnvironment ) ;
1400
1399
} ) ;
1401
1400
1402
1401
Assert . Equal ( string . Format ( $ "The function or proxy name '{ name } ' must be unique within the function app.", name ) , ex . Message ) ;
1403
1402
}
1404
1403
1404
+ [ Fact ]
1405
+ public void ValidateFunction_ThrowsForLegacyBlobTrigger_OnFlexConsumption ( )
1406
+ {
1407
+ var httpFunctions = new Dictionary < string , HttpTriggerAttribute > ( ) ;
1408
+ var name = "test" ;
1409
+
1410
+ var metadata = new FunctionMetadata ( ) ;
1411
+ metadata . Bindings . Add ( new BindingMetadata ( )
1412
+ {
1413
+ Direction = BindingDirection . In ,
1414
+ Type = "blobTrigger" ,
1415
+ Raw = JObject . Parse ( "{ \" type\" : \" blobTrigger\" , \" connection\" : \" \" , \" path\" : \" sample1/{name}\" , \" name\" : \" myBlob\" }" )
1416
+ } ) ;
1417
+ var function = new Mock < FunctionDescriptor > ( MockBehavior . Strict , name , null , metadata , null , null , null , null ) ;
1418
+ function . SetupGet ( p => p . HttpTriggerAttribute ) . Returns ( ( ) => null ) ;
1419
+
1420
+ TestEnvironment testEnvironment = new TestEnvironment ( ) ;
1421
+ testEnvironment . SetEnvironmentVariable ( EnvironmentSettingNames . AzureWebsiteSku , ScriptConstants . FlexConsumptionSku ) ;
1422
+
1423
+ string errorMessage = "The Flex Consumption SKU only supports EventGrid as the source for BlobTrigger functions. Please update function 'test' to use EventGrid. For more information see https://aka.ms/blob-trigger-eg." ;
1424
+
1425
+ var ex = Assert . Throws < InvalidOperationException > ( ( ) =>
1426
+ {
1427
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , testEnvironment ) ;
1428
+ } ) ;
1429
+ Assert . Equal ( errorMessage , ex . Message ) ;
1430
+
1431
+ metadata . Bindings . Clear ( ) ;
1432
+ metadata . Bindings . Add ( new BindingMetadata ( )
1433
+ {
1434
+ Direction = BindingDirection . In ,
1435
+ Type = "blobTrigger" ,
1436
+ Raw = JObject . Parse ( "{ \" type\" : \" blobTrigger\" , \" connection\" : \" \" , \" source\" : \" LogsAndContainerScan\" , \" path\" : \" sample1/{name}\" , \" name\" : \" myBlob\" }" )
1437
+ } ) ;
1438
+ ex = Assert . Throws < InvalidOperationException > ( ( ) =>
1439
+ {
1440
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , testEnvironment ) ;
1441
+ } ) ;
1442
+ Assert . Equal ( errorMessage , ex . Message ) ;
1443
+
1444
+ metadata . Bindings . Clear ( ) ;
1445
+ metadata . Bindings . Add ( new BindingMetadata ( )
1446
+ {
1447
+ Direction = BindingDirection . In ,
1448
+ Type = "blobTrigger" ,
1449
+ Raw = JObject . Parse ( "{ \" type\" : \" blobTrigger\" , \" connection\" : \" \" , \" source\" : \" EventGrid\" , \" path\" : \" sample1/{name}\" , \" name\" : \" myBlob\" }" )
1450
+ } ) ;
1451
+
1452
+ ScriptHost . ValidateFunction ( function . Object , httpFunctions , testEnvironment ) ;
1453
+ }
1454
+
1405
1455
[ Fact ]
1406
1456
public async Task IsFunction_ReturnsExpectedResult ( )
1407
1457
{
0 commit comments