Skip to content

Commit cf87b56

Browse files
authored
add csx trigger samples (#806)
* add trigger samples for csx * enable csx tests * add copy trigger sample * use utils.josnserialize * separate utils file * reuse utils from sql extension * remove deleted references
1 parent 4fd10b9 commit cf87b56

File tree

21 files changed

+229
-17
lines changed

21 files changed

+229
-17
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions"
4+
]
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"bindings": [
3+
{
4+
"name": "changes",
5+
"type": "sqlTrigger",
6+
"direction": "in",
7+
"tableName": "dbo.Products",
8+
"connectionStringSetting": "SqlConnectionString"
9+
}
10+
],
11+
"disabled": false
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#load "../../Common/product.csx"
2+
#r "Newtonsoft.Json"
3+
#r "Microsoft.Azure.WebJobs.Extensions.Sql"
4+
5+
using System.Net;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Primitives;
8+
using Newtonsoft.Json;
9+
using Microsoft.Azure.WebJobs.Extensions.Sql;
10+
11+
public static void Run(IReadOnlyList<SqlChange<Product>> changes, ILogger log)
12+
{
13+
log.LogInformation("SQL Changes: " + JsonConvert.SerializeObject(changes));
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "2.0",
3+
"logging": {
4+
"applicationInsights": {
5+
"samplingSettings": {
6+
"isEnabled": true,
7+
"excludedTypes": "Request"
8+
}
9+
}
10+
},
11+
"extensionBundle": {
12+
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
13+
"version": "[4.*, 5.0.0)"
14+
}
15+
}

test/Integration/SqlTriggerBindingIntegrationTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public SqlTriggerBindingIntegrationTests(ITestOutputHelper output = null) : base
3131
/// </summary>
3232
[Theory]
3333
[SqlInlineData()]
34-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
3534
public async Task SingleOperationTriggerTest(SupportedLanguages lang)
3635
{
3736
this.SetChangeTrackingForTable("Products");
@@ -80,7 +79,6 @@ await this.WaitForProductChanges(
8079
/// </summary>
8180
[Theory]
8281
[SqlInlineData()]
83-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
8482
public async Task BatchSizeOverrideTriggerTest(SupportedLanguages lang)
8583
{
8684
// Use enough items to require 4 batches to be processed but then
@@ -124,7 +122,6 @@ await this.WaitForProductChanges(
124122
/// </summary>
125123
[Theory]
126124
[SqlInlineData()]
127-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
128125
public async Task MaxBatchSizeOverrideTriggerTest(SupportedLanguages lang)
129126
{
130127
// Use enough items to require 4 batches to be processed but then
@@ -168,7 +165,6 @@ await this.WaitForProductChanges(
168165
/// </summary>
169166
[Theory]
170167
[SqlInlineData()]
171-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
172168
public async Task PollingIntervalOverrideTriggerTest(SupportedLanguages lang)
173169
{
174170
const int firstId = 1;
@@ -211,7 +207,6 @@ await this.WaitForProductChanges(
211207
/// </summary>
212208
[Theory]
213209
[SqlInlineData()]
214-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
215210
public async Task MultiOperationTriggerTest(SupportedLanguages lang)
216211
{
217212
int firstId = 1;
@@ -293,7 +288,6 @@ await this.WaitForProductChanges(
293288
/// </summary>
294289
[Theory]
295290
[SqlInlineData()]
296-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
297291
public async Task MultiFunctionTriggerTest(SupportedLanguages lang)
298292
{
299293
const string Trigger1Changes = "Trigger1 Changes: ";
@@ -420,7 +414,6 @@ public async Task MultiFunctionTriggerTest(SupportedLanguages lang)
420414
/// </summary>
421415
[Theory]
422416
[SqlInlineData()]
423-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
424417
public async Task MultiHostTriggerTest(SupportedLanguages lang)
425418
{
426419
this.SetChangeTrackingForTable("Products");
@@ -472,7 +465,6 @@ await this.WaitForProductChanges(
472465
/// </summary>
473466
[Theory]
474467
[SqlInlineData()]
475-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
476468
public void TableNotPresentTriggerTest(SupportedLanguages lang)
477469
{
478470
this.StartFunctionHostAndWaitForError(
@@ -487,7 +479,6 @@ public void TableNotPresentTriggerTest(SupportedLanguages lang)
487479
/// </summary>
488480
[Theory]
489481
[SqlInlineData()]
490-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
491482
public void PrimaryKeyNotCreatedTriggerTest(SupportedLanguages lang)
492483
{
493484
this.StartFunctionHostAndWaitForError(
@@ -503,7 +494,6 @@ public void PrimaryKeyNotCreatedTriggerTest(SupportedLanguages lang)
503494
/// </summary>
504495
[Theory]
505496
[SqlInlineData()]
506-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
507497
public void ReservedPrimaryKeyColumnNamesTriggerTest(SupportedLanguages lang)
508498
{
509499
this.StartFunctionHostAndWaitForError(
@@ -519,7 +509,6 @@ public void ReservedPrimaryKeyColumnNamesTriggerTest(SupportedLanguages lang)
519509
/// </summary>
520510
[Theory]
521511
[SqlInlineData()]
522-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
523512
public void UnsupportedColumnTypesTriggerTest(SupportedLanguages lang)
524513
{
525514
this.StartFunctionHostAndWaitForError(
@@ -535,7 +524,6 @@ public void UnsupportedColumnTypesTriggerTest(SupportedLanguages lang)
535524
/// </summary>
536525
[Theory]
537526
[SqlInlineData()]
538-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
539527
public void ChangeTrackingNotEnabledTriggerTest(SupportedLanguages lang)
540528
{
541529
this.StartFunctionHostAndWaitForError(
@@ -572,7 +560,6 @@ public async void GetMetricsTest()
572560
/// </summary>
573561
[Theory]
574562
[SqlInlineData()]
575-
[UnsupportedLanguages(SupportedLanguages.CSharpscript)]
576563
public void UnsupportedDatabaseThrows(SupportedLanguages lang)
577564
{
578565
// Change database compat level to unsupported version

test/Integration/test-csx/Common/Product.csx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
3-
4-
using System;
5-
using System.Linq;
6-
73
public class Product
84
{
95
public int ProductId { get; set; }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"bindings": [
3+
{
4+
"name": "changes",
5+
"type": "sqlTrigger",
6+
"direction": "in",
7+
"tableName": "dbo.Products",
8+
"connectionStringSetting": "SqlConnectionString"
9+
}
10+
],
11+
"disabled": false
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#load "../Common/Product.csx"
2+
#r "Newtonsoft.Json"
3+
#r "Microsoft.Azure.WebJobs.Extensions.Sql"
4+
5+
using System.Net;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Primitives;
8+
using Newtonsoft.Json;
9+
using Microsoft.Azure.WebJobs.Extensions.Sql;
10+
11+
public static void Run(IReadOnlyList<SqlChange<Product>> changes, ILogger log)
12+
{
13+
log.LogInformation("Trigger1 Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes));
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"bindings": [
3+
{
4+
"name": "changes",
5+
"type": "sqlTrigger",
6+
"direction": "in",
7+
"tableName": "dbo.Products",
8+
"connectionStringSetting": "SqlConnectionString"
9+
}
10+
],
11+
"disabled": false
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#load "../Common/Product.csx"
2+
#r "Newtonsoft.Json"
3+
#r "Microsoft.Azure.WebJobs.Extensions.Sql"
4+
5+
using System.Net;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Primitives;
8+
using Newtonsoft.Json;
9+
using Microsoft.Azure.WebJobs.Extensions.Sql;
10+
11+
public static void Run(IReadOnlyList<SqlChange<Product>> changes, ILogger log)
12+
{
13+
log.LogInformation("Trigger2 Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes));
14+
}

0 commit comments

Comments
 (0)