diff --git a/samples/samples-csharpscript/TriggerBindingSamples/.vscode/extensions.json b/samples/samples-csharpscript/TriggerBindingSamples/.vscode/extensions.json new file mode 100644 index 00000000..dde673dc --- /dev/null +++ b/samples/samples-csharpscript/TriggerBindingSamples/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions" + ] +} \ No newline at end of file diff --git a/samples/samples-csharpscript/TriggerBindingSamples/ProductsTrigger/function.json b/samples/samples-csharpscript/TriggerBindingSamples/ProductsTrigger/function.json new file mode 100644 index 00000000..f52bcac4 --- /dev/null +++ b/samples/samples-csharpscript/TriggerBindingSamples/ProductsTrigger/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.Products", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/samples/samples-csharpscript/TriggerBindingSamples/ProductsTrigger/run.csx b/samples/samples-csharpscript/TriggerBindingSamples/ProductsTrigger/run.csx new file mode 100644 index 00000000..650e28fa --- /dev/null +++ b/samples/samples-csharpscript/TriggerBindingSamples/ProductsTrigger/run.csx @@ -0,0 +1,14 @@ +#load "../../Common/product.csx" +#r "Newtonsoft.Json" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + log.LogInformation("SQL Changes: " + JsonConvert.SerializeObject(changes)); +} \ No newline at end of file diff --git a/samples/samples-csharpscript/TriggerBindingSamples/host.json b/samples/samples-csharpscript/TriggerBindingSamples/host.json new file mode 100644 index 00000000..22c599f8 --- /dev/null +++ b/samples/samples-csharpscript/TriggerBindingSamples/host.json @@ -0,0 +1,15 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle.Preview", + "version": "[4.*, 5.0.0)" + } +} \ No newline at end of file diff --git a/test/Integration/SqlTriggerBindingIntegrationTests.cs b/test/Integration/SqlTriggerBindingIntegrationTests.cs index 431af210..d8bf7f62 100644 --- a/test/Integration/SqlTriggerBindingIntegrationTests.cs +++ b/test/Integration/SqlTriggerBindingIntegrationTests.cs @@ -31,7 +31,6 @@ public SqlTriggerBindingIntegrationTests(ITestOutputHelper output = null) : base /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public async Task SingleOperationTriggerTest(SupportedLanguages lang) { this.SetChangeTrackingForTable("Products"); @@ -80,7 +79,6 @@ await this.WaitForProductChanges( /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public async Task BatchSizeOverrideTriggerTest(SupportedLanguages lang) { // Use enough items to require 4 batches to be processed but then @@ -124,7 +122,6 @@ await this.WaitForProductChanges( /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public async Task MaxBatchSizeOverrideTriggerTest(SupportedLanguages lang) { // Use enough items to require 4 batches to be processed but then @@ -168,7 +165,6 @@ await this.WaitForProductChanges( /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public async Task PollingIntervalOverrideTriggerTest(SupportedLanguages lang) { const int firstId = 1; @@ -211,7 +207,6 @@ await this.WaitForProductChanges( /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public async Task MultiOperationTriggerTest(SupportedLanguages lang) { int firstId = 1; @@ -293,7 +288,6 @@ await this.WaitForProductChanges( /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public async Task MultiFunctionTriggerTest(SupportedLanguages lang) { const string Trigger1Changes = "Trigger1 Changes: "; @@ -420,7 +414,6 @@ public async Task MultiFunctionTriggerTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public async Task MultiHostTriggerTest(SupportedLanguages lang) { this.SetChangeTrackingForTable("Products"); @@ -472,7 +465,6 @@ await this.WaitForProductChanges( /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public void TableNotPresentTriggerTest(SupportedLanguages lang) { this.StartFunctionHostAndWaitForError( @@ -487,7 +479,6 @@ public void TableNotPresentTriggerTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public void PrimaryKeyNotCreatedTriggerTest(SupportedLanguages lang) { this.StartFunctionHostAndWaitForError( @@ -503,7 +494,6 @@ public void PrimaryKeyNotCreatedTriggerTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public void ReservedPrimaryKeyColumnNamesTriggerTest(SupportedLanguages lang) { this.StartFunctionHostAndWaitForError( @@ -519,7 +509,6 @@ public void ReservedPrimaryKeyColumnNamesTriggerTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public void UnsupportedColumnTypesTriggerTest(SupportedLanguages lang) { this.StartFunctionHostAndWaitForError( @@ -535,7 +524,6 @@ public void UnsupportedColumnTypesTriggerTest(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public void ChangeTrackingNotEnabledTriggerTest(SupportedLanguages lang) { this.StartFunctionHostAndWaitForError( @@ -572,7 +560,6 @@ public async void GetMetricsTest() /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.CSharpscript)] public void UnsupportedDatabaseThrows(SupportedLanguages lang) { // Change database compat level to unsupported version diff --git a/test/Integration/test-csx/Common/Product.csx b/test/Integration/test-csx/Common/Product.csx index 5ef26794..c84985b9 100644 --- a/test/Integration/test-csx/Common/Product.csx +++ b/test/Integration/test-csx/Common/Product.csx @@ -1,9 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using System.Linq; - public class Product { public int ProductId { get; set; } diff --git a/test/Integration/test-csx/MultiFunctionTrigger1/function.json b/test/Integration/test-csx/MultiFunctionTrigger1/function.json new file mode 100644 index 00000000..f52bcac4 --- /dev/null +++ b/test/Integration/test-csx/MultiFunctionTrigger1/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.Products", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/test/Integration/test-csx/MultiFunctionTrigger1/run.csx b/test/Integration/test-csx/MultiFunctionTrigger1/run.csx new file mode 100644 index 00000000..ae696172 --- /dev/null +++ b/test/Integration/test-csx/MultiFunctionTrigger1/run.csx @@ -0,0 +1,14 @@ +#load "../Common/Product.csx" +#r "Newtonsoft.Json" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + log.LogInformation("Trigger1 Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes)); +} \ No newline at end of file diff --git a/test/Integration/test-csx/MultiFunctionTrigger2/function.json b/test/Integration/test-csx/MultiFunctionTrigger2/function.json new file mode 100644 index 00000000..f52bcac4 --- /dev/null +++ b/test/Integration/test-csx/MultiFunctionTrigger2/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.Products", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/test/Integration/test-csx/MultiFunctionTrigger2/run.csx b/test/Integration/test-csx/MultiFunctionTrigger2/run.csx new file mode 100644 index 00000000..570b7cb6 --- /dev/null +++ b/test/Integration/test-csx/MultiFunctionTrigger2/run.csx @@ -0,0 +1,14 @@ +#load "../Common/Product.csx" +#r "Newtonsoft.Json" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + log.LogInformation("Trigger2 Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes)); +} \ No newline at end of file diff --git a/test/Integration/test-csx/PrimaryKeyNotPresentTrigger/function.json b/test/Integration/test-csx/PrimaryKeyNotPresentTrigger/function.json new file mode 100644 index 00000000..1e1c80a9 --- /dev/null +++ b/test/Integration/test-csx/PrimaryKeyNotPresentTrigger/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.ProductsWithoutPrimaryKey", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/test/Integration/test-csx/PrimaryKeyNotPresentTrigger/run.csx b/test/Integration/test-csx/PrimaryKeyNotPresentTrigger/run.csx new file mode 100644 index 00000000..46fb86da --- /dev/null +++ b/test/Integration/test-csx/PrimaryKeyNotPresentTrigger/run.csx @@ -0,0 +1,14 @@ +#load "../Common/Product.csx" +#r "Newtonsoft.Json" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + throw new NotImplementedException("Associated test case should fail before the function is invoked."); +} \ No newline at end of file diff --git a/test/Integration/test-csx/ProductsTriggerWithValidation/function.json b/test/Integration/test-csx/ProductsTriggerWithValidation/function.json new file mode 100644 index 00000000..f52bcac4 --- /dev/null +++ b/test/Integration/test-csx/ProductsTriggerWithValidation/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.Products", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/test/Integration/test-csx/ProductsTriggerWithValidation/run.csx b/test/Integration/test-csx/ProductsTriggerWithValidation/run.csx new file mode 100644 index 00000000..a1320ae5 --- /dev/null +++ b/test/Integration/test-csx/ProductsTriggerWithValidation/run.csx @@ -0,0 +1,20 @@ +#load "../Common/Product.csx" +#r "Newtonsoft.Json" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + string expectedMaxBatchSize = Environment.GetEnvironmentVariable("TEST_EXPECTED_MAX_BATCH_SIZE"); + if (!string.IsNullOrEmpty(expectedMaxBatchSize) && int.Parse(expectedMaxBatchSize) != changes.Count) + { + throw new Exception($"Invalid max batch size, got {changes.Count} changes but expected {expectedMaxBatchSize}"); + } + // The output is used to inspect the trigger binding parameter in test methods. + log.LogInformation("SQL Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes)); +} \ No newline at end of file diff --git a/test/Integration/test-csx/ReservedPrimaryKeyColumnNamesTrigger/function.json b/test/Integration/test-csx/ReservedPrimaryKeyColumnNamesTrigger/function.json new file mode 100644 index 00000000..3660f6a2 --- /dev/null +++ b/test/Integration/test-csx/ReservedPrimaryKeyColumnNamesTrigger/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.ProductsWithReservedPrimaryKeyColumnNames", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/test/Integration/test-csx/ReservedPrimaryKeyColumnNamesTrigger/run.csx b/test/Integration/test-csx/ReservedPrimaryKeyColumnNamesTrigger/run.csx new file mode 100644 index 00000000..f556e7ca --- /dev/null +++ b/test/Integration/test-csx/ReservedPrimaryKeyColumnNamesTrigger/run.csx @@ -0,0 +1,12 @@ +#load "../Common/Product.csx" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + throw new NotImplementedException("Associated test case should fail before the function is invoked."); +} \ No newline at end of file diff --git a/test/Integration/test-csx/TableNotPresentTrigger/function.json b/test/Integration/test-csx/TableNotPresentTrigger/function.json new file mode 100644 index 00000000..5dd16ec7 --- /dev/null +++ b/test/Integration/test-csx/TableNotPresentTrigger/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.TableNotPresent", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/test/Integration/test-csx/TableNotPresentTrigger/run.csx b/test/Integration/test-csx/TableNotPresentTrigger/run.csx new file mode 100644 index 00000000..f556e7ca --- /dev/null +++ b/test/Integration/test-csx/TableNotPresentTrigger/run.csx @@ -0,0 +1,12 @@ +#load "../Common/Product.csx" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + throw new NotImplementedException("Associated test case should fail before the function is invoked."); +} \ No newline at end of file diff --git a/test/Integration/test-csx/UnsupportedColumnTypesTrigger/function.json b/test/Integration/test-csx/UnsupportedColumnTypesTrigger/function.json new file mode 100644 index 00000000..705397cc --- /dev/null +++ b/test/Integration/test-csx/UnsupportedColumnTypesTrigger/function.json @@ -0,0 +1,12 @@ +{ + "bindings": [ + { + "name": "changes", + "type": "sqlTrigger", + "direction": "in", + "tableName": "dbo.ProductsWithUnsupportedColumnTypes", + "connectionStringSetting": "SqlConnectionString" + } + ], + "disabled": false +} \ No newline at end of file diff --git a/test/Integration/test-csx/UnsupportedColumnTypesTrigger/run.csx b/test/Integration/test-csx/UnsupportedColumnTypesTrigger/run.csx new file mode 100644 index 00000000..f556e7ca --- /dev/null +++ b/test/Integration/test-csx/UnsupportedColumnTypesTrigger/run.csx @@ -0,0 +1,12 @@ +#load "../Common/Product.csx" +#r "Microsoft.Azure.WebJobs.Extensions.Sql" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Microsoft.Azure.WebJobs.Extensions.Sql; + +public static void Run(IReadOnlyList> changes, ILogger log) +{ + throw new NotImplementedException("Associated test case should fail before the function is invoked."); +} \ No newline at end of file diff --git a/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj b/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj index 5c8d1d3f..013b3eb8 100644 --- a/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj +++ b/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj @@ -69,6 +69,7 @@ <_CSharpScriptCopyItems Include="..\samples\samples-csharpscript\InputBindingSamples\**\*.*" /> <_CSharpScriptCopyItems Include="..\samples\samples-csharpscript\OutputBindingSamples\**\*.*" /> + <_CSharpScriptCopyItems Include="..\samples\samples-csharpscript\TriggerBindingSamples\**\*.*" /> <_CSharpScriptCopyItems Include="Integration\test-csx\**\*.*" />