Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 1 addition & 2 deletions samples/samples-powershell/ProductsTrigger/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
using namespace System.Net

param($changes)
$changesJson = $changes | ConvertTo-Json
# The output is used to inspect the trigger binding parameter in test methods.
# Removing new lines for testing purposes.
$changesJson = $changesJson -replace [Environment]::NewLine,"";
$changesJson = $changes | ConvertTo-Json -Compress

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment for what -Compress does?

Write-Host "SQL Changes: $changesJson"
48 changes: 30 additions & 18 deletions test/Integration/SqlTriggerBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ await this.WaitForProductChanges(
/// <summary>
/// Verifies that manually setting the polling interval correctly changes the delay between processing each batch of changes
/// </summary>
[Fact]
public async Task PollingIntervalOverrideTriggerTest()
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.OutOfProc)]
public async Task PollingIntervalOverrideTriggerTest(SupportedLanguages lang)
{
const int firstId = 1;
// Use enough items to require 5 batches to be processed - the test will
Expand All @@ -184,7 +186,7 @@ public async Task PollingIntervalOverrideTriggerTest()
pollingIntervalMs.ToString());
this.StartFunctionHost(
nameof(ProductsTriggerWithValidation),
SupportedLanguages.CSharp,
lang,
useTestFolder: true,
customOutputHandler: handler,
environmentVariables: new Dictionary<string, string>() {
Expand Down Expand Up @@ -289,16 +291,18 @@ await this.WaitForProductChanges(
/// <summary>
/// Ensures correct functionality with multiple user functions tracking the same table.
/// </summary>
[Fact]
public async Task MultiFunctionTriggerTest()
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.OutOfProc)]
public async Task MultiFunctionTriggerTest(SupportedLanguages lang)
{
const string Trigger1Changes = "Trigger1 Changes: ";
const string Trigger2Changes = "Trigger2 Changes: ";

this.SetChangeTrackingForTable("Products");

string functionList = $"{nameof(MultiFunctionTrigger.MultiFunctionTrigger1)} {nameof(MultiFunctionTrigger.MultiFunctionTrigger2)}";
this.StartFunctionHost(functionList, SupportedLanguages.CSharp, useTestFolder: true);
this.StartFunctionHost(functionList, lang, useTestFolder: true);

// 1. INSERT
int firstId = 1;
Expand Down Expand Up @@ -466,25 +470,29 @@ await this.WaitForProductChanges(
/// <summary>
/// Tests the error message when the user table is not present in the database.
/// </summary>
[Fact]
public void TableNotPresentTriggerTest()
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.OutOfProc)]
public void TableNotPresentTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
nameof(TableNotPresentTrigger),
SupportedLanguages.CSharp,
lang,
true,
"Could not find table: 'dbo.TableNotPresent'.");
}

/// <summary>
/// Tests the error message when the user table does not contain primary key.
/// </summary>
[Fact]
public void PrimaryKeyNotCreatedTriggerTest()
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.OutOfProc)]
public void PrimaryKeyNotCreatedTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
nameof(PrimaryKeyNotPresentTrigger),
SupportedLanguages.CSharp,
lang,
true,
"Could not find primary key created in table: 'dbo.ProductsWithoutPrimaryKey'.");
}
Expand All @@ -493,12 +501,14 @@ public void PrimaryKeyNotCreatedTriggerTest()
/// Tests the error message when the user table contains one or more primary keys with names conflicting with
/// column names in the leases table.
/// </summary>
[Fact]
public void ReservedPrimaryKeyColumnNamesTriggerTest()
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.OutOfProc)]
public void ReservedPrimaryKeyColumnNamesTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
nameof(ReservedPrimaryKeyColumnNamesTrigger),
SupportedLanguages.CSharp,
lang,
true,
"Found reserved column name(s): '_az_func_ChangeVersion', '_az_func_AttemptCount', '_az_func_LeaseExpirationTime' in table: 'dbo.ProductsWithReservedPrimaryKeyColumnNames'." +
" Please rename them to be able to use trigger binding.");
Expand All @@ -507,12 +517,14 @@ public void ReservedPrimaryKeyColumnNamesTriggerTest()
/// <summary>
/// Tests the error message when the user table contains columns of unsupported SQL types.
/// </summary>
[Fact]
public void UnsupportedColumnTypesTriggerTest()
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.OutOfProc)]
public void UnsupportedColumnTypesTriggerTest(SupportedLanguages lang)
{
this.StartFunctionHostAndWaitForError(
nameof(UnsupportedColumnTypesTrigger),
SupportedLanguages.CSharp,
lang,
true,
"Found column(s) with unsupported type(s): 'Location' (type: geography), 'Geometry' (type: geometry), 'Organization' (type: hierarchyid)" +
" in table: 'dbo.ProductsWithUnsupportedColumnTypes'.");
Expand Down
12 changes: 12 additions & 0 deletions test/Integration/test-js/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
}
6 changes: 6 additions & 0 deletions test/Integration/test-js/MultiFunctionTrigger1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

module.exports = async function (context, changes) {
context.log(`Trigger1 Changes: ${JSON.stringify(changes)}`)
}
12 changes: 12 additions & 0 deletions test/Integration/test-js/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
}
6 changes: 6 additions & 0 deletions test/Integration/test-js/MultiFunctionTrigger2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

module.exports = async function (context, changes) {
context.log(`Trigger2 Changes: ${JSON.stringify(changes)}`)
}
12 changes: 12 additions & 0 deletions test/Integration/test-js/PrimaryKeyNotPresentTrigger/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.ProductsWithoutPrimaryKey",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
6 changes: 6 additions & 0 deletions test/Integration/test-js/PrimaryKeyNotPresentTrigger/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

module.exports = async function (context, changes) {
throw new Error("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.ProductsWithReservedPrimaryKeyColumnNames",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

module.exports = async function (context, changes) {
throw new Error("Associated test case should fail before the function is invoked.");
}
12 changes: 12 additions & 0 deletions test/Integration/test-js/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
}
6 changes: 6 additions & 0 deletions test/Integration/test-js/TableNotPresentTrigger/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

module.exports = async function (context, changes) {
throw new Error("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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

module.exports = async function (context, changes) {
throw new Error("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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

using namespace System.Net

param($changes)
$changesJson = $changes | ConvertTo-Json -Compress
Write-Host "Trigger1 Changes: $changesJson"
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,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

using namespace System.Net

param($changes)
$changesJson = $changes | ConvertTo-Json -Compress
Write-Host "Trigger2 Changes: $changesJson"
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

using namespace System.Net

param($changes)

throw "Associated test case should fail before the function is invoked."
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ if ($expectedMaxBatchSize -and $expectedMaxBatchSize -ne $changes.Count) {
throw "Invalid max batch size, got $($changes.Count) changes but expected $expectedMaxBatchSize"
}

$changesJson = $changes | ConvertTo-Json
$changesJson = $changesJson -replace [Environment]::NewLine,"";
$changesJson = $changes | ConvertTo-Json -Compress
Write-Host "SQL Changes: $changesJson"
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,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

using namespace System.Net

param($changes)

throw "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.TableNotPresent",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

using namespace System.Net

param($changes)

throw "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
}
Loading