From 231628eed95e0de65cf0a1a2e4748b5fca5a6eca Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 6 Apr 2026 09:39:46 +0000
Subject: [PATCH 01/20] Add MockEndpoint and AspireIntegrationTestHost
infrastructure for E2E tutorial tests
Agent-Logs-Url: https://github.com/devstress/My3DLearning/sessions/d69f67ee-ec32-4682-83b7-da586b773c73
Co-authored-by: devstress <30769729+devstress@users.noreply.github.com>
---
.../AspireIntegrationTestHost.cs | 113 +++++++++++++
.../Infrastructure/MockEndpoint.cs | 158 ++++++++++++++++++
.../tests/TutorialLabs/TutorialLabs.csproj | 1 +
3 files changed, 272 insertions(+)
create mode 100644 EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/AspireIntegrationTestHost.cs
create mode 100644 EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/MockEndpoint.cs
diff --git a/EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/AspireIntegrationTestHost.cs b/EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/AspireIntegrationTestHost.cs
new file mode 100644
index 0000000..ffb5b11
--- /dev/null
+++ b/EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/AspireIntegrationTestHost.cs
@@ -0,0 +1,113 @@
+// ============================================================================
+// AspireIntegrationTestHost – DI-based test host for E2E integration testing
+// ============================================================================
+// Wires real EIP components with MockEndpoints using the same
+// HostApplicationBuilder pattern as .NET Aspire. Provides service resolution
+// for end-to-end integration tests.
+// ============================================================================
+
+using EnterpriseIntegrationPlatform.Ingestion;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Abstractions;
+
+namespace TutorialLabs.Infrastructure;
+
+///
+/// Aspire-style integration test host that wires real EIP components
+/// with MockEndpoints via dependency injection.
+///
+public sealed class AspireIntegrationTestHost : IAsyncDisposable
+{
+ private readonly IHost _host;
+ private readonly Dictionary _endpoints;
+
+ internal AspireIntegrationTestHost(IHost host, Dictionary endpoints)
+ {
+ _host = host;
+ _endpoints = endpoints;
+ }
+
+ public IServiceProvider Services => _host.Services;
+
+ public T GetService() where T : notnull =>
+ _host.Services.GetRequiredService();
+
+ public MockEndpoint GetEndpoint(string name) => _endpoints[name];
+
+ public IReadOnlyDictionary Endpoints => _endpoints;
+
+ public static Builder CreateBuilder() => new();
+
+ public ValueTask DisposeAsync()
+ {
+ _host.Dispose();
+ return ValueTask.CompletedTask;
+ }
+
+ public sealed class Builder
+ {
+ private readonly HostApplicationBuilder _inner;
+ private readonly Dictionary _endpoints = new();
+
+ public Builder()
+ {
+ _inner = Host.CreateApplicationBuilder([]);
+ _inner.Services.AddSingleton(NullLoggerFactory.Instance);
+ _inner.Services.AddSingleton(typeof(ILogger<>), typeof(NullLogger<>));
+ }
+
+ ///
+ /// Adds a named MockEndpoint for testing.
+ ///
+ public MockEndpoint AddMockEndpoint(string name)
+ {
+ var ep = new MockEndpoint(name);
+ _endpoints[name] = ep;
+ return ep;
+ }
+
+ ///
+ /// Registers a MockEndpoint as the default IMessageBrokerProducer.
+ ///
+ public Builder UseProducer(MockEndpoint endpoint)
+ {
+ _inner.Services.AddSingleton(endpoint);
+ return this;
+ }
+
+ ///
+ /// Registers a MockEndpoint as the default IMessageBrokerConsumer.
+ ///
+ public Builder UseConsumer(MockEndpoint endpoint)
+ {
+ _inner.Services.AddSingleton(endpoint);
+ return this;
+ }
+
+ public Builder ConfigureServices(Action configure)
+ {
+ configure(_inner.Services);
+ return this;
+ }
+
+ public Builder AddSingleton(TService instance) where TService : class
+ {
+ _inner.Services.AddSingleton(instance);
+ return this;
+ }
+
+ public Builder Configure(Action configure) where TOptions : class
+ {
+ _inner.Services.Configure(configure);
+ return this;
+ }
+
+ public AspireIntegrationTestHost Build()
+ {
+ var host = _inner.Build();
+ return new AspireIntegrationTestHost(host, _endpoints);
+ }
+ }
+}
diff --git a/EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/MockEndpoint.cs b/EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/MockEndpoint.cs
new file mode 100644
index 0000000..87a22c6
--- /dev/null
+++ b/EnterpriseIntegrationPlatform/tests/TutorialLabs/Infrastructure/MockEndpoint.cs
@@ -0,0 +1,158 @@
+// ============================================================================
+// MockEndpoint – Aspire-style test endpoint for end-to-end integration testing
+// ============================================================================
+// Captures messages published by EIP components and feeds test messages to
+// consumers. Inspired by Apache Camel's MockEndpoint pattern. Replaces
+// NSubstitute mocks with a real send/receive endpoint for E2E tests.
+// ============================================================================
+
+using System.Collections.Concurrent;
+using EnterpriseIntegrationPlatform.Contracts;
+using EnterpriseIntegrationPlatform.Ingestion;
+using NUnit.Framework;
+
+namespace TutorialLabs.Infrastructure;
+
+///
+/// Aspire-style MockEndpoint for end-to-end integration testing.
+/// Implements all broker interfaces so it can act as both producer (captures
+/// outbound messages) and consumer (feeds inbound messages to handlers).
+///
+public sealed class MockEndpoint : IMessageBrokerProducer, IMessageBrokerConsumer,
+ IEventDrivenConsumer, IPollingConsumer, ISelectiveConsumer, IAsyncDisposable
+{
+ private readonly string _name;
+ private readonly ConcurrentQueue _received = new();
+ private readonly ConcurrentQueue