Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add csx trigger samples #806

Merged
merged 8 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.Products",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> changes, ILogger log)
{
log.LogInformation("SQL Changes: " + JsonConvert.SerializeObject(changes));
}
15 changes: 15 additions & 0 deletions samples/samples-csharpscript/TriggerBindingSamples/host.json
Original file line number Diff line number Diff line change
@@ -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)"
}
}
13 changes: 0 additions & 13 deletions test/Integration/SqlTriggerBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public SqlTriggerBindingIntegrationTests(ITestOutputHelper output = null) : base
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public async Task SingleOperationTriggerTest(SupportedLanguages lang)
{
this.SetChangeTrackingForTable("Products");
Expand Down Expand Up @@ -80,7 +79,6 @@ await this.WaitForProductChanges(
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public async Task BatchSizeOverrideTriggerTest(SupportedLanguages lang)
{
// Use enough items to require 4 batches to be processed but then
Expand Down Expand Up @@ -124,7 +122,6 @@ await this.WaitForProductChanges(
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public async Task MaxBatchSizeOverrideTriggerTest(SupportedLanguages lang)
{
// Use enough items to require 4 batches to be processed but then
Expand Down Expand Up @@ -168,7 +165,6 @@ await this.WaitForProductChanges(
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public async Task PollingIntervalOverrideTriggerTest(SupportedLanguages lang)
{
const int firstId = 1;
Expand Down Expand Up @@ -211,7 +207,6 @@ await this.WaitForProductChanges(
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public async Task MultiOperationTriggerTest(SupportedLanguages lang)
{
int firstId = 1;
Expand Down Expand Up @@ -293,7 +288,6 @@ await this.WaitForProductChanges(
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public async Task MultiFunctionTriggerTest(SupportedLanguages lang)
{
const string Trigger1Changes = "Trigger1 Changes: ";
Expand Down Expand Up @@ -420,7 +414,6 @@ public async Task MultiFunctionTriggerTest(SupportedLanguages lang)
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public async Task MultiHostTriggerTest(SupportedLanguages lang)
{
this.SetChangeTrackingForTable("Products");
Expand Down Expand Up @@ -472,7 +465,6 @@ await this.WaitForProductChanges(
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public void TableNotPresentTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
Expand All @@ -487,7 +479,6 @@ public void TableNotPresentTriggerTest(SupportedLanguages lang)
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public void PrimaryKeyNotCreatedTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
Expand All @@ -503,7 +494,6 @@ public void PrimaryKeyNotCreatedTriggerTest(SupportedLanguages lang)
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public void ReservedPrimaryKeyColumnNamesTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
Expand All @@ -519,7 +509,6 @@ public void ReservedPrimaryKeyColumnNamesTriggerTest(SupportedLanguages lang)
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public void UnsupportedColumnTypesTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
Expand All @@ -535,7 +524,6 @@ public void UnsupportedColumnTypesTriggerTest(SupportedLanguages lang)
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public void ChangeTrackingNotEnabledTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
Expand Down Expand Up @@ -572,7 +560,6 @@ public async void GetMetricsTest()
/// </summary>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
public void UnsupportedDatabaseThrows(SupportedLanguages lang)
{
// Change database compat level to unsupported version
Expand Down
4 changes: 0 additions & 4 deletions test/Integration/test-csx/Common/Product.csx
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
12 changes: 12 additions & 0 deletions test/Integration/test-csx/MultiFunctionTrigger1/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.Products",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
14 changes: 14 additions & 0 deletions test/Integration/test-csx/MultiFunctionTrigger1/run.csx
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> changes, ILogger log)
{
log.LogInformation("Trigger1 Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes));
}
12 changes: 12 additions & 0 deletions test/Integration/test-csx/MultiFunctionTrigger2/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.Products",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
14 changes: 14 additions & 0 deletions test/Integration/test-csx/MultiFunctionTrigger2/run.csx
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> changes, ILogger log)
{
log.LogInformation("Trigger2 Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.ProductsWithoutPrimaryKey",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
14 changes: 14 additions & 0 deletions test/Integration/test-csx/PrimaryKeyNotPresentTrigger/run.csx
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> changes, ILogger log)
{
throw new NotImplementedException("Associated test case should fail before the function is invoked.");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.Products",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
20 changes: 20 additions & 0 deletions test/Integration/test-csx/ProductsTriggerWithValidation/run.csx
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> 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));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.ProductsWithReservedPrimaryKeyColumnNames",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> changes, ILogger log)
{
throw new NotImplementedException("Associated test case should fail before the function is invoked.");
}
12 changes: 12 additions & 0 deletions test/Integration/test-csx/TableNotPresentTrigger/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.TableNotPresent",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
12 changes: 12 additions & 0 deletions test/Integration/test-csx/TableNotPresentTrigger/run.csx
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> changes, ILogger log)
{
throw new NotImplementedException("Associated test case should fail before the function is invoked.");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "changes",
"type": "sqlTrigger",
"direction": "in",
"tableName": "dbo.ProductsWithUnsupportedColumnTypes",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
12 changes: 12 additions & 0 deletions test/Integration/test-csx/UnsupportedColumnTypesTrigger/run.csx
Original file line number Diff line number Diff line change
@@ -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<SqlChange<Product>> changes, ILogger log)
{
throw new NotImplementedException("Associated test case should fail before the function is invoked.");
}
1 change: 1 addition & 0 deletions test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<ItemGroup>
<_CSharpScriptCopyItems Include="..\samples\samples-csharpscript\InputBindingSamples\**\*.*" />
<_CSharpScriptCopyItems Include="..\samples\samples-csharpscript\OutputBindingSamples\**\*.*" />
<_CSharpScriptCopyItems Include="..\samples\samples-csharpscript\TriggerBindingSamples\**\*.*" />
<_CSharpScriptCopyItems Include="Integration\test-csx\**\*.*" />
</ItemGroup>
<Copy SourceFiles="@(_CSharpScriptCopyItems)" DestinationFolder="$(OutDir)\SqlExtensionSamples\CSharpscript\%(RecursiveDir)" />
Expand Down