diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 6bd7d91c..6a4c8626 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -21,7 +21,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
- dotnet-version: "6.0.102"
+ dotnet-version: "7.0.101"
- name: check format
run: dotnet format --severity error --verify-no-changes ./Motor.NET.sln
@@ -32,7 +32,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
- dotnet-version: 6.0.x
+ dotnet-version: 7.0.x
- name: Install dependencies
run: dotnet restore Motor.NET.sln
- name: Build
@@ -67,7 +67,7 @@ jobs:
# - name: Setup .NET
# uses: actions/setup-dotnet@v1
# with:
- # dotnet-version: 6.0.x
+ # dotnet-version: 7.0.x
# - name: Install dependencies
# run: dotnet restore Motor.NET.sln
# - name: Build
@@ -87,7 +87,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
- dotnet-version: 6.0.x
+ dotnet-version: 7.0.x
- name: Push to NuGet Feed
run: dotnet nuget push './artifacts/*.nupkg' --skip-duplicate --source $NUGET_FEED --api-key $NUGET_KEY
diff --git a/examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/ConsumeAndMultiOutputPublisherWithRabbitMQ.csproj b/examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/ConsumeAndMultiOutputPublisherWithRabbitMQ.csproj
index c980ded0..90342a45 100644
--- a/examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/ConsumeAndMultiOutputPublisherWithRabbitMQ.csproj
+++ b/examples/ConsumeAndMultiOutputPublisherWithRabbitMQ/ConsumeAndMultiOutputPublisherWithRabbitMQ.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
Motor.NET
diff --git a/examples/ConsumeAndPublishNATS/ConsumeAndPublishNATS.csproj b/examples/ConsumeAndPublishNATS/ConsumeAndPublishNATS.csproj
index 9f7f6639..376a26e3 100644
--- a/examples/ConsumeAndPublishNATS/ConsumeAndPublishNATS.csproj
+++ b/examples/ConsumeAndPublishNATS/ConsumeAndPublishNATS.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
Motor.NET
diff --git a/examples/ConsumeAndPublishWithKafka/ConsumeAndPublishWithKafka.csproj b/examples/ConsumeAndPublishWithKafka/ConsumeAndPublishWithKafka.csproj
index 5ceeee2c..f9ca0616 100644
--- a/examples/ConsumeAndPublishWithKafka/ConsumeAndPublishWithKafka.csproj
+++ b/examples/ConsumeAndPublishWithKafka/ConsumeAndPublishWithKafka.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
Motor.NET
diff --git a/examples/ConsumeAndPublishWithRabbitMQ/ConsumeAndPublishWithRabbitMQ.csproj b/examples/ConsumeAndPublishWithRabbitMQ/ConsumeAndPublishWithRabbitMQ.csproj
index f9845347..b3b4740a 100644
--- a/examples/ConsumeAndPublishWithRabbitMQ/ConsumeAndPublishWithRabbitMQ.csproj
+++ b/examples/ConsumeAndPublishWithRabbitMQ/ConsumeAndPublishWithRabbitMQ.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
Motor.NET
diff --git a/examples/ConsumeSQS/ConsumeSQS.csproj b/examples/ConsumeSQS/ConsumeSQS.csproj
index 9537775a..6ed1d840 100644
--- a/examples/ConsumeSQS/ConsumeSQS.csproj
+++ b/examples/ConsumeSQS/ConsumeSQS.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
Motor.NET
diff --git a/examples/ConsumeWithRabbitMQAndDeadLetterExchange/ConsumeWithRabbitMQAndDeadLetterExchange.csproj b/examples/ConsumeWithRabbitMQAndDeadLetterExchange/ConsumeWithRabbitMQAndDeadLetterExchange.csproj
index 29b56567..f407b1a5 100644
--- a/examples/ConsumeWithRabbitMQAndDeadLetterExchange/ConsumeWithRabbitMQAndDeadLetterExchange.csproj
+++ b/examples/ConsumeWithRabbitMQAndDeadLetterExchange/ConsumeWithRabbitMQAndDeadLetterExchange.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
Motor.NET
diff --git a/examples/MetricsExample/MetricsExample.csproj b/examples/MetricsExample/MetricsExample.csproj
index eecd2684..b8e7b694 100644
--- a/examples/MetricsExample/MetricsExample.csproj
+++ b/examples/MetricsExample/MetricsExample.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
enable
Motor.NET
diff --git a/examples/OpenTelemetryExample/OpenTelemetryExample.csproj b/examples/OpenTelemetryExample/OpenTelemetryExample.csproj
index 55d8f73e..a265fcf7 100644
--- a/examples/OpenTelemetryExample/OpenTelemetryExample.csproj
+++ b/examples/OpenTelemetryExample/OpenTelemetryExample.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0
+ net7.0
Motor.NET
diff --git a/shared.csproj b/shared.csproj
index 8a5db2a7..9215485f 100644
--- a/shared.csproj
+++ b/shared.csproj
@@ -1,8 +1,8 @@
- 0.10.6
- 10
+ 0.11.0
+ 11
enable
CS8600;CS8602;CS8625;CS8618;CS8604;CS8601
diff --git a/src/Motor.Extensions.ContentEncoding.Abstractions/Motor.Extensions.ContentEncoding.Abstractions.csproj b/src/Motor.Extensions.ContentEncoding.Abstractions/Motor.Extensions.ContentEncoding.Abstractions.csproj
index edcf0dd9..852b658a 100644
--- a/src/Motor.Extensions.ContentEncoding.Abstractions/Motor.Extensions.ContentEncoding.Abstractions.csproj
+++ b/src/Motor.Extensions.ContentEncoding.Abstractions/Motor.Extensions.ContentEncoding.Abstractions.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.ContentEncoding.Gzip/Motor.Extensions.ContentEncoding.Gzip.csproj b/src/Motor.Extensions.ContentEncoding.Gzip/Motor.Extensions.ContentEncoding.Gzip.csproj
index 391692ba..9f29404e 100644
--- a/src/Motor.Extensions.ContentEncoding.Gzip/Motor.Extensions.ContentEncoding.Gzip.csproj
+++ b/src/Motor.Extensions.ContentEncoding.Gzip/Motor.Extensions.ContentEncoding.Gzip.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Conversion.Abstractions/Motor.Extensions.Conversion.Abstractions.csproj b/src/Motor.Extensions.Conversion.Abstractions/Motor.Extensions.Conversion.Abstractions.csproj
index b0831f27..9f0ea5b3 100644
--- a/src/Motor.Extensions.Conversion.Abstractions/Motor.Extensions.Conversion.Abstractions.csproj
+++ b/src/Motor.Extensions.Conversion.Abstractions/Motor.Extensions.Conversion.Abstractions.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Conversion.JsonNet/Motor.Extensions.Conversion.JsonNet.csproj b/src/Motor.Extensions.Conversion.JsonNet/Motor.Extensions.Conversion.JsonNet.csproj
index 9f283dd0..c3795303 100644
--- a/src/Motor.Extensions.Conversion.JsonNet/Motor.Extensions.Conversion.JsonNet.csproj
+++ b/src/Motor.Extensions.Conversion.JsonNet/Motor.Extensions.Conversion.JsonNet.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
@@ -10,7 +10,7 @@
-
+
diff --git a/src/Motor.Extensions.Conversion.Protobuf/Motor.Extensions.Conversion.Protobuf.csproj b/src/Motor.Extensions.Conversion.Protobuf/Motor.Extensions.Conversion.Protobuf.csproj
index f4caa3e6..fc3912a3 100644
--- a/src/Motor.Extensions.Conversion.Protobuf/Motor.Extensions.Conversion.Protobuf.csproj
+++ b/src/Motor.Extensions.Conversion.Protobuf/Motor.Extensions.Conversion.Protobuf.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
@@ -11,7 +11,7 @@
-
+
diff --git a/src/Motor.Extensions.Conversion.SystemJson/Motor.Extensions.Conversion.SystemJson.csproj b/src/Motor.Extensions.Conversion.SystemJson/Motor.Extensions.Conversion.SystemJson.csproj
index 5b8ce4cc..f14473bd 100644
--- a/src/Motor.Extensions.Conversion.SystemJson/Motor.Extensions.Conversion.SystemJson.csproj
+++ b/src/Motor.Extensions.Conversion.SystemJson/Motor.Extensions.Conversion.SystemJson.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
@@ -10,8 +10,8 @@
-
-
+
+
diff --git a/src/Motor.Extensions.Diagnostics.HealthChecks/Motor.Extensions.Diagnostics.HealthChecks.csproj b/src/Motor.Extensions.Diagnostics.HealthChecks/Motor.Extensions.Diagnostics.HealthChecks.csproj
index b900aa78..772e188d 100644
--- a/src/Motor.Extensions.Diagnostics.HealthChecks/Motor.Extensions.Diagnostics.HealthChecks.csproj
+++ b/src/Motor.Extensions.Diagnostics.HealthChecks/Motor.Extensions.Diagnostics.HealthChecks.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Diagnostics.Logging/Motor.Extensions.Diagnostics.Logging.csproj b/src/Motor.Extensions.Diagnostics.Logging/Motor.Extensions.Diagnostics.Logging.csproj
index c614e404..3567687a 100644
--- a/src/Motor.Extensions.Diagnostics.Logging/Motor.Extensions.Diagnostics.Logging.csproj
+++ b/src/Motor.Extensions.Diagnostics.Logging/Motor.Extensions.Diagnostics.Logging.csproj
@@ -1,11 +1,11 @@
- net6.0
+ net7.0
-
+
diff --git a/src/Motor.Extensions.Diagnostics.Metrics.Abstractions/Motor.Extensions.Diagnostics.Metrics.Abstractions.csproj b/src/Motor.Extensions.Diagnostics.Metrics.Abstractions/Motor.Extensions.Diagnostics.Metrics.Abstractions.csproj
index 5ca52be1..d07faa08 100644
--- a/src/Motor.Extensions.Diagnostics.Metrics.Abstractions/Motor.Extensions.Diagnostics.Metrics.Abstractions.csproj
+++ b/src/Motor.Extensions.Diagnostics.Metrics.Abstractions/Motor.Extensions.Diagnostics.Metrics.Abstractions.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Diagnostics.Metrics/Motor.Extensions.Diagnostics.Metrics.csproj b/src/Motor.Extensions.Diagnostics.Metrics/Motor.Extensions.Diagnostics.Metrics.csproj
index 2a0b74b8..43b995b2 100644
--- a/src/Motor.Extensions.Diagnostics.Metrics/Motor.Extensions.Diagnostics.Metrics.csproj
+++ b/src/Motor.Extensions.Diagnostics.Metrics/Motor.Extensions.Diagnostics.Metrics.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
@@ -17,9 +17,9 @@
-
-
-
+
+
+
diff --git a/src/Motor.Extensions.Diagnostics.Queue.Abstractions/Motor.Extensions.Diagnostics.Queue.Abstractions.csproj b/src/Motor.Extensions.Diagnostics.Queue.Abstractions/Motor.Extensions.Diagnostics.Queue.Abstractions.csproj
index d311d9d9..70d85f7e 100644
--- a/src/Motor.Extensions.Diagnostics.Queue.Abstractions/Motor.Extensions.Diagnostics.Queue.Abstractions.csproj
+++ b/src/Motor.Extensions.Diagnostics.Queue.Abstractions/Motor.Extensions.Diagnostics.Queue.Abstractions.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Diagnostics.Queue.Metrics/Motor.Extensions.Diagnostics.Queue.Metrics.csproj b/src/Motor.Extensions.Diagnostics.Queue.Metrics/Motor.Extensions.Diagnostics.Queue.Metrics.csproj
index 7e681052..d8f38a79 100644
--- a/src/Motor.Extensions.Diagnostics.Queue.Metrics/Motor.Extensions.Diagnostics.Queue.Metrics.csproj
+++ b/src/Motor.Extensions.Diagnostics.Queue.Metrics/Motor.Extensions.Diagnostics.Queue.Metrics.csproj
@@ -1,11 +1,11 @@
- net6.0
+ net7.0
-
+
diff --git a/src/Motor.Extensions.Diagnostics.Sentry/Motor.Extensions.Diagnostics.Sentry.csproj b/src/Motor.Extensions.Diagnostics.Sentry/Motor.Extensions.Diagnostics.Sentry.csproj
index e7946ebf..4f30770c 100644
--- a/src/Motor.Extensions.Diagnostics.Sentry/Motor.Extensions.Diagnostics.Sentry.csproj
+++ b/src/Motor.Extensions.Diagnostics.Sentry/Motor.Extensions.Diagnostics.Sentry.csproj
@@ -1,11 +1,11 @@
- net6.0
+ net7.0
-
+
diff --git a/src/Motor.Extensions.Diagnostics.Telemetry/Motor.Extensions.Diagnostics.Telemetry.csproj b/src/Motor.Extensions.Diagnostics.Telemetry/Motor.Extensions.Diagnostics.Telemetry.csproj
index 077d21ab..6945d898 100644
--- a/src/Motor.Extensions.Diagnostics.Telemetry/Motor.Extensions.Diagnostics.Telemetry.csproj
+++ b/src/Motor.Extensions.Diagnostics.Telemetry/Motor.Extensions.Diagnostics.Telemetry.csproj
@@ -1,11 +1,11 @@
- net6.0
+ net7.0
-
+
diff --git a/src/Motor.Extensions.Diagnostics.Tracing/Motor.Extensions.Diagnostics.Tracing.csproj b/src/Motor.Extensions.Diagnostics.Tracing/Motor.Extensions.Diagnostics.Tracing.csproj
index ad9beebd..c2e39b33 100644
--- a/src/Motor.Extensions.Diagnostics.Tracing/Motor.Extensions.Diagnostics.Tracing.csproj
+++ b/src/Motor.Extensions.Diagnostics.Tracing/Motor.Extensions.Diagnostics.Tracing.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Hosting.Abstractions/Motor.Extensions.Hosting.Abstractions.csproj b/src/Motor.Extensions.Hosting.Abstractions/Motor.Extensions.Hosting.Abstractions.csproj
index 0706e23d..88e206eb 100644
--- a/src/Motor.Extensions.Hosting.Abstractions/Motor.Extensions.Hosting.Abstractions.csproj
+++ b/src/Motor.Extensions.Hosting.Abstractions/Motor.Extensions.Hosting.Abstractions.csproj
@@ -1,13 +1,13 @@
- net6.0
+ net7.0
-
-
+
+
diff --git a/src/Motor.Extensions.Hosting.Bridge/Dockerfile b/src/Motor.Extensions.Hosting.Bridge/Dockerfile
index cd28e32b..400b40fc 100644
--- a/src/Motor.Extensions.Hosting.Bridge/Dockerfile
+++ b/src/Motor.Extensions.Hosting.Bridge/Dockerfile
@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine
+FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine
COPY . /data
WORKDIR /data
diff --git a/src/Motor.Extensions.Hosting.Bridge/Motor.Extensions.Hosting.Bridge.csproj b/src/Motor.Extensions.Hosting.Bridge/Motor.Extensions.Hosting.Bridge.csproj
index 34b50d71..40482638 100644
--- a/src/Motor.Extensions.Hosting.Bridge/Motor.Extensions.Hosting.Bridge.csproj
+++ b/src/Motor.Extensions.Hosting.Bridge/Motor.Extensions.Hosting.Bridge.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
Exe
Motor.NET/bridge
diff --git a/src/Motor.Extensions.Hosting.Bridge/Program.cs b/src/Motor.Extensions.Hosting.Bridge/Program.cs
index 2715adef..8d1da514 100644
--- a/src/Motor.Extensions.Hosting.Bridge/Program.cs
+++ b/src/Motor.Extensions.Hosting.Bridge/Program.cs
@@ -20,7 +20,7 @@ await MotorHost.CreateDefaultBuilder()
})
.ConfigurePublisher((ctx, builder) =>
{
- var s = ctx.Configuration["PublisherType"];
+ var s = ctx.Configuration["PublisherType"] ?? string.Empty;
var publisherType = Enum.Parse(s, true);
switch (publisherType)
{
@@ -38,7 +38,7 @@ await MotorHost.CreateDefaultBuilder()
})
.ConfigureConsumer((ctx, builder) =>
{
- var s = ctx.Configuration["ConsumerType"];
+ var s = ctx.Configuration["ConsumerType"] ?? string.Empty;
var consumerType = Enum.Parse(s, true);
switch (consumerType)
{
diff --git a/src/Motor.Extensions.Hosting.CloudEvents/Motor.Extensions.Hosting.CloudEvents.csproj b/src/Motor.Extensions.Hosting.CloudEvents/Motor.Extensions.Hosting.CloudEvents.csproj
index d518d4d0..2951d701 100644
--- a/src/Motor.Extensions.Hosting.CloudEvents/Motor.Extensions.Hosting.CloudEvents.csproj
+++ b/src/Motor.Extensions.Hosting.CloudEvents/Motor.Extensions.Hosting.CloudEvents.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Hosting.Consumer/Motor.Extensions.Hosting.Consumer.csproj b/src/Motor.Extensions.Hosting.Consumer/Motor.Extensions.Hosting.Consumer.csproj
index 42e3b6b3..1af86b35 100644
--- a/src/Motor.Extensions.Hosting.Consumer/Motor.Extensions.Hosting.Consumer.csproj
+++ b/src/Motor.Extensions.Hosting.Consumer/Motor.Extensions.Hosting.Consumer.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Hosting.Kafka/Motor.Extensions.Hosting.Kafka.csproj b/src/Motor.Extensions.Hosting.Kafka/Motor.Extensions.Hosting.Kafka.csproj
index 8477abf8..ce11e9c8 100644
--- a/src/Motor.Extensions.Hosting.Kafka/Motor.Extensions.Hosting.Kafka.csproj
+++ b/src/Motor.Extensions.Hosting.Kafka/Motor.Extensions.Hosting.Kafka.csproj
@@ -1,16 +1,16 @@
- net6.0
+ net7.0
-
-
-
+
+
+
diff --git a/src/Motor.Extensions.Hosting.NATS/Motor.Extensions.Hosting.NATS.csproj b/src/Motor.Extensions.Hosting.NATS/Motor.Extensions.Hosting.NATS.csproj
index 5fcf1d83..c8aa594b 100644
--- a/src/Motor.Extensions.Hosting.NATS/Motor.Extensions.Hosting.NATS.csproj
+++ b/src/Motor.Extensions.Hosting.NATS/Motor.Extensions.Hosting.NATS.csproj
@@ -1,15 +1,15 @@
- net6.0
+ net7.0
-
-
+
+
-
+
diff --git a/src/Motor.Extensions.Hosting.Publisher/Motor.Extensions.Hosting.Publisher.csproj b/src/Motor.Extensions.Hosting.Publisher/Motor.Extensions.Hosting.Publisher.csproj
index 0b66e810..ae59b057 100644
--- a/src/Motor.Extensions.Hosting.Publisher/Motor.Extensions.Hosting.Publisher.csproj
+++ b/src/Motor.Extensions.Hosting.Publisher/Motor.Extensions.Hosting.Publisher.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Hosting.RabbitMQ/Motor.Extensions.Hosting.RabbitMQ.csproj b/src/Motor.Extensions.Hosting.RabbitMQ/Motor.Extensions.Hosting.RabbitMQ.csproj
index 44a643f2..97851379 100644
--- a/src/Motor.Extensions.Hosting.RabbitMQ/Motor.Extensions.Hosting.RabbitMQ.csproj
+++ b/src/Motor.Extensions.Hosting.RabbitMQ/Motor.Extensions.Hosting.RabbitMQ.csproj
@@ -1,13 +1,13 @@
- net6.0
+ net7.0
-
-
-
+
+
+
diff --git a/src/Motor.Extensions.Hosting.SQS/Motor.Extensions.Hosting.SQS.csproj b/src/Motor.Extensions.Hosting.SQS/Motor.Extensions.Hosting.SQS.csproj
index 7de82efd..e6cd4c03 100644
--- a/src/Motor.Extensions.Hosting.SQS/Motor.Extensions.Hosting.SQS.csproj
+++ b/src/Motor.Extensions.Hosting.SQS/Motor.Extensions.Hosting.SQS.csproj
@@ -1,14 +1,14 @@
- net6.0
+ net7.0
-
-
+
+
diff --git a/src/Motor.Extensions.Hosting.Timer/Motor.Extensions.Hosting.Timer.csproj b/src/Motor.Extensions.Hosting.Timer/Motor.Extensions.Hosting.Timer.csproj
index f7d13afb..4bd685ac 100644
--- a/src/Motor.Extensions.Hosting.Timer/Motor.Extensions.Hosting.Timer.csproj
+++ b/src/Motor.Extensions.Hosting.Timer/Motor.Extensions.Hosting.Timer.csproj
@@ -1,12 +1,12 @@
- net6.0
+ net7.0
-
-
+
+
diff --git a/src/Motor.Extensions.Hosting/Motor.Extensions.Hosting.csproj b/src/Motor.Extensions.Hosting/Motor.Extensions.Hosting.csproj
index 768598e1..a98960ae 100644
--- a/src/Motor.Extensions.Hosting/Motor.Extensions.Hosting.csproj
+++ b/src/Motor.Extensions.Hosting/Motor.Extensions.Hosting.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
@@ -12,8 +12,8 @@
-
-
+
+
diff --git a/src/Motor.Extensions.Http/Motor.Extensions.Http.csproj b/src/Motor.Extensions.Http/Motor.Extensions.Http.csproj
index 8d3b825f..cfb99035 100644
--- a/src/Motor.Extensions.Http/Motor.Extensions.Http.csproj
+++ b/src/Motor.Extensions.Http/Motor.Extensions.Http.csproj
@@ -1,14 +1,14 @@
- net6.0
+ net7.0
-
-
-
-
+
+
+
+
diff --git a/src/Motor.Extensions.TestUtilities/Motor.Extensions.TestUtilities.csproj b/src/Motor.Extensions.TestUtilities/Motor.Extensions.TestUtilities.csproj
index 67bb1792..da3c5ca1 100644
--- a/src/Motor.Extensions.TestUtilities/Motor.Extensions.TestUtilities.csproj
+++ b/src/Motor.Extensions.TestUtilities/Motor.Extensions.TestUtilities.csproj
@@ -1,13 +1,13 @@
- net6.0
+ net7.0
false
-
+
diff --git a/src/Motor.Extensions.Utilities.Abstractions/Motor.Extensions.Utilities.Abstractions.csproj b/src/Motor.Extensions.Utilities.Abstractions/Motor.Extensions.Utilities.Abstractions.csproj
index 5262eb93..aa1f024f 100644
--- a/src/Motor.Extensions.Utilities.Abstractions/Motor.Extensions.Utilities.Abstractions.csproj
+++ b/src/Motor.Extensions.Utilities.Abstractions/Motor.Extensions.Utilities.Abstractions.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/src/Motor.Extensions.Utilities/Motor.Extensions.Utilities.csproj b/src/Motor.Extensions.Utilities/Motor.Extensions.Utilities.csproj
index d698b6a2..1b5b7f1c 100644
--- a/src/Motor.Extensions.Utilities/Motor.Extensions.Utilities.csproj
+++ b/src/Motor.Extensions.Utilities/Motor.Extensions.Utilities.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
diff --git a/test/Motor.Extensions.ContentEncoding.Abstractions_UnitTest/Motor.Extensions.ContentEncoding.Abstractions_UnitTest.csproj b/test/Motor.Extensions.ContentEncoding.Abstractions_UnitTest/Motor.Extensions.ContentEncoding.Abstractions_UnitTest.csproj
index 1c38b4b8..38b4c715 100644
--- a/test/Motor.Extensions.ContentEncoding.Abstractions_UnitTest/Motor.Extensions.ContentEncoding.Abstractions_UnitTest.csproj
+++ b/test/Motor.Extensions.ContentEncoding.Abstractions_UnitTest/Motor.Extensions.ContentEncoding.Abstractions_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.ContentEncoding.Gzip_UnitTest/Motor.Extensions.ContentEncoding.Gzip_UnitTest.csproj b/test/Motor.Extensions.ContentEncoding.Gzip_UnitTest/Motor.Extensions.ContentEncoding.Gzip_UnitTest.csproj
index e8a1a1c7..70c68531 100644
--- a/test/Motor.Extensions.ContentEncoding.Gzip_UnitTest/Motor.Extensions.ContentEncoding.Gzip_UnitTest.csproj
+++ b/test/Motor.Extensions.ContentEncoding.Gzip_UnitTest/Motor.Extensions.ContentEncoding.Gzip_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Conversion.JsonNet_UnitTest/Motor.Extensions.Conversion.JsonNet_UnitTest.csproj b/test/Motor.Extensions.Conversion.JsonNet_UnitTest/Motor.Extensions.Conversion.JsonNet_UnitTest.csproj
index 50a41a9f..522c6704 100644
--- a/test/Motor.Extensions.Conversion.JsonNet_UnitTest/Motor.Extensions.Conversion.JsonNet_UnitTest.csproj
+++ b/test/Motor.Extensions.Conversion.JsonNet_UnitTest/Motor.Extensions.Conversion.JsonNet_UnitTest.csproj
@@ -1,12 +1,12 @@
- net6.0
+ net7.0
false
-
+
diff --git a/test/Motor.Extensions.Conversion.Protobuf_UnitTest/Motor.Extensions.Conversion.Protobuf_UnitTest.csproj b/test/Motor.Extensions.Conversion.Protobuf_UnitTest/Motor.Extensions.Conversion.Protobuf_UnitTest.csproj
index 248b94ed..ec32d297 100644
--- a/test/Motor.Extensions.Conversion.Protobuf_UnitTest/Motor.Extensions.Conversion.Protobuf_UnitTest.csproj
+++ b/test/Motor.Extensions.Conversion.Protobuf_UnitTest/Motor.Extensions.Conversion.Protobuf_UnitTest.csproj
@@ -1,12 +1,12 @@
- net6.0
+ net7.0
false
-
+
diff --git a/test/Motor.Extensions.Conversion.SystemJson_UnitTest/Motor.Extensions.Conversion.SystemJson_UnitTest.csproj b/test/Motor.Extensions.Conversion.SystemJson_UnitTest/Motor.Extensions.Conversion.SystemJson_UnitTest.csproj
index d382b534..07dcb996 100644
--- a/test/Motor.Extensions.Conversion.SystemJson_UnitTest/Motor.Extensions.Conversion.SystemJson_UnitTest.csproj
+++ b/test/Motor.Extensions.Conversion.SystemJson_UnitTest/Motor.Extensions.Conversion.SystemJson_UnitTest.csproj
@@ -1,12 +1,12 @@
- net6.0
+ net7.0
false
-
+
diff --git a/test/Motor.Extensions.Diagnostics.Metrics_UnitTest/Motor.Extensions.Diagnostics.Metrics_UnitTest.csproj b/test/Motor.Extensions.Diagnostics.Metrics_UnitTest/Motor.Extensions.Diagnostics.Metrics_UnitTest.csproj
index bf9cc56a..2bcca02c 100644
--- a/test/Motor.Extensions.Diagnostics.Metrics_UnitTest/Motor.Extensions.Diagnostics.Metrics_UnitTest.csproj
+++ b/test/Motor.Extensions.Diagnostics.Metrics_UnitTest/Motor.Extensions.Diagnostics.Metrics_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Hosting.CloudEvents_UnitTest/Motor.Extensions.Hosting.CloudEvents_UnitTest.csproj b/test/Motor.Extensions.Hosting.CloudEvents_UnitTest/Motor.Extensions.Hosting.CloudEvents_UnitTest.csproj
index 90d7d652..57b4ff00 100644
--- a/test/Motor.Extensions.Hosting.CloudEvents_UnitTest/Motor.Extensions.Hosting.CloudEvents_UnitTest.csproj
+++ b/test/Motor.Extensions.Hosting.CloudEvents_UnitTest/Motor.Extensions.Hosting.CloudEvents_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Hosting.Consumer_UnitTest/Motor.Extensions.Hosting.Consumer_UnitTest.csproj b/test/Motor.Extensions.Hosting.Consumer_UnitTest/Motor.Extensions.Hosting.Consumer_UnitTest.csproj
index 7eabc299..3f9307b7 100644
--- a/test/Motor.Extensions.Hosting.Consumer_UnitTest/Motor.Extensions.Hosting.Consumer_UnitTest.csproj
+++ b/test/Motor.Extensions.Hosting.Consumer_UnitTest/Motor.Extensions.Hosting.Consumer_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
enable
diff --git a/test/Motor.Extensions.Hosting.Kafka_IntegrationTest/Motor.Extensions.Hosting.Kafka_IntegrationTest.csproj b/test/Motor.Extensions.Hosting.Kafka_IntegrationTest/Motor.Extensions.Hosting.Kafka_IntegrationTest.csproj
index 2d2de69a..8d33155b 100644
--- a/test/Motor.Extensions.Hosting.Kafka_IntegrationTest/Motor.Extensions.Hosting.Kafka_IntegrationTest.csproj
+++ b/test/Motor.Extensions.Hosting.Kafka_IntegrationTest/Motor.Extensions.Hosting.Kafka_IntegrationTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Hosting.Kafka_UnitTest/Motor.Extensions.Hosting.Kafka_UnitTest.csproj b/test/Motor.Extensions.Hosting.Kafka_UnitTest/Motor.Extensions.Hosting.Kafka_UnitTest.csproj
index 7ff7f70e..51c8003a 100644
--- a/test/Motor.Extensions.Hosting.Kafka_UnitTest/Motor.Extensions.Hosting.Kafka_UnitTest.csproj
+++ b/test/Motor.Extensions.Hosting.Kafka_UnitTest/Motor.Extensions.Hosting.Kafka_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Hosting.NATS_IntegrationTest/Motor.Extensions.Hosting.NATS_IntegrationTest.csproj b/test/Motor.Extensions.Hosting.NATS_IntegrationTest/Motor.Extensions.Hosting.NATS_IntegrationTest.csproj
index 337bc556..52be5cb9 100644
--- a/test/Motor.Extensions.Hosting.NATS_IntegrationTest/Motor.Extensions.Hosting.NATS_IntegrationTest.csproj
+++ b/test/Motor.Extensions.Hosting.NATS_IntegrationTest/Motor.Extensions.Hosting.NATS_IntegrationTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Hosting.Publisher_UnitTest/Motor.Extensions.Hosting.Publisher_UnitTest.csproj b/test/Motor.Extensions.Hosting.Publisher_UnitTest/Motor.Extensions.Hosting.Publisher_UnitTest.csproj
index 67173038..4c484f53 100644
--- a/test/Motor.Extensions.Hosting.Publisher_UnitTest/Motor.Extensions.Hosting.Publisher_UnitTest.csproj
+++ b/test/Motor.Extensions.Hosting.Publisher_UnitTest/Motor.Extensions.Hosting.Publisher_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
enable
diff --git a/test/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest.csproj b/test/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest.csproj
index 2c9a1323..d4ce23ce 100644
--- a/test/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest.csproj
+++ b/test/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest/Motor.Extensions.Hosting.RabbitMQ_IntegrationTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
@@ -15,10 +15,10 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
+
+
+
+
diff --git a/test/Motor.Extensions.Hosting.RabbitMQ_UnitTest/Motor.Extensions.Hosting.RabbitMQ_UnitTest.csproj b/test/Motor.Extensions.Hosting.RabbitMQ_UnitTest/Motor.Extensions.Hosting.RabbitMQ_UnitTest.csproj
index 5c9b2cae..1c644cbc 100644
--- a/test/Motor.Extensions.Hosting.RabbitMQ_UnitTest/Motor.Extensions.Hosting.RabbitMQ_UnitTest.csproj
+++ b/test/Motor.Extensions.Hosting.RabbitMQ_UnitTest/Motor.Extensions.Hosting.RabbitMQ_UnitTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Hosting.SQS_IntegrationTest/Motor.Extensions.Hosting.SQS_IntegrationTest.csproj b/test/Motor.Extensions.Hosting.SQS_IntegrationTest/Motor.Extensions.Hosting.SQS_IntegrationTest.csproj
index 9c77a0d7..91b3536f 100644
--- a/test/Motor.Extensions.Hosting.SQS_IntegrationTest/Motor.Extensions.Hosting.SQS_IntegrationTest.csproj
+++ b/test/Motor.Extensions.Hosting.SQS_IntegrationTest/Motor.Extensions.Hosting.SQS_IntegrationTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
false
diff --git a/test/Motor.Extensions.Hosting.Timer_IntegrationTest/Motor.Extensions.Hosting.Timer_IntegrationTest.csproj b/test/Motor.Extensions.Hosting.Timer_IntegrationTest/Motor.Extensions.Hosting.Timer_IntegrationTest.csproj
index 8e78db11..b63a158d 100644
--- a/test/Motor.Extensions.Hosting.Timer_IntegrationTest/Motor.Extensions.Hosting.Timer_IntegrationTest.csproj
+++ b/test/Motor.Extensions.Hosting.Timer_IntegrationTest/Motor.Extensions.Hosting.Timer_IntegrationTest.csproj
@@ -1,7 +1,7 @@
- net6.0
+ net7.0
@@ -12,7 +12,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/test/Motor.Extensions.Hosting_IntegrationTest/GenericHostingTests.cs b/test/Motor.Extensions.Hosting_IntegrationTest/GenericHostingTests.cs
index 47b2cafd..ddff7b6f 100644
--- a/test/Motor.Extensions.Hosting_IntegrationTest/GenericHostingTests.cs
+++ b/test/Motor.Extensions.Hosting_IntegrationTest/GenericHostingTests.cs
@@ -29,245 +29,244 @@
using Xunit;
using Xunit.Abstractions;
-namespace Motor.Extensions.Hosting_IntegrationTest
+namespace Motor.Extensions.Hosting_IntegrationTest;
+
+public class GenericHostingTests : IDisposable
{
- public class GenericHostingTests : IDisposable
- {
- private readonly ActivityListener _listener;
+ private readonly ActivityListener _listener;
- public GenericHostingTests(ITestOutputHelper outputHelper)
+ public GenericHostingTests(ITestOutputHelper outputHelper)
+ {
+ _listener = new ActivityListener
{
- _listener = new ActivityListener
- {
- ShouldListenTo = source => source.Name == OpenTelemetryOptions.DefaultActivitySourceName,
- Sample = (ref ActivityCreationOptions _) =>
- ActivitySamplingResult.AllDataAndRecorded,
- ActivityStarted = _ => { outputHelper.WriteLine("test"); },
- };
- ActivitySource.AddActivityListener(_listener);
- }
+ ShouldListenTo = source => source.Name == OpenTelemetryOptions.DefaultActivitySourceName,
+ Sample = (ref ActivityCreationOptions _) =>
+ ActivitySamplingResult.AllDataAndRecorded,
+ ActivityStarted = _ => { outputHelper.WriteLine("test"); },
+ };
+ ActivitySource.AddActivityListener(_listener);
+ }
- [Fact]
- public async Task
- StartAsync_SetupAndStartReverseStringServiceAndPublishMessageIntoServiceQueue_MessageInDestinationQueueIsReversed()
- {
- var consumer = new InMemoryConsumer();
- var publisher = new InMemoryPublisher();
- using var host = GetReverseStringService(consumer, publisher);
+ [Fact]
+ public async Task
+ StartAsync_SetupAndStartReverseStringServiceAndPublishMessageIntoServiceQueue_MessageInDestinationQueueIsReversed()
+ {
+ var consumer = new InMemoryConsumer();
+ var publisher = new InMemoryPublisher();
+ using var host = GetReverseStringService(consumer, publisher);
- var message = "12345";
+ var message = "12345";
- await host.StartAsync();
- await ConsumeMessage(consumer, message);
+ await host.StartAsync();
+ await ConsumeMessage(consumer, message);
- var actual = Encoding.UTF8.GetString(publisher.Events.First().TypedData);
- Assert.Equal("54321", actual);
- await host.StopAsync();
- }
+ var actual = Encoding.UTF8.GetString(publisher.Events.First().TypedData);
+ Assert.Equal("54321", actual);
+ await host.StopAsync();
+ }
- [Fact]
- public async Task StartAsync_CreateSpanAsReference_ContextIsReferenced()
- {
- var consumer = new InMemoryConsumer();
- var publisher = new InMemoryPublisher();
- using var host = GetReverseStringService(consumer, publisher);
+ [Fact]
+ public async Task StartAsync_CreateSpanAsReference_ContextIsReferenced()
+ {
+ var consumer = new InMemoryConsumer();
+ var publisher = new InMemoryPublisher();
+ using var host = GetReverseStringService(consumer, publisher);
- await host.StartAsync();
+ await host.StartAsync();
- var randomActivity = CreateRandomActivity();
- var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(Array.Empty());
- motorCloudEvent.SetActivity(randomActivity);
- await consumer.AddMessage(motorCloudEvent);
+ var randomActivity = CreateRandomActivity();
+ var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(Array.Empty());
+ motorCloudEvent.SetActivity(randomActivity);
+ await consumer.AddMessage(motorCloudEvent);
- var ctx = publisher.Events.First().GetActivityContext();
+ var ctx = publisher.Events.First().GetActivityContext();
- Assert.Equal(randomActivity.Context.TraceId, ctx.TraceId);
- Assert.NotEqual(randomActivity.Context.SpanId, ctx.SpanId);
- await host.StopAsync();
- }
+ Assert.Equal(randomActivity.Context.TraceId, ctx.TraceId);
+ Assert.NotEqual(randomActivity.Context.SpanId, ctx.SpanId);
+ await host.StopAsync();
+ }
- [Fact]
- public async Task StartAsync_CreateCustomExtension_ExtensionIsPassedThrough()
- {
- var consumer = new InMemoryConsumer();
- var publisher = new InMemoryPublisher();
- using var host = GetReverseStringService(consumer, publisher);
+ [Fact]
+ public async Task StartAsync_CreateCustomExtension_ExtensionIsPassedThrough()
+ {
+ var consumer = new InMemoryConsumer();
+ var publisher = new InMemoryPublisher();
+ using var host = GetReverseStringService(consumer, publisher);
- await host.StartAsync();
+ await host.StartAsync();
- var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(Array.Empty());
- motorCloudEvent.SetSomeCustomExtension(DateTimeOffset.MaxValue);
+ var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(Array.Empty());
+ motorCloudEvent.SetSomeCustomExtension(DateTimeOffset.MaxValue);
- await consumer.AddMessage(motorCloudEvent);
+ await consumer.AddMessage(motorCloudEvent);
- var receivedCloudEvent = publisher.Events.First();
+ var receivedCloudEvent = publisher.Events.First();
- Assert.Equal(DateTimeOffset.MaxValue, receivedCloudEvent.GetSomeCustomExtension());
- await host.StopAsync();
- }
+ Assert.Equal(DateTimeOffset.MaxValue, receivedCloudEvent.GetSomeCustomExtension());
+ await host.StopAsync();
+ }
- [Fact]
- public async Task StartAsync_CreateSpanWithoutReference_NewSpanIsCreated()
- {
- var consumer = new InMemoryConsumer();
- var publisher = new InMemoryPublisher();
- using var host = GetReverseStringService(consumer, publisher);
- await host.StartAsync();
- await ConsumeMessage(consumer, "test");
+ [Fact]
+ public async Task StartAsync_CreateSpanWithoutReference_NewSpanIsCreated()
+ {
+ var consumer = new InMemoryConsumer();
+ var publisher = new InMemoryPublisher();
+ using var host = GetReverseStringService(consumer, publisher);
+ await host.StartAsync();
+ await ConsumeMessage(consumer, "test");
- Assert.Single(publisher.Events);
- var ctx = publisher.Events.First().GetActivityContext();
+ Assert.Single(publisher.Events);
+ var ctx = publisher.Events.First().GetActivityContext();
- Assert.NotEqual(default, ctx.TraceId);
- await host.StopAsync();
- }
+ Assert.NotEqual(default, ctx.TraceId);
+ await host.StopAsync();
+ }
- [Fact]
- public async Task StartAsync_CreateSpan_ActivityListenerGotTrace()
- {
- var consumer = new InMemoryConsumer();
- var publisher = new InMemoryPublisher();
- var traceIsPublished = false;
- _listener.ActivityStarted = _ => { traceIsPublished = true; };
+ [Fact]
+ public async Task StartAsync_CreateSpan_ActivityListenerGotTrace()
+ {
+ var consumer = new InMemoryConsumer();
+ var publisher = new InMemoryPublisher();
+ var traceIsPublished = false;
+ _listener.ActivityStarted = _ => { traceIsPublished = true; };
- using var host = GetReverseStringService(consumer, publisher);
+ using var host = GetReverseStringService(consumer, publisher);
- await host.StartAsync();
- await ConsumeMessage(consumer, "12345");
+ await host.StartAsync();
+ await ConsumeMessage(consumer, "12345");
- Assert.True(traceIsPublished);
- await host.StopAsync();
- }
+ Assert.True(traceIsPublished);
+ await host.StopAsync();
+ }
- public Activity CreateRandomActivity()
- {
- var activity = new Activity(nameof(CreateRandomActivity));
- activity.SetIdFormat(ActivityIdFormat.W3C);
- activity.Start();
- return activity;
- }
+ public Activity CreateRandomActivity()
+ {
+ var activity = new Activity(nameof(CreateRandomActivity));
+ activity.SetIdFormat(ActivityIdFormat.W3C);
+ activity.Start();
+ return activity;
+ }
- private IHost GetReverseStringService(InMemoryConsumer consumer, InMemoryPublisher publisher)
- {
- var host = new MotorHostBuilder(new HostBuilder(), false)
- .UseSetting(MotorHostDefaults.EnablePrometheusEndpointKey, false.ToString())
- .ConfigureSerilog()
- .ConfigurePrometheus()
- .ConfigureServices((_, services) =>
- {
- services.AddTransient(_ =>
- {
- var mock = new Mock();
- mock.Setup(t => t.GetVersion()).Returns("test");
- mock.Setup(t => t.GetLibVersion()).Returns("test");
- mock.Setup(t => t.GetSource()).Returns(new Uri("motor://test"));
- return mock.Object;
- });
- services.AddTransient, ReverseStringConverter>();
- services.AddTransient, StringSerializer>();
- services.AddTransient, StringDeserializer>();
- services.AddTransient, SingleOutputServiceAdapter>();
- services.AddTransient, TelemetryDelegatingMessageHandler>();
- services.AddQueuedGenericService();
- //services.AddSingleton(provider => tracer);
- services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
- })
- .ConfigureConsumer((_, builder) =>
- {
- builder.AddInMemory(consumer);
- builder.AddDeserializer();
- })
- .ConfigurePublisher((_, builder) =>
- {
- builder.AddInMemory(publisher);
- builder.AddSerializer();
- })
- .ConfigureAppConfiguration((_, config) =>
+ private IHost GetReverseStringService(InMemoryConsumer consumer, InMemoryPublisher publisher)
+ {
+ var host = new MotorHostBuilder(new HostBuilder(), false)
+ .UseSetting(MotorHostDefaults.EnablePrometheusEndpointKey, false.ToString())
+ .ConfigureSerilog()
+ .ConfigurePrometheus()
+ .ConfigureServices((_, services) =>
+ {
+ services.AddTransient(_ =>
{
- config.AddJsonFile("appsettings.json", true, false);
- config.AddEnvironmentVariables();
- })
- .Build();
-
- return host;
- }
-
- private Task ConsumeMessage(InMemoryConsumer consumer,
- string messageToPublish)
- {
- return consumer.AddMessage(MotorCloudEvent.CreateTestCloudEvent(Encoding.UTF8.GetBytes(messageToPublish)));
- }
+ var mock = new Mock();
+ mock.Setup(t => t.GetVersion()).Returns("test");
+ mock.Setup(t => t.GetLibVersion()).Returns("test");
+ mock.Setup(t => t.GetSource()).Returns(new Uri("motor://test"));
+ return mock.Object;
+ });
+ services.AddTransient, ReverseStringConverter>();
+ services.AddTransient, StringSerializer>();
+ services.AddTransient, StringDeserializer>();
+ services.AddTransient, SingleOutputServiceAdapter>();
+ services.AddTransient, TelemetryDelegatingMessageHandler>();
+ services.AddQueuedGenericService();
+ //services.AddSingleton(provider => tracer);
+ services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
+ })
+ .ConfigureConsumer((_, builder) =>
+ {
+ builder.AddInMemory(consumer);
+ builder.AddDeserializer();
+ })
+ .ConfigurePublisher((_, builder) =>
+ {
+ builder.AddInMemory(publisher);
+ builder.AddSerializer();
+ })
+ .ConfigureAppConfiguration((_, config) =>
+ {
+ config.AddJsonFile("appsettings.json", true, false);
+ config.AddEnvironmentVariables();
+ })
+ .Build();
- protected class ReverseStringConverter : ISingleOutputService
- {
- private readonly ILogger _logger;
- private readonly IMetricFamily _summary;
- private static readonly ActivitySource ActivitySource = new(OpenTelemetryOptions.DefaultActivitySourceName);
+ return host;
+ }
- public ReverseStringConverter(ILogger logger,
- IMetricsFactory metricsFactory)
- {
- _logger = logger;
- _summary = metricsFactory.CreateSummary("summaryName", "summaryHelpString", new[] { "someLabel" });
- }
+ private Task ConsumeMessage(InMemoryConsumer consumer,
+ string messageToPublish)
+ {
+ return consumer.AddMessage(MotorCloudEvent.CreateTestCloudEvent(Encoding.UTF8.GetBytes(messageToPublish)));
+ }
- public Task?> ConvertMessageAsync(MotorCloudEvent dataCloudEvent,
- CancellationToken token = default)
- {
- _logger.LogInformation("log your request");
- var tmpChar = dataCloudEvent.TypedData.ToCharArray();
- if (!ActivitySource.HasListeners())
- {
- throw new ArgumentException();
- }
+ protected class ReverseStringConverter : ISingleOutputService
+ {
+ private readonly ILogger _logger;
+ private readonly IMetricFamily _summary;
+ private static readonly ActivitySource ActivitySource = new(OpenTelemetryOptions.DefaultActivitySourceName);
- var reversed = tmpChar.Reverse().ToArray();
- _summary.WithLabels("collect_your_metrics").Observe(1.0);
- return Task.FromResult?>(dataCloudEvent.CreateNew(new string(reversed)));
- }
+ public ReverseStringConverter(ILogger logger,
+ IMetricsFactory metricsFactory)
+ {
+ _logger = logger;
+ _summary = metricsFactory.CreateSummary("summaryName", "summaryHelpString", new[] { "someLabel" });
}
- protected class StringSerializer : IMessageSerializer
+ public Task?> ConvertMessageAsync(MotorCloudEvent dataCloudEvent,
+ CancellationToken token = default)
{
- public byte[] Serialize(string message)
+ _logger.LogInformation("log your request");
+ var tmpChar = dataCloudEvent.TypedData.ToCharArray();
+ if (!ActivitySource.HasListeners())
{
- return Encoding.UTF8.GetBytes(message);
+ throw new ArgumentException();
}
+
+ var reversed = tmpChar.Reverse().ToArray();
+ _summary.WithLabels("collect_your_metrics").Observe(1.0);
+ return Task.FromResult?>(dataCloudEvent.CreateNew(new string(reversed)));
}
+ }
- protected class StringDeserializer : IMessageDeserializer
+ protected class StringSerializer : IMessageSerializer
+ {
+ public byte[] Serialize(string message)
{
- public string Deserialize(byte[] message)
- {
- return Encoding.UTF8.GetString(message);
- }
+ return Encoding.UTF8.GetBytes(message);
}
+ }
- public void Dispose()
+ protected class StringDeserializer : IMessageDeserializer
+ {
+ public string Deserialize(byte[] message)
{
- _listener.Dispose();
+ return Encoding.UTF8.GetString(message);
}
}
- public static class SomeCustomExtension
+ public void Dispose()
{
- public static CloudEventAttribute SomeCustomExtensionAttribute { get; } =
- CloudEventAttribute.CreateExtension("somecustomextension", CloudEventAttributeType.Timestamp);
+ _listener.Dispose();
+ }
+}
- public static IEnumerable AllAttributes { get; } =
- new[] { SomeCustomExtensionAttribute }.ToList().AsReadOnly();
+public static class SomeCustomExtension
+{
+ public static CloudEventAttribute SomeCustomExtensionAttribute { get; } =
+ CloudEventAttribute.CreateExtension("somecustomextension", CloudEventAttributeType.Timestamp);
- public static MotorCloudEvent SetSomeCustomExtension(this MotorCloudEvent cloudEvent,
- DateTimeOffset? value) where TData : class
- {
- Validation.CheckNotNull(cloudEvent, nameof(cloudEvent));
- cloudEvent[SomeCustomExtensionAttribute] = value;
- return cloudEvent;
- }
+ public static IEnumerable AllAttributes { get; } =
+ new[] { SomeCustomExtensionAttribute }.ToList().AsReadOnly();
- public static DateTimeOffset GetSomeCustomExtension(this MotorCloudEvent cloudEvent)
- where TData : class =>
- (DateTimeOffset?)Validation.CheckNotNull(cloudEvent, nameof(cloudEvent))[SomeCustomExtensionAttribute] ??
- DateTimeOffset.MinValue;
+ public static MotorCloudEvent SetSomeCustomExtension(this MotorCloudEvent cloudEvent,
+ DateTimeOffset? value) where TData : class
+ {
+ Validation.CheckNotNull(cloudEvent, nameof(cloudEvent));
+ cloudEvent[SomeCustomExtensionAttribute] = value;
+ return cloudEvent;
}
+
+ public static DateTimeOffset GetSomeCustomExtension(this MotorCloudEvent cloudEvent)
+ where TData : class =>
+ (DateTimeOffset?)Validation.CheckNotNull(cloudEvent, nameof(cloudEvent))[SomeCustomExtensionAttribute] ??
+ DateTimeOffset.MinValue;
}
diff --git a/test/Motor.Extensions.Hosting_IntegrationTest/Motor.Extensions.Hosting_IntegrationTest.csproj b/test/Motor.Extensions.Hosting_IntegrationTest/Motor.Extensions.Hosting_IntegrationTest.csproj
index 92e91c49..654c3f0b 100644
--- a/test/Motor.Extensions.Hosting_IntegrationTest/Motor.Extensions.Hosting_IntegrationTest.csproj
+++ b/test/Motor.Extensions.Hosting_IntegrationTest/Motor.Extensions.Hosting_IntegrationTest.csproj
@@ -1,9 +1,8 @@
- net6.0
+ net7.0
false
- 9
enable
@@ -15,9 +14,9 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
+
+
+
diff --git a/test/Motor.Extensions.Hosting_UnitTest/BackgroundTaskQueueTests.cs b/test/Motor.Extensions.Hosting_UnitTest/BackgroundTaskQueueTests.cs
index fe01f605..355282cc 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/BackgroundTaskQueueTests.cs
+++ b/test/Motor.Extensions.Hosting_UnitTest/BackgroundTaskQueueTests.cs
@@ -5,43 +5,42 @@
using Motor.Extensions.Hosting.Internal;
using Xunit;
-namespace Motor.Extensions.Hosting_UnitTest
+namespace Motor.Extensions.Hosting_UnitTest;
+
+public class BackgroundTaskQueueTests
{
- public class BackgroundTaskQueueTests
+ [Fact]
+ public async Task DequeueAsync_MessageInQueues_GetMessage()
+ {
+ var message = "test";
+ var backgroundTaskQueue = new BackgroundTaskQueue(null);
+
+ var queueBackgroundWorkItem = backgroundTaskQueue.QueueBackgroundWorkItem(message);
+
+ var dequeueAsync = await backgroundTaskQueue.DequeueAsync(CancellationToken.None);
+ Assert.Equal(message, dequeueAsync!.Item);
+ Assert.Equal(TaskStatus.WaitingForActivation, queueBackgroundWorkItem.Status);
+ }
+
+ [Fact]
+ public async Task QueueBackgroundWorkItem_()
{
- [Fact]
- public async Task DequeueAsync_MessageInQueues_GetMessage()
- {
- var message = "test";
- var backgroundTaskQueue = new BackgroundTaskQueue(null);
-
- var queueBackgroundWorkItem = backgroundTaskQueue.QueueBackgroundWorkItem(message);
-
- var dequeueAsync = await backgroundTaskQueue.DequeueAsync(CancellationToken.None);
- Assert.Equal(message, dequeueAsync!.Item);
- Assert.Equal(TaskStatus.WaitingForActivation, queueBackgroundWorkItem.Status);
- }
-
- [Fact]
- public async Task QueueBackgroundWorkItem_()
- {
- var backgroundTaskQueue = new BackgroundTaskQueue(null);
- var queueBackgroundWorkItem = backgroundTaskQueue.QueueBackgroundWorkItem("test");
- var dequeueAsync = await backgroundTaskQueue.DequeueAsync(CancellationToken.None);
-
- dequeueAsync!.TaskCompletionStatus.SetResult(ProcessedMessageStatus.Success);
-
- var processedMessageStatus = await queueBackgroundWorkItem;
- Assert.Equal(TaskStatus.RanToCompletion, queueBackgroundWorkItem.Status);
- Assert.Equal(ProcessedMessageStatus.Success, processedMessageStatus);
- }
-
- [Fact]
- public async Task QueueBackgroundWorkItem_NullInput_ThrowArgument()
- {
- var backgroundTaskQueue = new BackgroundTaskQueue(null);
-
- await Assert.ThrowsAsync(() => backgroundTaskQueue.QueueBackgroundWorkItem(null));
- }
+ var backgroundTaskQueue = new BackgroundTaskQueue(null);
+ var queueBackgroundWorkItem = backgroundTaskQueue.QueueBackgroundWorkItem("test");
+ var dequeueAsync = await backgroundTaskQueue.DequeueAsync(CancellationToken.None);
+
+ dequeueAsync!.TaskCompletionStatus.SetResult(ProcessedMessageStatus.Success);
+
+ var processedMessageStatus = await queueBackgroundWorkItem;
+ Assert.Equal(TaskStatus.RanToCompletion, queueBackgroundWorkItem.Status);
+ Assert.Equal(ProcessedMessageStatus.Success, processedMessageStatus);
+ }
+
+ [Fact]
+ public async Task QueueBackgroundWorkItem_NullInput_ThrowArgument()
+ {
+ var backgroundTaskQueue = new BackgroundTaskQueue(null);
+
+ await Assert.ThrowsAsync(() => backgroundTaskQueue.QueueBackgroundWorkItem(null));
}
}
diff --git a/test/Motor.Extensions.Hosting_UnitTest/DefaultApplicationNameServiceTests.cs b/test/Motor.Extensions.Hosting_UnitTest/DefaultApplicationNameServiceTests.cs
index 4d51a0c4..ae7a8d9d 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/DefaultApplicationNameServiceTests.cs
+++ b/test/Motor.Extensions.Hosting_UnitTest/DefaultApplicationNameServiceTests.cs
@@ -3,84 +3,83 @@
using Motor.Extensions.Hosting;
using Xunit;
-namespace Motor.Extensions.Hosting_UnitTest
+namespace Motor.Extensions.Hosting_UnitTest;
+
+public class DefaultApplicationNameServiceTests
{
- public class DefaultApplicationNameServiceTests
+ [Theory]
+ [InlineData("test", "IpFeatureExtraction.Console", "test/ip-feature-extraction")]
+ [InlineData("test", "IpFeatureExtraction.Service", "test/ip-feature-extraction")]
+ [InlineData("test", "IpFeatureExtractionConsole", "test/ip-feature-extraction")]
+ [InlineData("test", "IpFeatureExtractionService", "test/ip-feature-extraction")]
+ public void ExtractServiceName_ProductAndName_UnifiedServiceName(string product, string assembly,
+ string expected)
{
- [Theory]
- [InlineData("test", "IpFeatureExtraction.Console", "test/ip-feature-extraction")]
- [InlineData("test", "IpFeatureExtraction.Service", "test/ip-feature-extraction")]
- [InlineData("test", "IpFeatureExtractionConsole", "test/ip-feature-extraction")]
- [InlineData("test", "IpFeatureExtractionService", "test/ip-feature-extraction")]
- public void ExtractServiceName_ProductAndName_UnifiedServiceName(string product, string assembly,
- string expected)
- {
- var application = CreateDefaultApplicationNameService();
+ var application = CreateDefaultApplicationNameService();
- var extractedServiceName = application.ExtractServiceName(product, assembly);
+ var extractedServiceName = application.ExtractServiceName(product, assembly);
- Assert.Equal(expected, extractedServiceName);
- }
+ Assert.Equal(expected, extractedServiceName);
+ }
- [Fact]
- public void GetFullName_FullNameWithOverride_SameFullName()
+ [Fact]
+ public void GetFullName_FullNameWithOverride_SameFullName()
+ {
+ var options = new DefaultApplicationNameOptions
{
- var options = new DefaultApplicationNameOptions
- {
- FullName = "test",
- };
- var application = CreateDefaultApplicationNameService(options);
+ FullName = "test",
+ };
+ var application = CreateDefaultApplicationNameService(options);
- var actualFullName = application.GetFullName();
+ var actualFullName = application.GetFullName();
- Assert.Equal(options.FullName, actualFullName);
- }
+ Assert.Equal(options.FullName, actualFullName);
+ }
- [Fact]
- public void GetFullName_FullNameWithoutOverride_DifferentFullName()
+ [Fact]
+ public void GetFullName_FullNameWithoutOverride_DifferentFullName()
+ {
+ var options = new DefaultApplicationNameOptions
{
- var options = new DefaultApplicationNameOptions
- {
- FullName = "",
- };
- var application = CreateDefaultApplicationNameService(options);
+ FullName = "",
+ };
+ var application = CreateDefaultApplicationNameService(options);
- var actualFullName = application.GetFullName();
+ var actualFullName = application.GetFullName();
- Assert.NotEqual(options.FullName, actualFullName);
- }
+ Assert.NotEqual(options.FullName, actualFullName);
+ }
- [Fact]
- public void GetSource_SourceWithOverride_SameSource()
+ [Fact]
+ public void GetSource_SourceWithOverride_SameSource()
+ {
+ var options = new DefaultApplicationNameOptions
{
- var options = new DefaultApplicationNameOptions
- {
- Source = "motor://test/",
- };
- var application = CreateDefaultApplicationNameService(options);
+ Source = "motor://test/",
+ };
+ var application = CreateDefaultApplicationNameService(options);
- var actualSource = application.GetSource();
+ var actualSource = application.GetSource();
- Assert.Equal(options.Source, actualSource.ToString());
- }
+ Assert.Equal(options.Source, actualSource.ToString());
+ }
- [Fact]
- public void GetSource_SourceWithoutOverride_DifferentSource()
+ [Fact]
+ public void GetSource_SourceWithoutOverride_DifferentSource()
+ {
+ var options = new DefaultApplicationNameOptions
{
- var options = new DefaultApplicationNameOptions
- {
- Source = "",
- };
- var application = CreateDefaultApplicationNameService(options);
+ Source = "",
+ };
+ var application = CreateDefaultApplicationNameService(options);
- var actualSource = application.GetSource();
+ var actualSource = application.GetSource();
- Assert.NotEqual(options.Source, actualSource.ToString());
- }
+ Assert.NotEqual(options.Source, actualSource.ToString());
+ }
- private static DefaultApplicationNameService CreateDefaultApplicationNameService(DefaultApplicationNameOptions? fullName = null)
- {
- return new(Assembly.GetAssembly(typeof(DefaultApplicationNameServiceTests))!, Options.Create(fullName ?? new DefaultApplicationNameOptions()));
- }
+ private static DefaultApplicationNameService CreateDefaultApplicationNameService(DefaultApplicationNameOptions? fullName = null)
+ {
+ return new(Assembly.GetAssembly(typeof(DefaultApplicationNameServiceTests))!, Options.Create(fullName ?? new DefaultApplicationNameOptions()));
}
}
diff --git a/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/MessageProcessingHealthCheckTest.cs b/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/MessageProcessingHealthCheckTest.cs
index d72513ed..c38d73c8 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/MessageProcessingHealthCheckTest.cs
+++ b/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/MessageProcessingHealthCheckTest.cs
@@ -7,66 +7,65 @@
using Motor.Extensions.Hosting.HealthChecks;
using Xunit;
-namespace Motor.Extensions.Hosting_UnitTest.HealthChecks
+namespace Motor.Extensions.Hosting_UnitTest.HealthChecks;
+
+public class MessageProcessingHealthCheckTest
{
- public class MessageProcessingHealthCheckTest
+ [Fact]
+ public async void CheckHealthAsync_LastDequeuedAtExceededTimeoutRangeAndQueueNotEmpty_ServiceIsUnhealthy()
{
- [Fact]
- public async void CheckHealthAsync_LastDequeuedAtExceededTimeoutRangeAndQueueNotEmpty_ServiceIsUnhealthy()
- {
- var healthCheck = CreateHealthCheck(true, 10);
+ var healthCheck = CreateHealthCheck(true, 10);
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Unhealthy, result);
- }
+ Assert.Equal(HealthStatus.Unhealthy, result);
+ }
- [Fact]
- public async void CheckHealthAsync_LastDequeuedAtWithinTimeoutRangeAndQueueNotEmpty_ServiceIsHealthy()
- {
- var healthCheck = CreateHealthCheck(false, 10);
+ [Fact]
+ public async void CheckHealthAsync_LastDequeuedAtWithinTimeoutRangeAndQueueNotEmpty_ServiceIsHealthy()
+ {
+ var healthCheck = CreateHealthCheck(false, 10);
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Healthy, result);
- }
+ Assert.Equal(HealthStatus.Healthy, result);
+ }
- [Fact]
- public async void CheckHealthAsync_LastDequeuedAtExceededTimeoutRangeAndQueueEmpty_ServiceIsHealthy()
- {
- var healthCheck = CreateHealthCheck(true, 0);
+ [Fact]
+ public async void CheckHealthAsync_LastDequeuedAtExceededTimeoutRangeAndQueueEmpty_ServiceIsHealthy()
+ {
+ var healthCheck = CreateHealthCheck(true, 0);
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Healthy, result);
- }
+ Assert.Equal(HealthStatus.Healthy, result);
+ }
- [Fact]
- public async void CheckHealthAsync_LastDequeuedAtWithinTimeoutRangeAndQueueEmpty_ServiceIsHealthy()
- {
- var healthCheck = CreateHealthCheck(false, 0);
+ [Fact]
+ public async void CheckHealthAsync_LastDequeuedAtWithinTimeoutRangeAndQueueEmpty_ServiceIsHealthy()
+ {
+ var healthCheck = CreateHealthCheck(false, 0);
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Healthy, result);
- }
+ Assert.Equal(HealthStatus.Healthy, result);
+ }
- private MessageProcessingHealthCheck CreateHealthCheck(bool exceededMaxTimeSinceLastProcessedMessage,
- int itemCount)
+ private MessageProcessingHealthCheck CreateHealthCheck(bool exceededMaxTimeSinceLastProcessedMessage,
+ int itemCount)
+ {
+ var maxTimeSinceLastProcessedMessage = TimeSpan.FromMilliseconds(100);
+ var config = new MessageProcessingOptions
{
- var maxTimeSinceLastProcessedMessage = TimeSpan.FromMilliseconds(100);
- var config = new MessageProcessingOptions
- {
- MaxTimeSinceLastProcessedMessage = maxTimeSinceLastProcessedMessage
- };
- var queue = new Mock>>();
- queue.Setup(q => q.LastDequeuedAt).Returns(exceededMaxTimeSinceLastProcessedMessage
- ? DateTimeOffset.UtcNow.Subtract(maxTimeSinceLastProcessedMessage + TimeSpan.FromMilliseconds(50))
- : DateTimeOffset.UtcNow.Subtract(maxTimeSinceLastProcessedMessage - TimeSpan.FromMilliseconds(50)));
- queue.Setup(q => q.ItemCount).Returns(itemCount);
- return new MessageProcessingHealthCheck(
- Options.Create(config),
- queue.Object);
- }
+ MaxTimeSinceLastProcessedMessage = maxTimeSinceLastProcessedMessage
+ };
+ var queue = new Mock>>();
+ queue.Setup(q => q.LastDequeuedAt).Returns(exceededMaxTimeSinceLastProcessedMessage
+ ? DateTimeOffset.UtcNow.Subtract(maxTimeSinceLastProcessedMessage + TimeSpan.FromMilliseconds(50))
+ : DateTimeOffset.UtcNow.Subtract(maxTimeSinceLastProcessedMessage - TimeSpan.FromMilliseconds(50)));
+ queue.Setup(q => q.ItemCount).Returns(itemCount);
+ return new MessageProcessingHealthCheck(
+ Options.Create(config),
+ queue.Object);
}
}
diff --git a/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresHealthCheckTest.cs b/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresHealthCheckTest.cs
index 80a88dab..52fd67fe 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresHealthCheckTest.cs
+++ b/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresHealthCheckTest.cs
@@ -4,86 +4,85 @@
using Motor.Extensions.Hosting.HealthChecks;
using Xunit;
-namespace Motor.Extensions.Hosting_UnitTest.HealthChecks
+namespace Motor.Extensions.Hosting_UnitTest.HealthChecks;
+
+public class TooManyTemporaryFailuresHealthCheckTest
{
- public class TooManyTemporaryFailuresHealthCheckTest
+ [Fact]
+ public async void CheckHealthAsync_NoTemporaryFailure_ServiceHealthy()
{
- [Fact]
- public async void CheckHealthAsync_NoTemporaryFailure_ServiceHealthy()
+ var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
{
- var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
- {
- LastHandledMessageAt = DateTimeOffset.UtcNow,
- TemporaryFailureCountSinceLastHandledMessage = 0
- });
+ LastHandledMessageAt = DateTimeOffset.UtcNow,
+ TemporaryFailureCountSinceLastHandledMessage = 0
+ });
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Healthy, result);
- }
+ Assert.Equal(HealthStatus.Healthy, result);
+ }
- [Fact]
- public async void CheckHealthAsync_ManyTemporaryFailuresAfterLastHandledMessage_ServiceIsUnhealthy()
+ [Fact]
+ public async void CheckHealthAsync_ManyTemporaryFailuresAfterLastHandledMessage_ServiceIsUnhealthy()
+ {
+ var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
{
- var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
- {
- LastHandledMessageAt = DateTimeOffset.MinValue,
- TemporaryFailureCountSinceLastHandledMessage = 1001
- });
+ LastHandledMessageAt = DateTimeOffset.MinValue,
+ TemporaryFailureCountSinceLastHandledMessage = 1001
+ });
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Unhealthy, result);
- }
+ Assert.Equal(HealthStatus.Unhealthy, result);
+ }
- [Fact]
- public async void CheckHealthAsync_SingleTemporaryFailureAfterRecentLastHandledMessage_ServiceIsHealthy()
+ [Fact]
+ public async void CheckHealthAsync_SingleTemporaryFailureAfterRecentLastHandledMessage_ServiceIsHealthy()
+ {
+ var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
{
- var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
- {
- LastHandledMessageAt = DateTimeOffset.UtcNow,
- TemporaryFailureCountSinceLastHandledMessage = 1
- });
+ LastHandledMessageAt = DateTimeOffset.UtcNow,
+ TemporaryFailureCountSinceLastHandledMessage = 1
+ });
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Healthy, result);
- }
+ Assert.Equal(HealthStatus.Healthy, result);
+ }
- [Fact]
- public async void CheckHealthAsync_SingleTemporaryFailureAfterLastHandledMessage_ServiceIsHealthy()
+ [Fact]
+ public async void CheckHealthAsync_SingleTemporaryFailureAfterLastHandledMessage_ServiceIsHealthy()
+ {
+ var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
{
- var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
- {
- LastHandledMessageAt = DateTimeOffset.MinValue,
- TemporaryFailureCountSinceLastHandledMessage = 1
- });
+ LastHandledMessageAt = DateTimeOffset.MinValue,
+ TemporaryFailureCountSinceLastHandledMessage = 1
+ });
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Healthy, result);
- }
+ Assert.Equal(HealthStatus.Healthy, result);
+ }
- [Fact]
- public async void CheckHealthAsync_ManyTemporaryFailureAfterRecentLastHandledMessage_ServiceIsHealthy()
+ [Fact]
+ public async void CheckHealthAsync_ManyTemporaryFailureAfterRecentLastHandledMessage_ServiceIsHealthy()
+ {
+ var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
{
- var healthCheck = CreateHealthCheck(new TooManyTemporaryFailuresStatistics
- {
- LastHandledMessageAt = DateTimeOffset.UtcNow,
- TemporaryFailureCountSinceLastHandledMessage = 1001
- });
+ LastHandledMessageAt = DateTimeOffset.UtcNow,
+ TemporaryFailureCountSinceLastHandledMessage = 1001
+ });
- var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
+ var result = (await healthCheck.CheckHealthAsync(new HealthCheckContext())).Status;
- Assert.Equal(HealthStatus.Healthy, result);
- }
+ Assert.Equal(HealthStatus.Healthy, result);
+ }
- private static TooManyTemporaryFailuresHealthCheck CreateHealthCheck(
- TooManyTemporaryFailuresStatistics temporaryFailuresStatistics)
- {
- var options = new TooManyTemporaryFailuresOptions();
- return new TooManyTemporaryFailuresHealthCheck(
- Options.Create(options), temporaryFailuresStatistics);
- }
+ private static TooManyTemporaryFailuresHealthCheck CreateHealthCheck(
+ TooManyTemporaryFailuresStatistics temporaryFailuresStatistics)
+ {
+ var options = new TooManyTemporaryFailuresOptions();
+ return new TooManyTemporaryFailuresHealthCheck(
+ Options.Create(options), temporaryFailuresStatistics);
}
}
diff --git a/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresStatisticsTest.cs b/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresStatisticsTest.cs
index 0f0fa063..1d844b7f 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresStatisticsTest.cs
+++ b/test/Motor.Extensions.Hosting_UnitTest/HealthChecks/TooManyTemporaryFailuresStatisticsTest.cs
@@ -6,100 +6,99 @@
using Motor.Extensions.Hosting.HealthChecks;
using Xunit;
-namespace Motor.Extensions.Hosting_UnitTest.HealthChecks
+namespace Motor.Extensions.Hosting_UnitTest.HealthChecks;
+
+public class TooManyTemporaryFailuresStatisticsTest
{
- public class TooManyTemporaryFailuresStatisticsTest
+ [Theory]
+ [InlineData(ProcessedMessageStatus.Success)]
+ [InlineData(ProcessedMessageStatus.InvalidInput)]
+ public async void RegisterMessageStatusAsync_StatusHandledCorrectly_SetLastHandledMessage(
+ ProcessedMessageStatus status)
{
- [Theory]
- [InlineData(ProcessedMessageStatus.Success)]
- [InlineData(ProcessedMessageStatus.InvalidInput)]
- public async void RegisterMessageStatusAsync_StatusHandledCorrectly_SetLastHandledMessage(
- ProcessedMessageStatus status)
- {
- var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
- var beforeRegister = DateTimeOffset.UtcNow;
+ var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
+ var beforeRegister = DateTimeOffset.UtcNow;
- await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
+ await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
- Assert.InRange(tooManyTemporaryFailuresStatistics.LastHandledMessageAt, beforeRegister,
- DateTimeOffset.UtcNow);
- }
-
- [Theory]
- [InlineData(ProcessedMessageStatus.CriticalFailure)]
- [InlineData(ProcessedMessageStatus.TemporaryFailure)]
- public async void RegisterMessageStatusAsync_StatusNotHandledCorrectly_DoesNotSetLastHandledMessage(
- ProcessedMessageStatus status)
- {
- var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
- var beforeRegister = DateTimeOffset.UtcNow;
+ Assert.InRange(tooManyTemporaryFailuresStatistics.LastHandledMessageAt, beforeRegister,
+ DateTimeOffset.UtcNow);
+ }
- await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
+ [Theory]
+ [InlineData(ProcessedMessageStatus.CriticalFailure)]
+ [InlineData(ProcessedMessageStatus.TemporaryFailure)]
+ public async void RegisterMessageStatusAsync_StatusNotHandledCorrectly_DoesNotSetLastHandledMessage(
+ ProcessedMessageStatus status)
+ {
+ var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
+ var beforeRegister = DateTimeOffset.UtcNow;
- Assert.NotInRange(tooManyTemporaryFailuresStatistics.LastHandledMessageAt, beforeRegister,
- DateTimeOffset.UtcNow);
- }
+ await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
- [Theory]
- [InlineData(1, ProcessedMessageStatus.TemporaryFailure)]
- [InlineData(4, ProcessedMessageStatus.TemporaryFailure)]
- [InlineData(1, ProcessedMessageStatus.CriticalFailure)]
- [InlineData(4, ProcessedMessageStatus.CriticalFailure)]
- public async void RegisterMessageStatusAsync_StatusNotHandledCorrectly_IncreasesTemporaryFailureCount(
- uint count, ProcessedMessageStatus status)
- {
- var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
+ Assert.NotInRange(tooManyTemporaryFailuresStatistics.LastHandledMessageAt, beforeRegister,
+ DateTimeOffset.UtcNow);
+ }
- for (uint i = 0; i < count; i++)
- {
- await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
- }
+ [Theory]
+ [InlineData(1, ProcessedMessageStatus.TemporaryFailure)]
+ [InlineData(4, ProcessedMessageStatus.TemporaryFailure)]
+ [InlineData(1, ProcessedMessageStatus.CriticalFailure)]
+ [InlineData(4, ProcessedMessageStatus.CriticalFailure)]
+ public async void RegisterMessageStatusAsync_StatusNotHandledCorrectly_IncreasesTemporaryFailureCount(
+ uint count, ProcessedMessageStatus status)
+ {
+ var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
- Assert.Equal(count, tooManyTemporaryFailuresStatistics.TemporaryFailureCountSinceLastHandledMessage);
+ for (uint i = 0; i < count; i++)
+ {
+ await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
}
- [Theory]
- [InlineData(ProcessedMessageStatus.Success)]
- [InlineData(ProcessedMessageStatus.InvalidInput)]
- public async void RegisterMessageStatusAsync_StatusHandledCorrectly_ResetTemporaryFailureCount(
- ProcessedMessageStatus status)
+ Assert.Equal(count, tooManyTemporaryFailuresStatistics.TemporaryFailureCountSinceLastHandledMessage);
+ }
+
+ [Theory]
+ [InlineData(ProcessedMessageStatus.Success)]
+ [InlineData(ProcessedMessageStatus.InvalidInput)]
+ public async void RegisterMessageStatusAsync_StatusHandledCorrectly_ResetTemporaryFailureCount(
+ ProcessedMessageStatus status)
+ {
+ var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics
{
- var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics
- {
- TemporaryFailureCountSinceLastHandledMessage = 100
- };
+ TemporaryFailureCountSinceLastHandledMessage = 100
+ };
- await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
+ await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(status);
- Assert.Equal((uint)0, tooManyTemporaryFailuresStatistics.TemporaryFailureCountSinceLastHandledMessage);
- }
+ Assert.Equal((uint)0, tooManyTemporaryFailuresStatistics.TemporaryFailureCountSinceLastHandledMessage);
+ }
- [Fact]
- public async void
- RegisterMessageStatusAsync_ManyStatusesNotHandledCorrectlyInParallel_CorrectTemporaryFailureCount()
+ [Fact]
+ public async void
+ RegisterMessageStatusAsync_ManyStatusesNotHandledCorrectlyInParallel_CorrectTemporaryFailureCount()
+ {
+ var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
+ var notHandledCorrectlyTasks = new List(100);
+ var startSignal = new SemaphoreSlim(0, 100);
+ for (var i = 0; i < 100; i++)
{
- var tooManyTemporaryFailuresStatistics = new TooManyTemporaryFailuresStatistics();
- var notHandledCorrectlyTasks = new List(100);
- var startSignal = new SemaphoreSlim(0, 100);
- for (var i = 0; i < 100; i++)
- {
- notHandledCorrectlyTasks.Add(IncreaseTemporaryFailureCount(startSignal,
- tooManyTemporaryFailuresStatistics));
- }
- startSignal.Release(100);
-
- await Task.WhenAll(notHandledCorrectlyTasks);
-
- Assert.Equal((uint)100, tooManyTemporaryFailuresStatistics.TemporaryFailureCountSinceLastHandledMessage);
+ notHandledCorrectlyTasks.Add(IncreaseTemporaryFailureCount(startSignal,
+ tooManyTemporaryFailuresStatistics));
}
+ startSignal.Release(100);
- private static async Task IncreaseTemporaryFailureCount(SemaphoreSlim startSignal,
- TooManyTemporaryFailuresStatistics tooManyTemporaryFailuresStatistics)
- {
- await startSignal.WaitAsync();
+ await Task.WhenAll(notHandledCorrectlyTasks);
- await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(ProcessedMessageStatus
- .TemporaryFailure);
- }
+ Assert.Equal((uint)100, tooManyTemporaryFailuresStatistics.TemporaryFailureCountSinceLastHandledMessage);
+ }
+
+ private static async Task IncreaseTemporaryFailureCount(SemaphoreSlim startSignal,
+ TooManyTemporaryFailuresStatistics tooManyTemporaryFailuresStatistics)
+ {
+ await startSignal.WaitAsync();
+
+ await tooManyTemporaryFailuresStatistics.RegisterMessageStatusAsync(ProcessedMessageStatus
+ .TemporaryFailure);
}
}
diff --git a/test/Motor.Extensions.Hosting_UnitTest/Motor.Extensions.Hosting_UnitTest.csproj b/test/Motor.Extensions.Hosting_UnitTest/Motor.Extensions.Hosting_UnitTest.csproj
index a6ef4fe7..630d4354 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/Motor.Extensions.Hosting_UnitTest.csproj
+++ b/test/Motor.Extensions.Hosting_UnitTest/Motor.Extensions.Hosting_UnitTest.csproj
@@ -1,9 +1,8 @@
- net6.0
+ net7.0
false
- 9
enable
Test
diff --git a/test/Motor.Extensions.Hosting_UnitTest/MultiOutputServiceAdapterTests.cs b/test/Motor.Extensions.Hosting_UnitTest/MultiOutputServiceAdapterTests.cs
index e9fc57f7..d6fd23a2 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/MultiOutputServiceAdapterTests.cs
+++ b/test/Motor.Extensions.Hosting_UnitTest/MultiOutputServiceAdapterTests.cs
@@ -12,188 +12,187 @@
using Prometheus.Client;
using Xunit;
-namespace Motor.Extensions.Hosting_UnitTest
+namespace Motor.Extensions.Hosting_UnitTest;
+
+public class MultiOutputServiceAdapterTests
{
- public class MultiOutputServiceAdapterTests
- {
- private static Mock> FakeService =>
- new();
+ private static Mock> FakeService =>
+ new();
- private static Mock> FakePublisher => new();
+ private static Mock> FakePublisher => new();
- [Fact]
- public void Ctor_WithMetricsFactory_SummaryIsCreated()
- {
- var metricsFactoryMock = new Mock>>();
+ [Fact]
+ public void Ctor_WithMetricsFactory_SummaryIsCreated()
+ {
+ var metricsFactoryMock = new Mock>>();
- GetMessageHandler(metrics: metricsFactoryMock.Object);
+ GetMessageHandler(metrics: metricsFactoryMock.Object);
- metricsFactoryMock.Verify(x =>
- x.CreateSummary("message_processing", "Message processing duration in ms",
- false, null as IReadOnlyList, null, null, null)
- );
- }
+ metricsFactoryMock.Verify(x =>
+ x.CreateSummary("message_processing", "Message processing duration in ms",
+ false, null as IReadOnlyList, null, null, null)
+ );
+ }
- [Fact]
- public async Task HandleMessageAsync_WithContextAndInput_HasContext()
- {
- var converterMock = FakeService;
- var context = CreateMotorEvent("message");
- var messageHandler = GetMessageHandler(service: converterMock.Object);
+ [Fact]
+ public async Task HandleMessageAsync_WithContextAndInput_HasContext()
+ {
+ var converterMock = FakeService;
+ var context = CreateMotorEvent("message");
+ var messageHandler = GetMessageHandler(service: converterMock.Object);
- await messageHandler.HandleMessageAsync(context).ConfigureAwait(false);
+ await messageHandler.HandleMessageAsync(context).ConfigureAwait(false);
- converterMock.Verify(x => x.ConvertMessageAsync(context, It.IsAny()), Times.Exactly(1));
- }
+ converterMock.Verify(x => x.ConvertMessageAsync(context, It.IsAny()), Times.Exactly(1));
+ }
- [Fact]
- public async Task HandleMessageAsync_ConverterThrowsArgumentException_ThrowsArgumentException()
- {
- var converterMock = FakeService;
- converterMock.Setup(x =>
- x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
- .Throws(new ArgumentException("argException"));
- var messageHandler = GetMessageHandler(service: converterMock.Object);
-
- await Assert.ThrowsAsync(() =>
- messageHandler.HandleMessageAsync(CreateMotorEvent("message_1"))).ConfigureAwait(false);
- }
+ [Fact]
+ public async Task HandleMessageAsync_ConverterThrowsArgumentException_ThrowsArgumentException()
+ {
+ var converterMock = FakeService;
+ converterMock.Setup(x =>
+ x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
+ .Throws(new ArgumentException("argException"));
+ var messageHandler = GetMessageHandler(service: converterMock.Object);
+
+ await Assert.ThrowsAsync(() =>
+ messageHandler.HandleMessageAsync(CreateMotorEvent("message_1"))).ConfigureAwait(false);
+ }
- [Fact]
- public async Task HandleMessageAsync_ConverterThrowsSomeException_TemporaryFailureResult()
- {
- var converterMock = FakeService;
- converterMock.Setup(x =>
- x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
- .Throws(new Exception("someException"));
- var messageHandler = GetMessageHandler(service: converterMock.Object);
+ [Fact]
+ public async Task HandleMessageAsync_ConverterThrowsSomeException_TemporaryFailureResult()
+ {
+ var converterMock = FakeService;
+ converterMock.Setup(x =>
+ x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
+ .Throws(new Exception("someException"));
+ var messageHandler = GetMessageHandler(service: converterMock.Object);
- var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_3")).ConfigureAwait(false);
+ var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_3")).ConfigureAwait(false);
- Assert.Equal(ProcessedMessageStatus.TemporaryFailure, actual);
- }
+ Assert.Equal(ProcessedMessageStatus.TemporaryFailure, actual);
+ }
- [Fact]
- public async Task HandleMessageAsync_ConverterReturnsNull_ReturnWithSuccess()
- {
- var converterMock = FakeService;
- converterMock.Setup(x =>
- x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
- .Returns(CreateReturnValues((string)null));
- var publisherMock = FakePublisher;
- var messageHandler = GetMessageHandler(service: converterMock.Object,
- publisher: publisherMock.Object);
-
- var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_5")).ConfigureAwait(false);
-
- Assert.Equal(ProcessedMessageStatus.Success, actual);
- publisherMock.Verify(
- x => x.PublishMessageAsync(It.IsAny>(), It.IsAny()),
- Times.Never);
- }
+ [Fact]
+ public async Task HandleMessageAsync_ConverterReturnsNull_ReturnWithSuccess()
+ {
+ var converterMock = FakeService;
+ converterMock.Setup(x =>
+ x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
+ .Returns(CreateReturnValues((string)null));
+ var publisherMock = FakePublisher;
+ var messageHandler = GetMessageHandler(service: converterMock.Object,
+ publisher: publisherMock.Object);
+
+ var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_5")).ConfigureAwait(false);
+
+ Assert.Equal(ProcessedMessageStatus.Success, actual);
+ publisherMock.Verify(
+ x => x.PublishMessageAsync(It.IsAny>(), It.IsAny()),
+ Times.Never);
+ }
- [Fact]
- public async Task HandleMessageAsync_ConverterReturnIsEmpty_ReturnWithSuccess()
- {
- var converterMock = FakeService;
- converterMock.Setup(x =>
- x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
- .Returns(CreateReturnValues());
- var publisherMock = FakePublisher;
- var messageHandler = GetMessageHandler(service: converterMock.Object, publisher: publisherMock.Object);
-
- var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_5")).ConfigureAwait(false);
-
- Assert.Equal(ProcessedMessageStatus.Success, actual);
- publisherMock.Verify(
- x => x.PublishMessageAsync(It.IsAny>(), It.IsAny()),
- Times.Never);
- }
+ [Fact]
+ public async Task HandleMessageAsync_ConverterReturnIsEmpty_ReturnWithSuccess()
+ {
+ var converterMock = FakeService;
+ converterMock.Setup(x =>
+ x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
+ .Returns(CreateReturnValues());
+ var publisherMock = FakePublisher;
+ var messageHandler = GetMessageHandler(service: converterMock.Object, publisher: publisherMock.Object);
+
+ var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_5")).ConfigureAwait(false);
+
+ Assert.Equal(ProcessedMessageStatus.Success, actual);
+ publisherMock.Verify(
+ x => x.PublishMessageAsync(It.IsAny>(), It.IsAny()),
+ Times.Never);
+ }
- [Fact]
- public async Task HandleMessageAsync_ConverterReturnsSomeResult_ReturnWithSuccess()
- {
- var converterMock = FakeService;
- converterMock.Setup(x =>
- x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
- .Returns(CreateReturnValues("someResult"));
- var publisherMock = FakePublisher;
- var messageHandler = GetMessageHandler(service: converterMock.Object, publisher: publisherMock.Object);
+ [Fact]
+ public async Task HandleMessageAsync_ConverterReturnsSomeResult_ReturnWithSuccess()
+ {
+ var converterMock = FakeService;
+ converterMock.Setup(x =>
+ x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
+ .Returns(CreateReturnValues("someResult"));
+ var publisherMock = FakePublisher;
+ var messageHandler = GetMessageHandler(service: converterMock.Object, publisher: publisherMock.Object);
- var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_6"));
+ var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_6"));
- Assert.Equal(ProcessedMessageStatus.Success, actual);
- }
+ Assert.Equal(ProcessedMessageStatus.Success, actual);
+ }
- [Fact]
- public async Task HandleMessageAsync_ConverterReturnsMultipleResults_PublisherIsCalledWithEachResult()
- {
- const string converterResult1 = "someOtherResult1";
- const string converterResult2 = "someOtherResult2";
- const string converterResult3 = "someOtherResult3";
- var converterMock = FakeService;
- converterMock.Setup(x =>
- x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
- .Returns(CreateReturnValues(converterResult1, converterResult2, converterResult3));
- var publisherMock = FakePublisher;
- var messageHandler = GetMessageHandler(service: converterMock.Object, publisher: publisherMock.Object);
-
- await messageHandler.HandleMessageAsync(CreateMotorEvent("message_6"));
-
- publisherMock.Verify(
- x => x.PublishMessageAsync(It.IsAny>(), It.IsAny()),
- Times.Exactly(3));
- publisherMock.Verify(
- x => x.PublishMessageAsync(It.Is>(t => t.TypedData == converterResult1),
- It.IsAny()), Times.Once);
- publisherMock.Verify(
- x => x.PublishMessageAsync(It.Is>(t => t.TypedData == converterResult2),
- It.IsAny()), Times.Once);
- publisherMock.Verify(
- x => x.PublishMessageAsync(It.Is>(t => t.TypedData == converterResult3),
- It.IsAny()), Times.Once);
- }
+ [Fact]
+ public async Task HandleMessageAsync_ConverterReturnsMultipleResults_PublisherIsCalledWithEachResult()
+ {
+ const string converterResult1 = "someOtherResult1";
+ const string converterResult2 = "someOtherResult2";
+ const string converterResult3 = "someOtherResult3";
+ var converterMock = FakeService;
+ converterMock.Setup(x =>
+ x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
+ .Returns(CreateReturnValues(converterResult1, converterResult2, converterResult3));
+ var publisherMock = FakePublisher;
+ var messageHandler = GetMessageHandler(service: converterMock.Object, publisher: publisherMock.Object);
+
+ await messageHandler.HandleMessageAsync(CreateMotorEvent("message_6"));
+
+ publisherMock.Verify(
+ x => x.PublishMessageAsync(It.IsAny>(), It.IsAny()),
+ Times.Exactly(3));
+ publisherMock.Verify(
+ x => x.PublishMessageAsync(It.Is>(t => t.TypedData == converterResult1),
+ It.IsAny()), Times.Once);
+ publisherMock.Verify(
+ x => x.PublishMessageAsync(It.Is>(t => t.TypedData == converterResult2),
+ It.IsAny()), Times.Once);
+ publisherMock.Verify(
+ x => x.PublishMessageAsync(It.Is>(t => t.TypedData == converterResult3),
+ It.IsAny()), Times.Once);
+ }
- [Fact]
- public async Task HandleMessageAsync_MessageProcessingFailure_ReturnsFailure()
- {
- var converterMock = FakeService;
- converterMock.Setup(x =>
- x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
- .Throws(new FailureException("message processing failed"));
- var messageHandler = GetMessageHandler(service: converterMock.Object);
+ [Fact]
+ public async Task HandleMessageAsync_MessageProcessingFailure_ReturnsFailure()
+ {
+ var converterMock = FakeService;
+ converterMock.Setup(x =>
+ x.ConvertMessageAsync(It.IsAny>(), It.IsAny()))
+ .Throws(new FailureException("message processing failed"));
+ var messageHandler = GetMessageHandler(service: converterMock.Object);
- var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_7"));
+ var actual = await messageHandler.HandleMessageAsync(CreateMotorEvent("message_7"));
- Assert.Equal(ProcessedMessageStatus.Failure, actual);
- }
+ Assert.Equal(ProcessedMessageStatus.Failure, actual);
+ }
- private async IAsyncEnumerable> CreateReturnValues(params string[] data)
+ private async IAsyncEnumerable> CreateReturnValues(params string[] data)
+ {
+ foreach (var t in data)
{
- foreach (var t in data)
- {
- yield return await Task.FromResult(MotorCloudEvent.CreateTestCloudEvent(t, new Uri("test://non")));
- }
+ yield return await Task.FromResult(MotorCloudEvent.CreateTestCloudEvent(t, new Uri("test://non")));
}
+ }
- private MultiOutputServiceAdapter GetMessageHandler(
- ILogger>? logger = null,
- IMetricsFactory>? metrics = null,
- IMultiOutputService? service = null,
- ITypedMessagePublisher? publisher = null)
- {
- logger ??= Mock.Of>>();
- service ??= FakeService.Object;
- publisher ??= FakePublisher.Object;
+ private MultiOutputServiceAdapter GetMessageHandler(
+ ILogger>? logger = null,
+ IMetricsFactory>? metrics = null,
+ IMultiOutputService? service = null,
+ ITypedMessagePublisher? publisher = null)
+ {
+ logger ??= Mock.Of>>();
+ service ??= FakeService.Object;
+ publisher ??= FakePublisher.Object;
- return new MultiOutputServiceAdapter(logger, metrics, service, publisher);
- }
+ return new MultiOutputServiceAdapter(logger, metrics, service, publisher);
+ }
- private static MotorCloudEvent CreateMotorEvent(string data = "")
- {
- return MotorCloudEvent.CreateTestCloudEvent(data, new Uri("test://non"));
- }
+ private static MotorCloudEvent CreateMotorEvent(string data = "")
+ {
+ return MotorCloudEvent.CreateTestCloudEvent(data, new Uri("test://non"));
}
}
diff --git a/test/Motor.Extensions.Hosting_UnitTest/QueuedGenericServiceTests.cs b/test/Motor.Extensions.Hosting_UnitTest/QueuedGenericServiceTests.cs
index b1e9b8de..12468a31 100644
--- a/test/Motor.Extensions.Hosting_UnitTest/QueuedGenericServiceTests.cs
+++ b/test/Motor.Extensions.Hosting_UnitTest/QueuedGenericServiceTests.cs
@@ -14,191 +14,190 @@
using Motor.Extensions.TestUtilities;
using Xunit;
-namespace Motor.Extensions.Hosting_UnitTest
+namespace Motor.Extensions.Hosting_UnitTest;
+
+public class QueuedGenericServiceTests
{
- public class QueuedGenericServiceTests
+ [Fact]
+ public async Task ExecuteAsync_CancellationTokenIsCanceled_StopProcessing()
{
- [Fact]
- public async Task ExecuteAsync_CancellationTokenIsCanceled_StopProcessing()
- {
- var queuedGenericService = CreateQueuedGenericService();
+ var queuedGenericService = CreateQueuedGenericService();
- await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
+ await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
- await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
- }
+ await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
+ }
- [Fact]
- public async Task ExecuteAsync_Messages_HandleMessageAsyncIsCalled()
- {
- var service = new Mock>();
- var queuedGenericService = CreateQueuedGenericService(service.Object);
+ [Fact]
+ public async Task ExecuteAsync_Messages_HandleMessageAsyncIsCalled()
+ {
+ var service = new Mock>();
+ var queuedGenericService = CreateQueuedGenericService(service.Object);
- await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
- await Task.Delay(100).ConfigureAwait(false);
- await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
+ await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
+ await Task.Delay(100).ConfigureAwait(false);
+ await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
- service.Verify(
- t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()),
- Times.AtLeastOnce);
- }
+ service.Verify(
+ t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()),
+ Times.AtLeastOnce);
+ }
- [Theory]
- [InlineData(1)]
- [InlineData(4)]
- [InlineData(8)]
- [InlineData(null)]
- public async void ExecuteAsync_MultipleMessage_ParallelProcessingBasedOnConfig(
- int? parallelProcessesOrProcessorCount)
+ [Theory]
+ [InlineData(1)]
+ [InlineData(4)]
+ [InlineData(8)]
+ [InlineData(null)]
+ public async void ExecuteAsync_MultipleMessage_ParallelProcessingBasedOnConfig(
+ int? parallelProcessesOrProcessorCount)
+ {
+ parallelProcessesOrProcessorCount ??= Environment.ProcessorCount;
+ var waitTimeInMs = 200;
+ var taskCompletionSources = new List>();
+ var queue = new Mock>>();
+ var setupSequentialResult = queue.SetupSequence(t => t.DequeueAsync(It.IsAny()));
+ for (var i = 0; i < parallelProcessesOrProcessorCount * 2; i++)
{
- parallelProcessesOrProcessorCount ??= Environment.ProcessorCount;
- var waitTimeInMs = 200;
- var taskCompletionSources = new List>();
- var queue = new Mock>>();
- var setupSequentialResult = queue.SetupSequence(t => t.DequeueAsync(It.IsAny()));
- for (var i = 0; i < parallelProcessesOrProcessorCount * 2; i++)
- {
- var source = new TaskCompletionSource();
- setupSequentialResult = setupSequentialResult.ReturnsAsync(() =>
- new QueueItem>(
- MotorCloudEvent.CreateTestCloudEvent(string.Empty, new Uri("test://non")),
- source));
- taskCompletionSources.Add(source);
- }
-
- var service = new Mock>();
- service.Setup(t =>
- t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
- .Returns(async () =>
- {
- await Task.Delay(waitTimeInMs).ConfigureAwait(false);
- return ProcessedMessageStatus.Success;
- });
- var queuedGenericService = CreateQueuedGenericService(service.Object, queue.Object,
- config: new QueuedGenericServiceOptions
- {
- ParallelProcesses = parallelProcessesOrProcessorCount
- });
-
- await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
- await Task.Delay(Convert.ToInt32(Math.Floor(waitTimeInMs * 0.5))).ConfigureAwait(false);
- await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
-
- service.Verify(t => t
- .HandleMessageAsync(It.IsAny>(), It.IsAny()),
- Times.Exactly(parallelProcessesOrProcessorCount.Value));
- var done = taskCompletionSources
- .Count(completionSource => completionSource.Task.Status == TaskStatus.RanToCompletion);
- Assert.Equal(parallelProcessesOrProcessorCount, done);
+ var source = new TaskCompletionSource();
+ setupSequentialResult = setupSequentialResult.ReturnsAsync(() =>
+ new QueueItem>(
+ MotorCloudEvent.CreateTestCloudEvent(string.Empty, new Uri("test://non")),
+ source));
+ taskCompletionSources.Add(source);
}
- [Theory]
- [InlineData(ProcessedMessageStatus.Success)]
- [InlineData(ProcessedMessageStatus.InvalidInput)]
- [InlineData(ProcessedMessageStatus.TemporaryFailure)]
- [InlineData(ProcessedMessageStatus.CriticalFailure)]
- public async Task ExecuteAsync_MessagesProcessingStatus_TaskCompletionSourceIsCompleted(
- ProcessedMessageStatus expectedStatus)
- {
- var taskCompletionSource = new TaskCompletionSource();
- var queue = CreateQueue(status: taskCompletionSource);
+ var service = new Mock>();
+ service.Setup(t =>
+ t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
+ .Returns(async () =>
+ {
+ await Task.Delay(waitTimeInMs).ConfigureAwait(false);
+ return ProcessedMessageStatus.Success;
+ });
+ var queuedGenericService = CreateQueuedGenericService(service.Object, queue.Object,
+ config: new QueuedGenericServiceOptions
+ {
+ ParallelProcesses = parallelProcessesOrProcessorCount
+ });
+
+ await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
+ await Task.Delay(Convert.ToInt32(Math.Floor(waitTimeInMs * 0.5))).ConfigureAwait(false);
+ await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
+
+ service.Verify(t => t
+ .HandleMessageAsync(It.IsAny>(), It.IsAny()),
+ Times.Exactly(parallelProcessesOrProcessorCount.Value));
+ var done = taskCompletionSources
+ .Count(completionSource => completionSource.Task.Status == TaskStatus.RanToCompletion);
+ Assert.Equal(parallelProcessesOrProcessorCount, done);
+ }
- var service = new Mock>();
- service
- .Setup(t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
- .ReturnsAsync(expectedStatus);
+ [Theory]
+ [InlineData(ProcessedMessageStatus.Success)]
+ [InlineData(ProcessedMessageStatus.InvalidInput)]
+ [InlineData(ProcessedMessageStatus.TemporaryFailure)]
+ [InlineData(ProcessedMessageStatus.CriticalFailure)]
+ public async Task ExecuteAsync_MessagesProcessingStatus_TaskCompletionSourceIsCompleted(
+ ProcessedMessageStatus expectedStatus)
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+ var queue = CreateQueue(status: taskCompletionSource);
- var queuedGenericService = CreateQueuedGenericService(service.Object, queue);
+ var service = new Mock>();
+ service
+ .Setup(t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
+ .ReturnsAsync(expectedStatus);
- await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
- await Task.Delay(100).ConfigureAwait(false);
+ var queuedGenericService = CreateQueuedGenericService(service.Object, queue);
- var actualStatus = await taskCompletionSource.Task.ConfigureAwait(false);
- Assert.Equal(expectedStatus, actualStatus);
+ await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
+ await Task.Delay(100).ConfigureAwait(false);
- await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
- }
+ var actualStatus = await taskCompletionSource.Task.ConfigureAwait(false);
+ Assert.Equal(expectedStatus, actualStatus);
- [Fact]
- public async Task ExecuteAsync_MessagesProcessStatusSuccess_NeverCallStopApplication()
- {
- var service = new Mock>();
- service
- .Setup(t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
- .ReturnsAsync(ProcessedMessageStatus.Success);
- var hostApplicationLifetime = new Mock();
+ await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
+ }
- var queuedGenericService = CreateQueuedGenericService(service.Object,
- hostApplicationLifetime: hostApplicationLifetime.Object);
+ [Fact]
+ public async Task ExecuteAsync_MessagesProcessStatusSuccess_NeverCallStopApplication()
+ {
+ var service = new Mock>();
+ service
+ .Setup(t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
+ .ReturnsAsync(ProcessedMessageStatus.Success);
+ var hostApplicationLifetime = new Mock();
- await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
- await Task.Delay(100).ConfigureAwait(false);
- await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
+ var queuedGenericService = CreateQueuedGenericService(service.Object,
+ hostApplicationLifetime: hostApplicationLifetime.Object);
- hostApplicationLifetime.Verify(t => t.StopApplication(), Times.Never);
- }
+ await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
+ await Task.Delay(100).ConfigureAwait(false);
+ await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
- [Fact]
- public async Task ExecuteAsync_MessagesProcessStatusCritical_StopApplication()
- {
- var service = new Mock>();
- service
- .Setup(t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
- .ReturnsAsync(ProcessedMessageStatus.CriticalFailure);
- var hostApplicationLifetime = new Mock();
+ hostApplicationLifetime.Verify(t => t.StopApplication(), Times.Never);
+ }
- var queuedGenericService = CreateQueuedGenericService(service.Object,
- hostApplicationLifetime: hostApplicationLifetime.Object);
+ [Fact]
+ public async Task ExecuteAsync_MessagesProcessStatusCritical_StopApplication()
+ {
+ var service = new Mock>();
+ service
+ .Setup(t => t.HandleMessageAsync(It.IsAny>(), It.IsAny()))
+ .ReturnsAsync(ProcessedMessageStatus.CriticalFailure);
+ var hostApplicationLifetime = new Mock();
- await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
- await Task.Delay(100).ConfigureAwait(false);
- await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
+ var queuedGenericService = CreateQueuedGenericService(service.Object,
+ hostApplicationLifetime: hostApplicationLifetime.Object);
- hostApplicationLifetime.Verify(t => t.StopApplication(), Times.AtLeastOnce);
- }
+ await queuedGenericService.StartAsync(CancellationToken.None).ConfigureAwait(false);
+ await Task.Delay(100).ConfigureAwait(false);
+ await queuedGenericService.StopAsync(CancellationToken.None).ConfigureAwait(false);
- private static IBackgroundTaskQueue> CreateQueue(
- MotorCloudEvent? dataCloudEvent = null, TaskCompletionSource? status = null)
- {
- var queue = new Mock>>();
- queue.Setup(t => t.DequeueAsync(It.IsAny()))
- .ReturnsAsync(() =>
- new QueueItem>(
- dataCloudEvent ?? MotorCloudEvent.CreateTestCloudEvent(string.Empty, new Uri("test://non")),
- status ?? new TaskCompletionSource()));
- return queue.Object;
- }
+ hostApplicationLifetime.Verify(t => t.StopApplication(), Times.AtLeastOnce);
+ }
- private static QueuedGenericService CreateQueuedGenericService(
- INoOutputService? service = null,
- IBackgroundTaskQueue>? backgroundTaskQueue = null,
- IHostApplicationLifetime? hostApplicationLifetime = null,
- QueuedGenericServiceOptions? config = null)
- {
- var logger = new Mock>>();
- hostApplicationLifetime ??= new Mock().Object;
- backgroundTaskQueue ??= CreateQueue();
- service ??= new Mock>().Object;
- var options = Options.Create(config ?? new QueuedGenericServiceOptions());
- var baseDelegatingMessageHandler = CreateBaseDelegatingMessageHandler(service);
-
- return new QueuedGenericService(
- logger.Object,
- options,
- hostApplicationLifetime,
- backgroundTaskQueue,
- baseDelegatingMessageHandler);
- }
+ private static IBackgroundTaskQueue> CreateQueue(
+ MotorCloudEvent? dataCloudEvent = null, TaskCompletionSource? status = null)
+ {
+ var queue = new Mock