Skip to content
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
8 changes: 4 additions & 4 deletions test-outofproc/MultiFunctionTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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.Collections.Generic;
using DotnetIsolatedTests.Common;
using Microsoft.Extensions.Logging;
Expand All @@ -16,15 +15,15 @@ namespace DotnetIsolatedTests
/// </summary>
public static class MultiFunctionTrigger
{
private static readonly Action<ILogger, string, Exception> _loggerMessage = LoggerMessage.Define<string>(LogLevel.Information, eventId: new EventId(0, "INFO"), formatString: "{Message}");

[Function(nameof(MultiFunctionTrigger1))]
public static void MultiFunctionTrigger1(
[SqlTrigger("[dbo].[Products]", "SqlConnectionString")]
IReadOnlyList<SqlChange<Product>> products,
FunctionContext context)
{
_loggerMessage(context.GetLogger("ProductsTriggerWithValidation"), "Trigger1 Changes: " + Utils.JsonSerializeObject(products), null);
ILogger logger = context.GetLogger("MultiFunctionTrigger1");
logger.LogInformation("Trigger1 Changes: " + Utils.JsonSerializeObject(products), null);
}

[Function(nameof(MultiFunctionTrigger2))]
Expand All @@ -33,7 +32,8 @@ public static void MultiFunctionTrigger2(
IReadOnlyList<SqlChange<Product>> products,
FunctionContext context)
{
_loggerMessage(context.GetLogger("ProductsTriggerWithValidation"), "Trigger2 Changes: " + Utils.JsonSerializeObject(products), null);
ILogger logger = context.GetLogger("MultiFunctionTrigger1");
logger.LogInformation("Trigger2 Changes: " + Utils.JsonSerializeObject(products), null);
}
}
}
5 changes: 2 additions & 3 deletions test-outofproc/ProductsTriggerWithValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace DotnetIsolatedTests
{
public static class ProductsTriggerWithValidation
{
private static readonly Action<ILogger, string, Exception> _loggerMessage = LoggerMessage.Define<string>(LogLevel.Information, eventId: new EventId(0, "INFO"), formatString: "{Message}");

/// <summary>
/// Simple trigger function with additional logic to allow for verifying that the expected number
/// of changes was received in each batch.
Expand All @@ -24,13 +22,14 @@ public static void Run(
IReadOnlyList<SqlChange<Product>> changes,
FunctionContext context)
{
ILogger logger = context.GetLogger("ProductsTriggerWithValidation");
string expectedMaxBatchSize = Environment.GetEnvironmentVariable("TEST_EXPECTED_MAX_BATCH_SIZE");
if (!string.IsNullOrEmpty(expectedMaxBatchSize) && int.Parse(expectedMaxBatchSize, null) != changes.Count)
{
throw new InvalidOperationException($"Invalid max batch size, got {changes.Count} changes but expected {expectedMaxBatchSize}");
}
// The output is used to inspect the trigger binding parameter in test methods.
_loggerMessage(context.GetLogger("ProductsTriggerWithValidation"), "SQL Changes: " + Utils.JsonSerializeObject(changes), null);
logger.LogInformation("SQL Changes: " + Utils.JsonSerializeObject(changes), null);
}
}
}
3 changes: 2 additions & 1 deletion test-outofproc/TriggerWithException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public static class TriggerWithException
public static void Run(
[SqlTrigger("[dbo].[Products]", "SqlConnectionString")]
IReadOnlyList<SqlChange<Product>> changes,
ILogger logger)
FunctionContext context)
{
ILogger logger = context.GetLogger("TriggerWithException");
if (!threwException)
{
threwException = true;
Expand Down