From 739a0bbc71745b74f1751194d2c0701a67340233 Mon Sep 17 00:00:00 2001
From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Wed, 21 Dec 2022 13:07:14 +0100
Subject: [PATCH 1/4] feat: set isolated project option as default az func
worker
---
.../azurefunctions-eventhubs-template.md | 4 +-
...zurefunctions-servicebus-queue-template.md | 4 +-
...zurefunctions-servicebus-topic-template.md | 4 +-
.../.template.config/template.json | 2 +-
.../.template.config/template.json | 2 +-
.../.template.config/template.json | 2 +-
.../AzureFunctions/AzureFunctionsProject.cs | 35 +++++++++++++---
.../AzureFunctionsProjectOptions.cs | 40 +++++++++++++++++++
.../AzureFunctionsDatabricksProject.cs | 8 ++--
.../AzureFunctionsDatabricksProjectOptions.cs | 7 ++--
.../AzureFunctionsEventHubsProject.cs | 26 ++++--------
.../AzureFunctionsEventHubsProjectOptions.cs | 29 ++------------
.../Http/AzureFunctionsHttpProject.cs | 22 ++--------
.../Http/AzureFunctionsHttpProjectOptions.cs | 25 +-----------
.../AzureFunctionsServiceBusProject.cs | 32 ++++++---------
.../AzureFunctionsServiceBusProjectOptions.cs | 28 ++-----------
.../ServiceBus/Logging/SerilogLoggingTests.cs | 6 +++
17 files changed, 124 insertions(+), 152 deletions(-)
create mode 100644 src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProjectOptions.cs
diff --git a/docs/preview/features/azurefunctions-eventhubs-template.md b/docs/preview/features/azurefunctions-eventhubs-template.md
index b1c9fad6..89f1d5bc 100644
--- a/docs/preview/features/azurefunctions-eventhubs-template.md
+++ b/docs/preview/features/azurefunctions-eventhubs-template.md
@@ -31,7 +31,7 @@ Creates a starter worker project with by default configured:
And additional features available with options:
* `--functions-worker`: Configures the type of Azure Functions worker type the project should target.
- * `inProcess` (default): Uses the in-process Azure Functions worker type which runs on the same process as run Azure Function
- * `isolated`: Uses the isolated Azure Functions worker type which runs on a different process as the Azure Function
+ * `isolated` (default): Uses the isolated Azure Functions worker type which runs on a different process as the Azure Function
+ * `inProcess`: Uses the in-process Azure Functions worker type which runs on the same process as run Azure Function
For more information on the difference between the two, see [Microsoft's documentation](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide).
* `-es|--exclude-serilog`: Exclude the [Serilog](https://serilog.net/) logging infrastructure in the worker project which includes default enrichers ([version](https://observability.arcus-azure.net/features/telemetry-enrichment#version-enricher) and [application](https://observability.arcus-azure.net/features/telemetry-enrichment#application-enricher)), and sinking to Application Insights.
\ No newline at end of file
diff --git a/docs/preview/features/azurefunctions-servicebus-queue-template.md b/docs/preview/features/azurefunctions-servicebus-queue-template.md
index 43de002a..a34086e6 100644
--- a/docs/preview/features/azurefunctions-servicebus-queue-template.md
+++ b/docs/preview/features/azurefunctions-servicebus-queue-template.md
@@ -31,7 +31,7 @@ Creates a starter worker project with by default configured:
And additional features available with options:
* `--functions-worker`: Configures the type of Azure Functions worker type the project should target.
- * `inProcess` (default): Uses the in-process Azure Functions worker type which runs on the same process as run Azure Function
- * `isolated`: Uses the isolated Azure Functions worker type which runs on a different process as the Azure Function
+ * `isolated` (default): Uses the isolated Azure Functions worker type which runs on a different process as the Azure Function
+ * `inProcess`: Uses the in-process Azure Functions worker type which runs on the same process as run Azure Function
For more information on the difference between the two, see [Microsoft's documentation](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide).
* `--exclude-serilog`: Exclude the [Serilog](https://serilog.net/) logging infrastructure in the Azure Functions project which includes default enrichers ([version](https://observability.arcus-azure.net/features/telemetry-enrichment#version-enricher) and [application](https://observability.arcus-azure.net/features/telemetry-enrichment#application-enricher)), and sinking to Application Insights.
\ No newline at end of file
diff --git a/docs/preview/features/azurefunctions-servicebus-topic-template.md b/docs/preview/features/azurefunctions-servicebus-topic-template.md
index 4ea0cae2..cee931d2 100644
--- a/docs/preview/features/azurefunctions-servicebus-topic-template.md
+++ b/docs/preview/features/azurefunctions-servicebus-topic-template.md
@@ -31,7 +31,7 @@ Creates a starter worker project with by default configured:
And additional features available with options:
* `--functions-worker`: Configures the type of Azure Functions worker type the project should target.
- * `inProcess` (default): Uses the in-process Azure Functions worker type which runs on the same process as run Azure Function
- * `isolated`: Uses the isolated Azure Functions worker type which runs on a different process as the Azure Function
+ * `isolated` (default): Uses the isolated Azure Functions worker type which runs on a different process as the Azure Function
+ * `inProcess`: Uses the in-process Azure Functions worker type which runs on the same process as run Azure Function
For more information on the difference between the two, see [Microsoft's documentation](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide).
* `--exclude-serilog`: Exclude the [Serilog](https://serilog.net/) logging infrastructure in the Azure Functions project which includes default enrichers ([version](https://observability.arcus-azure.net/features/telemetry-enrichment#version-enricher) and [application](https://observability.arcus-azure.net/features/telemetry-enrichment#application-enricher)), and sinking to Application Insights.
\ No newline at end of file
diff --git a/src/Arcus.Templates.AzureFunctions.EventHubs/.template.config/template.json b/src/Arcus.Templates.AzureFunctions.EventHubs/.template.config/template.json
index 0aae279d..5c3234a6 100644
--- a/src/Arcus.Templates.AzureFunctions.EventHubs/.template.config/template.json
+++ b/src/Arcus.Templates.AzureFunctions.EventHubs/.template.config/template.json
@@ -88,7 +88,7 @@
"description": "Uses Azure Functions isolated worker template"
}
],
- "defaultValue": "inProcess",
+ "defaultValue": "isolated",
"description": "Chooses the kind of Azure Functions worker template"
},
"InProcess": {
diff --git a/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/.template.config/template.json b/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/.template.config/template.json
index a4124c5a..7c3909cf 100644
--- a/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/.template.config/template.json
+++ b/src/Arcus.Templates.AzureFunctions.ServiceBus.Queue/.template.config/template.json
@@ -90,7 +90,7 @@
"description": "Uses Azure Functions isolated worker template"
}
],
- "defaultValue": "inProcess",
+ "defaultValue": "isolated",
"description": "Chooses the kind of Azure Functions worker template"
},
"InProcess": {
diff --git a/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/.template.config/template.json b/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/.template.config/template.json
index fa719542..fcc931c1 100644
--- a/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/.template.config/template.json
+++ b/src/Arcus.Templates.AzureFunctions.ServiceBus.Topic/.template.config/template.json
@@ -90,7 +90,7 @@
"description": "Uses Azure Functions isolated worker template"
}
],
- "defaultValue": "inProcess",
+ "defaultValue": "isolated",
"description": "Chooses the kind of Azure Functions worker template"
},
"InProcess": {
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProject.cs
index dc18b5ab..957c050f 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProject.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProject.cs
@@ -29,11 +29,13 @@ public abstract class AzureFunctionsProject : TemplateProject
///
/// The file directory where the .NET project template is located.
/// The configuration instance to retrieve Azure Functions-specific test values.
+ /// The options used to manipulate the resulting Azure Functions project.
/// The logger instance to write diagnostic trace messages during the lifetime of the test project.
/// Thrown when the , , or is null.
protected AzureFunctionsProject(
DirectoryInfo templateDirectory,
TestConfig configuration,
+ AzureFunctionsProjectOptions options,
ITestOutputHelper outputWriter)
: base(templateDirectory,
configuration.GetFixtureProjectDirectory(),
@@ -44,11 +46,23 @@ protected AzureFunctionsProject(
Guard.NotNull(outputWriter, nameof(outputWriter), "Requires an logger instance to write diagnostic trace messages during the lifetime of the project.");
Configuration = configuration;
+ FunctionsWorker = options.FunctionsWorker;
+ RuntimeFileName = DetermineStartupCodeFileName();
RootEndpoint = configuration.GenerateRandomLocalhostUrl().ResetToRoot().ToUri();
AzureFunctionsConfig = configuration.GetAzureFunctionsConfig();
ApplicationInsightsConfig = configuration.GetApplicationInsightsConfig();
}
+ ///
+ /// Gets the Azure Functions worker type the project should target.
+ ///
+ public FunctionsWorker FunctionsWorker { get; }
+
+ ///
+ /// Gets the file name of the Azure Functions that contains the startup code ('Startup.cs' for in-process functions, 'Program.cs' for isolated functions).
+ ///
+ public string RuntimeFileName { get; }
+
///
/// Gets the root endpoint on which the Azure Function is running.
///
@@ -72,23 +86,34 @@ protected AzureFunctionsProject(
///
/// Adds an test Azure storage account connection string to the Azure Function project so the project can start up correctly.
///
- protected void AddLocalSettings(FunctionsWorker workerType)
+ protected void AddLocalSettings()
{
string storageAccountConnectionString = AzureFunctionsConfig.StorageAccountConnectionString;
- string workerRuntime = DetermineWorkerRuntime(workerType);
+ string workerRuntime = DetermineWorkerRuntime();
AddFileInProject("local.settings.json",
$"{{ \"IsEncrypted\": false, \"Values\": {{ \"AzureWebJobsStorage\": \"{storageAccountConnectionString}\", \"FUNCTIONS_WORKER_RUNTIME\": \"{workerRuntime}\", \"APPLICATIONINSIGHTS_CONNECTION_STRING\": \"\" }}, \"Host\": {{ \"LocalHttpPort\": {RootEndpoint.Port} }} }}");
}
- private static string DetermineWorkerRuntime(FunctionsWorker workerType)
+ private string DetermineWorkerRuntime()
{
- switch (workerType)
+ switch (FunctionsWorker)
{
case FunctionsWorker.InProcess: return "dotnet";
case FunctionsWorker.Isolated: return "dotnet-isolated";
default:
- throw new ArgumentOutOfRangeException(nameof(workerType), workerType, "Unknown Azure Functions worker type");
+ throw new ArgumentOutOfRangeException(nameof(FunctionsWorker), FunctionsWorker, "Unknown Azure Functions worker type");
+ }
+ }
+
+ private string DetermineStartupCodeFileName()
+ {
+ switch (FunctionsWorker)
+ {
+ case FunctionsWorker.InProcess: return "Startup.cs";
+ case FunctionsWorker.Isolated: return "Program.cs";
+ default:
+ throw new ArgumentOutOfRangeException(nameof(FunctionsWorker), FunctionsWorker, "Unknown Azure Functions worker type");
}
}
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProjectOptions.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProjectOptions.cs
new file mode 100644
index 00000000..af26aa60
--- /dev/null
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/AzureFunctionsProjectOptions.cs
@@ -0,0 +1,40 @@
+using System;
+using Arcus.Templates.Tests.Integration.Fixture;
+
+namespace Arcus.Templates.Tests.Integration.AzureFunctions
+{
+ ///
+ /// Represents an simple set of options used in the Azure Functions project templates.
+ ///
+ public class AzureFunctionsProjectOptions : ProjectOptions
+ {
+ ///
+ /// Gets the Azure Functions worker type the project should target.
+ ///
+ public FunctionsWorker FunctionsWorker { get; protected set; } = FunctionsWorker.Isolated;
+
+ ///
+ /// Sets the Azure Functions worker type of the project template.
+ ///
+ /// The functions worker type.
+ /// Thrown when the is outside the bounds of the enumeration.
+ protected void SetFunctionsWorker(FunctionsWorker workerType)
+ {
+ string workerTyperArgument = DetermineFunctionsWorkerArgument(workerType);
+ AddOption($"--functions-worker {workerTyperArgument}");
+
+ FunctionsWorker = workerType;
+ }
+
+ private static string DetermineFunctionsWorkerArgument(FunctionsWorker workerType)
+ {
+ switch (workerType)
+ {
+ case FunctionsWorker.InProcess: return "inProcess";
+ case FunctionsWorker.Isolated: return "isolated";
+ default:
+ throw new ArgumentOutOfRangeException(nameof(workerType), workerType, "Unknown functions worker type");
+ }
+ }
+ }
+}
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProject.cs
index e924dcf0..fa0c9e00 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProject.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProject.cs
@@ -26,9 +26,11 @@ public class AzureFunctionsDatabricksProject : AzureFunctionsProject
private AzureFunctionsDatabricksProject(
TestConfig configuration,
+ AzureFunctionsDatabricksProjectOptions options,
ITestOutputHelper outputWriter)
: base(configuration.GetAzureFunctionsDatabricksJobMetricsProjectDirectory(),
configuration,
+ options,
outputWriter)
{
AzureFunctionDatabricksConfig = configuration.GetDatabricksConfig();
@@ -89,10 +91,10 @@ public static async Task StartNewAsync(TestConf
private static AzureFunctionsDatabricksProject CreateNew(TestConfig configuration, AzureFunctionsDatabricksProjectOptions options, ITestOutputHelper outputWriter)
{
- var project = new AzureFunctionsDatabricksProject(configuration, outputWriter);
+ var project = new AzureFunctionsDatabricksProject(configuration, options, outputWriter);
project.CreateNewProject(options);
project.AddDatabricksSecurityToken(project.AzureFunctionDatabricksConfig.SecurityToken);
- project.AddLocalSettings(FunctionsWorker.InProcess);
+ project.AddLocalSettings();
return project;
}
@@ -107,7 +109,7 @@ private void AddDatabricksSecurityToken(string securityToken)
{
AddTypeAsFile();
- UpdateFileInProject("Startup.cs", contents =>
+ UpdateFileInProject(RuntimeFileName, contents =>
RemovesUserErrorsFromContents(contents)
.Replace("AddAzureKeyVaultWithManagedIdentity(\"https://your-keyvault.vault.azure.net/\", CacheConfiguration.Default)",
$"AddProvider(new {nameof(SingleValueSecretProvider)}(\"{securityToken}\"))"));
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProjectOptions.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProjectOptions.cs
index 7c51382a..ddde6acc 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProjectOptions.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Databricks/JobMetrics/AzureFunctionsDatabricksProjectOptions.cs
@@ -1,17 +1,16 @@
-using Arcus.Templates.Tests.Integration.Fixture;
-
-namespace Arcus.Templates.Tests.Integration.AzureFunctions.Databricks.JobMetrics
+namespace Arcus.Templates.Tests.Integration.AzureFunctions.Databricks.JobMetrics
{
///
/// Represents the additional user project options to change the project contents and functionality.
///
- public class AzureFunctionsDatabricksProjectOptions : ProjectOptions
+ public class AzureFunctionsDatabricksProjectOptions : AzureFunctionsProjectOptions
{
///
/// Initializes a new instance of the class.
///
public AzureFunctionsDatabricksProjectOptions()
{
+ FunctionsWorker = FunctionsWorker.InProcess;
}
///
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs
index 9e7a0da6..9556fc50 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProject.cs
@@ -11,15 +11,16 @@
namespace Arcus.Templates.Tests.Integration.AzureFunctions.EventHubs
{
///
- /// Project template to create Azure Functions EventHubs triger projects.
+ /// Project template to create Azure Functions EventHubs trigger projects.
///
public class AzureFunctionsEventHubsProject : AzureFunctionsProject, IAsyncDisposable
{
private AzureFunctionsEventHubsProject(
TestEventHubsMessageProducer messageProducer,
TestConfig config,
+ AzureFunctionsEventHubsProjectOptions options,
ITestOutputHelper outputWriter)
- : base(config.GetAzureFunctionsEventHubsProjectDirectory(), config, outputWriter)
+ : base(config.GetAzureFunctionsEventHubsProjectDirectory(), config, options, outputWriter)
{
MessagePump = new MessagePumpService(messageProducer, config, outputWriter);
}
@@ -82,16 +83,16 @@ private static AzureFunctionsEventHubsProject CreateNew(
{
EventHubsConfig eventHubsConfig = configuration.GetEventHubsConfig();
var producer = new TestEventHubsMessageProducer(eventHubsConfig.EventHubsName, eventHubsConfig.EventHubsConnectionString);
- var project = new AzureFunctionsEventHubsProject(producer, configuration, outputWriter);
+ var project = new AzureFunctionsEventHubsProject(producer, configuration, options, outputWriter);
project.CreateNewProject(options);
- project.AddTestMessageHandler(eventHubsConfig, options);
- project.AddLocalSettings(options.FunctionsWorker);
+ project.AddTestMessageHandler(eventHubsConfig);
+ project.AddLocalSettings();
return project;
}
- private void AddTestMessageHandler(EventHubsConfig eventHubsConfig, AzureFunctionsEventHubsProjectOptions options)
+ private void AddTestMessageHandler(EventHubsConfig eventHubsConfig)
{
AddPackage("Arcus.EventGrid.Core", "3.3.0");
AddTypeAsFile();
@@ -104,18 +105,7 @@ private void AddTestMessageHandler(EventHubsConfig eventHubsConfig, AzureFunctio
contents => contents.Replace("EventHubTrigger(\"sensors\"", $"EventHubTrigger(\"{eventHubsConfig.EventHubsName}\"")
.Replace("var data = new EventData(message);", $"var data = new EventData(message);{Environment.NewLine}data.CorrelationId = properties[\"Operation-Id\"].GetString();"));
- string fileName = "";
- if (options.FunctionsWorker is FunctionsWorker.InProcess)
- {
- fileName = "Startup.cs";
- }
-
- if (options.FunctionsWorker is FunctionsWorker.Isolated)
- {
- fileName = "Program.cs";
- }
-
- UpdateFileInProject(fileName, contents =>
+ UpdateFileInProject(RuntimeFileName, contents =>
RemovesUserErrorsFromContents(contents)
.Replace(".MinimumLevel.Debug()", ".MinimumLevel.Verbose()")
.Replace("SensorReadingAzureEventHubsMessageHandler", nameof(TestOrdersAzureEventHubsMessageHandler))
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProjectOptions.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProjectOptions.cs
index ad2a0416..da5ba165 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProjectOptions.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/EventHubs/AzureFunctionsEventHubsProjectOptions.cs
@@ -1,12 +1,9 @@
-using System;
-using Arcus.Templates.Tests.Integration.Fixture;
-
-namespace Arcus.Templates.Tests.Integration.AzureFunctions.EventHubs
+namespace Arcus.Templates.Tests.Integration.AzureFunctions.EventHubs
{
///
/// Represents the available options for the Azure Functions EventHubs projects.
///
- public class AzureFunctionsEventHubsProjectOptions : ProjectOptions
+ public class AzureFunctionsEventHubsProjectOptions : AzureFunctionsProjectOptions
{
///
/// Initializes a new instance of the class.
@@ -15,36 +12,16 @@ public AzureFunctionsEventHubsProjectOptions()
{
}
- ///
- /// Gets the Azure Functions worker type the project should target.
- ///
- public FunctionsWorker FunctionsWorker { get; private set; } = FunctionsWorker.InProcess;
-
///
/// Sets the Azure Functions worker type to the project options when running the project template.
///
/// The Azure Functions worker type the project should target.
public AzureFunctionsEventHubsProjectOptions WithFunctionWorker(FunctionsWorker workerType)
{
- FunctionsWorker = workerType;
-
- string workerTypeArgument = DetermineFunctionWorkerArgument(workerType);
- AddOption($"--functions-worker {workerTypeArgument}");
-
+ SetFunctionsWorker(workerType);
return this;
}
- private static string DetermineFunctionWorkerArgument(FunctionsWorker workerType)
- {
- switch (workerType)
- {
- case FunctionsWorker.InProcess: return "inProcess";
- case FunctionsWorker.Isolated: return "isolated";
- default:
- throw new ArgumentOutOfRangeException(nameof(workerType), workerType, "Unknown function worker type");
- }
- }
-
///
/// Adds the project option to exclude the Serilog logging infrastructure from the Azure Functions project.
///
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs
index fc178ac6..71f95072 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProject.cs
@@ -35,9 +35,9 @@ private AzureFunctionsHttpProject(
ITestOutputHelper outputWriter)
: base(configuration.GetAzureFunctionsHttpProjectDirectory(),
configuration,
+ options,
outputWriter)
{
- RuntimeFileName = DetermineStartupCodeFileName(options.FunctionsWorker);
OrderFunctionEndpoint = RootEndpoint.AppendPathSegments("api", "v1", "order").ToUri();
Order = new OrderService(OrderFunctionEndpoint, outputWriter);
Health = new HealthEndpointService(
@@ -49,22 +49,6 @@ private AzureFunctionsHttpProject(
outputWriter);
}
- private static string DetermineStartupCodeFileName(FunctionsWorker workerType)
- {
- switch (workerType)
- {
- case FunctionsWorker.InProcess: return "Startup.cs";
- case FunctionsWorker.Isolated: return "Program.cs";
- default:
- throw new ArgumentOutOfRangeException(nameof(workerType), workerType, "Unknown Azure Functions worker type");
- }
- }
-
- ///
- /// Gets the file name of the Azure Functions that contains the startup code ('Startup.cs' for in-process functions, 'Program.cs' for isolated functions).
- ///
- public string RuntimeFileName { get; }
-
///
/// Gets the endpoint of the order Azure Function.
///
@@ -186,7 +170,7 @@ public static AzureFunctionsHttpProject CreateNew(TestConfig configuration, ITes
AzureFunctionsHttpProject project = CreateNew(configuration, new AzureFunctionsHttpProjectOptions(), outputWriter);
return project;
- }
+ }
///
/// Creates a new temporary project based on the Azure Functions HTTP trigger project template.
@@ -208,7 +192,7 @@ public static AzureFunctionsHttpProject CreateNew(TestConfig configuration, Azur
var project = new AzureFunctionsHttpProject(configuration, options, outputWriter);
project.CreateNewProject(options);
- project.AddLocalSettings(options.FunctionsWorker);
+ project.AddLocalSettings();
project.UpdateFileInProject(project.RuntimeFileName, contents => project.RemovesUserErrorsFromContents(contents));
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProjectOptions.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProjectOptions.cs
index 5dd09cf9..a6816c2d 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProjectOptions.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/AzureFunctionsHttpProjectOptions.cs
@@ -1,12 +1,11 @@
using System;
-using Arcus.Templates.Tests.Integration.Fixture;
namespace Arcus.Templates.Tests.Integration.AzureFunctions.Http
{
///
/// Represents the additional consumer options for the .
///
- public class AzureFunctionsHttpProjectOptions : ProjectOptions
+ public class AzureFunctionsHttpProjectOptions : AzureFunctionsProjectOptions
{
///
/// Initializes a new instance of the class.
@@ -15,11 +14,6 @@ public AzureFunctionsHttpProjectOptions()
{
}
- ///
- /// Gets the Azure Functions worker type the project should target.
- ///
- public FunctionsWorker FunctionsWorker { get; private set; } = FunctionsWorker.Isolated;
-
///
/// Adds the project option to configure the Azure Functions worker type of the Azure Functions HTTP trigger project.
///
@@ -27,25 +21,10 @@ public AzureFunctionsHttpProjectOptions()
/// Thrown when the is outside the bounds of the enumeration.
public AzureFunctionsHttpProjectOptions WithFunctionsWorker(FunctionsWorker workerType)
{
- FunctionsWorker = workerType;
-
- string workerTyperArgument = DetermineFunctionsWorkerArgument(workerType);
- AddOption($"--functions-worker {workerTyperArgument}");
-
+ SetFunctionsWorker(workerType);
return this;
}
- private static string DetermineFunctionsWorkerArgument(FunctionsWorker workerType)
- {
- switch (workerType)
- {
- case FunctionsWorker.InProcess: return "inProcess";
- case FunctionsWorker.Isolated: return "isolated";
- default:
- throw new ArgumentOutOfRangeException(nameof(workerType), workerType, "Unknown functions worker type");
- }
- }
-
///
/// Adds the project option to include the health checks Azure Function from the Azure Functions HTTP trigger project.
///
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs
index 80424717..2db99cd0 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProject.cs
@@ -30,9 +30,11 @@ public class AzureFunctionsServiceBusProject : AzureFunctionsProject, IAsyncDisp
private AzureFunctionsServiceBusProject(
ServiceBusEntityType entityType,
TestConfig configuration,
+ AzureFunctionsServiceBusProjectOptions options,
ITestOutputHelper outputWriter)
: base(configuration.GetAzureFunctionsServiceBusProjectDirectory(entityType),
configuration,
+ options,
outputWriter)
{
string connectionString = configuration.GetServiceBusConnectionString(entityType);
@@ -102,7 +104,7 @@ public static async Task StartNewProjectAsync(
AzureFunctionsServiceBusProject project = CreateNew(entityType, options, configuration, outputWriter);
- await project.StartAsync(entityType, options);
+ await project.StartAsync(entityType);
return project;
}
@@ -112,15 +114,15 @@ private static AzureFunctionsServiceBusProject CreateNew(
TestConfig configuration,
ITestOutputHelper outputWriter)
{
- var project = new AzureFunctionsServiceBusProject(entityType, configuration, outputWriter);
+ var project = new AzureFunctionsServiceBusProject(entityType, configuration, options, outputWriter);
project.CreateNewProject(options);
- project.AddOrderMessageHandlerImplementation(options);
- project.AddLocalSettings(options.FunctionsWorker);
+ project.AddOrderMessageHandlerImplementation();
+ project.AddLocalSettings();
return project;
}
- private void AddOrderMessageHandlerImplementation(AzureFunctionsServiceBusProjectOptions options)
+ private void AddOrderMessageHandlerImplementation()
{
AddPackage("Arcus.EventGrid.Core", "3.3.0");
@@ -129,23 +131,13 @@ private void AddOrderMessageHandlerImplementation(AzureFunctionsServiceBusProjec
AddTypeAsFile();
AddTypeAsFile();
- if (options.FunctionsWorker is FunctionsWorker.InProcess)
- {
- AddTypeAsFile();
- UpdateFileInProject("Startup.cs", contents =>
- RemovesUserErrorsFromContents(contents)
- .Replace("OrdersAzureServiceBusMessageHandler", nameof(TestOrdersAzureServiceBusMessageHandler)));
- }
- else if (options.FunctionsWorker is FunctionsWorker.Isolated)
- {
- AddTypeAsFile();
- UpdateFileInProject("Program.cs", contents =>
- RemovesUserErrorsFromContents(contents)
- .Replace("OrdersAzureServiceBusMessageHandler", nameof(TestOrdersAzureServiceBusMessageHandler)));
- }
+ AddTypeAsFile();
+ UpdateFileInProject(RuntimeFileName, contents =>
+ RemovesUserErrorsFromContents(contents)
+ .Replace("OrdersAzureServiceBusMessageHandler", nameof(TestOrdersAzureServiceBusMessageHandler)));
}
- private async Task StartAsync(ServiceBusEntityType entityType, AzureFunctionsServiceBusProjectOptions options)
+ private async Task StartAsync(ServiceBusEntityType entityType)
{
string serviceBusConnectionString = Configuration.GetServiceBusConnectionString(entityType);
var properties = ServiceBusConnectionStringProperties.Parse(serviceBusConnectionString);
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProjectOptions.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProjectOptions.cs
index bbeb6e7c..54f8f3d2 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProjectOptions.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/AzureFunctionsServiceBusProjectOptions.cs
@@ -1,13 +1,11 @@
-using System;
-using Arcus.Templates.Tests.Integration.Fixture;
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
namespace Arcus.Templates.Tests.Integration.AzureFunctions.ServiceBus
{
///
/// Represents the available options to pass along to the .
///
- public class AzureFunctionsServiceBusProjectOptions : ProjectOptions
+ public class AzureFunctionsServiceBusProjectOptions : AzureFunctionsProjectOptions
{
private readonly ServiceBusEntityType _entityType;
@@ -19,36 +17,16 @@ public AzureFunctionsServiceBusProjectOptions(ServiceBusEntityType entityType)
_entityType = entityType;
}
- ///
- /// Gets the Azure Functions worker type the project should target.
- ///
- public FunctionsWorker FunctionsWorker { get; private set; } = FunctionsWorker.InProcess;
-
///
/// Sets the Azure Functions worker type to the project options when running the project template.
///
/// The Azure Functions worker type the project should target.
public AzureFunctionsServiceBusProjectOptions WithFunctionWorker(FunctionsWorker workerType)
{
- FunctionsWorker = workerType;
-
- string workerTypeArgument = DetermineFunctionWorkerArgument(workerType);
- AddOption($"--functions-worker {workerTypeArgument}");
-
+ SetFunctionsWorker(workerType);
return this;
}
- private static string DetermineFunctionWorkerArgument(FunctionsWorker workerType)
- {
- switch (workerType)
- {
- case FunctionsWorker.InProcess: return "inProcess";
- case FunctionsWorker.Isolated: return "isolated";
- default:
- throw new ArgumentOutOfRangeException(nameof(workerType), workerType, "Unknown function worker type");
- }
- }
-
///
/// Adds the 'exclude Serilog' project options when running the project template.
///
diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/Logging/SerilogLoggingTests.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/Logging/SerilogLoggingTests.cs
index c7e6622d..9dbc540e 100644
--- a/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/Logging/SerilogLoggingTests.cs
+++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/ServiceBus/Logging/SerilogLoggingTests.cs
@@ -38,6 +38,12 @@ public async Task ServiceBusQueueProjectInProcess_WithoutSerilog_CorrectlyProces
await TestServiceBusProjectWithoutSerilogCorrectlyProcessesMessage(ServiceBusEntityType.Queue, FunctionsWorker.InProcess);
}
+ [Fact]
+ public async Task ServiceBusQueueProjectIsolated_WithoutSerilog_CorrectlyProcessesMessage()
+ {
+ await TestServiceBusProjectWithoutSerilogCorrectlyProcessesMessage(ServiceBusEntityType.Queue, FunctionsWorker.Isolated);
+ }
+
private async Task TestServiceBusProjectWithoutSerilogCorrectlyProcessesMessage(ServiceBusEntityType entityType, FunctionsWorker workerType)
{
// Arrange
From ff9b621bf04dc48c0916c3d733aee30865c2e0c5 Mon Sep 17 00:00:00 2001
From: Stijn Moreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Wed, 21 Dec 2022 13:27:09 +0100
Subject: [PATCH 2/4] Update docker-integration-tests.yml
---
build/templates/docker-integration-tests.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/build/templates/docker-integration-tests.yml b/build/templates/docker-integration-tests.yml
index a5fb825c..acea0043 100644
--- a/build/templates/docker-integration-tests.yml
+++ b/build/templates/docker-integration-tests.yml
@@ -179,7 +179,7 @@ stages:
parameters:
projectName: 'Arcus.Demo.AzureFunctions.EventHubs.InProcess'
projectAlias: 'arcus-az-func-eventhubs'
- options: '--functions-worker inProcess'
+ projectOptions: '--functions-worker inProcess'
ports: '$(Arcus.AzureFunctions.EventHubs.InProcess.Port):$(Arcus.AzureFunctions.EventHubs.InProcess.Port)'
script: |
Get-Content './Arcus.Demo.AzureFunctions.EventHubs.InProcess/Startup.cs' -Raw |
@@ -196,7 +196,7 @@ stages:
parameters:
projectName: 'Arcus.Demo.AzureFunctions.EventHubs.Isolated'
projectAlias: 'arcus-az-func-eventhubs'
- options: '--functions-worker isolated'
+ projectOptions: '--functions-worker isolated'
ports: '$(Arcus.AzureFunctions.EventHubs.Isolated.Port):$(Arcus.AzureFunctions.EventHubs.Isolated.Port)'
script: |
Get-Content './Arcus.Demo.AzureFunctions.EventHubs.Isolated/Startup.cs' -Raw |
@@ -273,4 +273,4 @@ stages:
inputs:
targetType: 'inline'
script: 'docker logs Arcus.Demo.AzureFunctions.Isolated.Http'
- condition: failed()
\ No newline at end of file
+ condition: failed()
From 919aa322a838a1c4d46f482f0ded68ef2c5a53d1 Mon Sep 17 00:00:00 2001
From: Stijn Moreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Wed, 21 Dec 2022 13:52:57 +0100
Subject: [PATCH 3/4] Update docker-integration-tests.yml
---
build/templates/docker-integration-tests.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/build/templates/docker-integration-tests.yml b/build/templates/docker-integration-tests.yml
index acea0043..af15b0d6 100644
--- a/build/templates/docker-integration-tests.yml
+++ b/build/templates/docker-integration-tests.yml
@@ -199,9 +199,9 @@ stages:
projectOptions: '--functions-worker isolated'
ports: '$(Arcus.AzureFunctions.EventHubs.Isolated.Port):$(Arcus.AzureFunctions.EventHubs.Isolated.Port)'
script: |
- Get-Content './Arcus.Demo.AzureFunctions.EventHubs.Isolated/Startup.cs' -Raw |
+ Get-Content './Arcus.Demo.AzureFunctions.EventHubs.Isolated/Program.cs' -Raw |
% { $_ -replace '#error', '#warning' -replace '#if DEBUG', '#if RELEASE' } |
- Set-Content './Arcus.Demo.AzureFunctions.EventHubs.Isolated/Startup.cs'
+ Set-Content './Arcus.Demo.AzureFunctions.EventHubs.Isolated/Program.cs'
Get-Content './Arcus.Demo.AzureFunctions.EventHubs.Isolated/SensorReadingFunction.cs' -Raw |
% { $_ -replace 'sensors', '$(Arcus.EventHubs.Docker.EventHubsName)' } |
Set-Content './Arcus.Demo.AzureFunctions.EventHubs.Isolated/SensorReadingFunction.cs'
From caa57048687bbec06db9bc0cace192fc9f169a8c Mon Sep 17 00:00:00 2001
From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Thu, 22 Dec 2022 06:22:13 +0100
Subject: [PATCH 4/4] pr-fix: add 'using' for 'SensorReading' example model
---
src/Arcus.Templates.AzureFunctions.EventHubs/Program.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/Arcus.Templates.AzureFunctions.EventHubs/Program.cs b/src/Arcus.Templates.AzureFunctions.EventHubs/Program.cs
index fa748dce..a1ac6d96 100644
--- a/src/Arcus.Templates.AzureFunctions.EventHubs/Program.cs
+++ b/src/Arcus.Templates.AzureFunctions.EventHubs/Program.cs
@@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Arcus.Security.Core;
using Arcus.Security.Core.Caching.Configuration;
+using Arcus.Templates.AzureFunctions.EventHubs.Model;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
#if Serilog_AppInsights