diff --git a/src/BuslyCLI.Console/Factories/IRawEndpointFactory.cs b/src/BuslyCLI.Console/Factories/IRawEndpointFactory.cs index bd91079..8098406 100644 --- a/src/BuslyCLI.Console/Factories/IRawEndpointFactory.cs +++ b/src/BuslyCLI.Console/Factories/IRawEndpointFactory.cs @@ -4,7 +4,7 @@ namespace BuslyCLI.Factories; public interface IRawEndpointFactory { - Task CreateRawEndpoint(string endpointName, TransportConfig transportConfig); + Task CreateRawEndpoint(string endpointName, TransportConfig transportConfig, bool setupInfrastructure = true); Task CreateRawSendOnlyEndpoint(string endpointName, TransportConfig transportConfig); } \ No newline at end of file diff --git a/src/BuslyCLI.Console/Factories/RawEndpoint.cs b/src/BuslyCLI.Console/Factories/RawEndpoint.cs index 58d6140..981a2a1 100644 --- a/src/BuslyCLI.Console/Factories/RawEndpoint.cs +++ b/src/BuslyCLI.Console/Factories/RawEndpoint.cs @@ -7,7 +7,7 @@ namespace BuslyCLI.Factories; -public class RawEndpoint(TransportInfrastructure infrastructure) : RawSendOnlyEndpoint(infrastructure) +public class RawEndpoint(TransportInfrastructure infrastructure, string endpointName) : RawSendOnlyEndpoint(infrastructure, endpointName) { private static readonly TimeSpan IncomingMessageTimeout = TimeSpan.FromSeconds(5); private readonly BlockingCollection _receivedMessages = new(); diff --git a/src/BuslyCLI.Console/Factories/RawEndpointFactory.cs b/src/BuslyCLI.Console/Factories/RawEndpointFactory.cs index 24d7c8e..0d8208e 100644 --- a/src/BuslyCLI.Console/Factories/RawEndpointFactory.cs +++ b/src/BuslyCLI.Console/Factories/RawEndpointFactory.cs @@ -10,10 +10,10 @@ namespace BuslyCLI.Factories; public class RawEndpointFactory : IRawEndpointFactory { - public async Task CreateRawEndpoint(string endpointName, TransportConfig transportConfig) + public async Task CreateRawEndpoint(string endpointName, TransportConfig transportConfig, bool setupInfrastructure = true) { var transport = CreateTransport(transportConfig); - return await InternalCreateEndpoint(endpointName, transport); + return await InternalCreateEndpoint(endpointName, transport, setupInfrastructure); } public async Task CreateRawSendOnlyEndpoint(string endpointName, TransportConfig transportConfig) @@ -148,14 +148,16 @@ private AzureServiceBusTransport CreateAzureServiceBusTransport(string transport private static async Task InternalCreateEndpoint( string endpointName, - TransportDefinition transport) + TransportDefinition transport, + bool setupInfrastructure = true) { var infrastructure = await InternalCreateInfrastructure( endpointName, transport, - isReceiveEnabled: true); + isReceiveEnabled: true, + setupInfrastructure); - return new RawEndpoint(infrastructure); + return new RawEndpoint(infrastructure, endpointName); } private static async Task InternalCreateSendOnlyEndpoint( @@ -165,15 +167,17 @@ private static async Task InternalCreateSendOnlyEndpoint( var infrastructure = await InternalCreateInfrastructure( endpointName, transport, - isReceiveEnabled: false); + isReceiveEnabled: false, + setupInfrastructure: false); - return new RawSendOnlyEndpoint(infrastructure); + return new RawSendOnlyEndpoint(infrastructure, endpointName); } private static async Task InternalCreateInfrastructure( string endpointName, TransportDefinition transport, - bool isReceiveEnabled) + bool isReceiveEnabled, + bool setupInfrastructure) { var hostSettings = new HostSettings( endpointName, @@ -183,7 +187,7 @@ private static async Task InternalCreateInfrastructure( { // Console.WriteLine("Critical error: " + exception); }, - isReceiveEnabled); + setupInfrastructure); var infrastructure = await transport.Initialize(hostSettings, isReceiveEnabled diff --git a/src/BuslyCLI.Console/Factories/RawSendOnlyEndpoint.cs b/src/BuslyCLI.Console/Factories/RawSendOnlyEndpoint.cs index 6e234e1..fcb54ea 100644 --- a/src/BuslyCLI.Console/Factories/RawSendOnlyEndpoint.cs +++ b/src/BuslyCLI.Console/Factories/RawSendOnlyEndpoint.cs @@ -5,11 +5,13 @@ namespace BuslyCLI.Factories; public class RawSendOnlyEndpoint { protected readonly TransportInfrastructure _infrastructure; + public string EndpointName { get; } - public RawSendOnlyEndpoint(TransportInfrastructure infrastructure) + public RawSendOnlyEndpoint(TransportInfrastructure infrastructure, string endpointName) { _infrastructure = infrastructure; + EndpointName = endpointName; } public async Task Dispatch(TransportOperations outgoingMessages, TransportTransaction transaction, diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs index 93215b3..600ca6b 100644 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs +++ b/tests/BuslyCLI.Console.Tests/EndToEnd/AmazonSQS/SendCommandAmazonSqsEndToEndAmazonSqsTests.cs @@ -1,8 +1,9 @@ using System.Text; using System.Text.Json; -using BuslyCLI.Console.Tests.EndToEnd.Infrastructure; +using BuslyCLI.Config; using BuslyCLI.Console.Tests.TestHelpers; using BuslyCLI.DependencyInjection; +using BuslyCLI.Factories; using BuslyCLI.Spectre; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli.Extensions.DependencyInjection; @@ -110,9 +111,19 @@ await RunWithTestEndpoint(async testEndpoint => }); } - private async Task RunWithTestEndpoint(Func testAction) + private async Task RunWithTestEndpoint(Func testAction) { - var testEndpoint = await new TestEndpointFactory().CreateAmazonSQSTestEndpoint(Container.GetConnectionString()); + var testEndpoint = await new RawEndpointFactory().CreateRawEndpoint(TestEndpointNameGenerator.GenerateUniqueEndpointName(), new TransportConfig() + { + AmazonsqsTransportConfig = new AmazonsqsTransportConfig() + { + ServiceUrl = Container.GetConnectionString(), + RegionName = "us-east-1", + AccessKey = "test", + SecretKey = "test" + } + }); + try { diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs index 2240655..4bb4a9e 100644 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs +++ b/tests/BuslyCLI.Console.Tests/EndToEnd/AzureServiceBus/SendCommandAzureServiceBusEndToEndTests.cs @@ -1,8 +1,9 @@ using System.Text; using System.Text.Json; -using BuslyCLI.Console.Tests.EndToEnd.Infrastructure; +using BuslyCLI.Config; using BuslyCLI.Console.Tests.TestHelpers; using BuslyCLI.DependencyInjection; +using BuslyCLI.Factories; using BuslyCLI.Spectre; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli.Extensions.DependencyInjection; @@ -116,11 +117,17 @@ await RunWithTestEndpoint(async testEndpoint => }); } - private async Task RunWithTestEndpoint(Func testAction) + private async Task RunWithTestEndpoint(Func testAction) { var random = new Random(); var testEndpointName = GeneratedTestEndpointNamesAndSubscribedEvent[random.Next(GeneratedTestEndpointNamesAndSubscribedEvent.Count)]; - var testEndpoint = await new TestEndpointFactory().CreateAzureServiceBusTestEndpoint(testEndpointName.Item1, Container.GetConnectionString()); + var testEndpoint = await new RawEndpointFactory().CreateRawEndpoint(testEndpointName.Item1, new TransportConfig() + { + AzureServiceBusTransportConfig = new AzureServiceBusTransportConfig() + { + ConnectionString = Container.GetConnectionString() + } + }, false); await testAction(testEndpoint); await testEndpoint.ShutDownAndCleanUp(); diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/AzureStorageQueues/SendCommandAzureStorageQueuesEndToEndTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/AzureStorageQueues/SendCommandAzureStorageQueuesEndToEndTests.cs index e1ddd9d..95b492c 100644 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/AzureStorageQueues/SendCommandAzureStorageQueuesEndToEndTests.cs +++ b/tests/BuslyCLI.Console.Tests/EndToEnd/AzureStorageQueues/SendCommandAzureStorageQueuesEndToEndTests.cs @@ -1,8 +1,9 @@ using System.Text; using System.Text.Json; -using BuslyCLI.Console.Tests.EndToEnd.Infrastructure; +using BuslyCLI.Config; using BuslyCLI.Console.Tests.TestHelpers; using BuslyCLI.DependencyInjection; +using BuslyCLI.Factories; using BuslyCLI.Spectre; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli.Extensions.DependencyInjection; @@ -109,9 +110,15 @@ await RunWithTestEndpoint(async testEndpoint => // Test Endpoint // Example of how to wait for and get messages // https://github.com/Particular/NServiceBus.RabbitMQ/blob/dba627a5a2c50519d7a2466efe3f76c8d5c8828d/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs#L41 - private async Task RunWithTestEndpoint(Func testAction) + private async Task RunWithTestEndpoint(Func testAction) { - var testEndpoint = await new TestEndpointFactory().CreateAzureStorageQueuesTestEndpoint(Container.GetConnectionString()); + var testEndpoint = await new RawEndpointFactory().CreateRawEndpoint(TestEndpointNameGenerator.GenerateUniqueEndpointName(), new TransportConfig() + { + AzureStorageQueuesTransportConfig = new AzureStorageQueuesTransportConfig() + { + ConnectionString = Container.GetConnectionString() + } + }); await testAction(testEndpoint); await testEndpoint.ShutDownAndCleanUp(); diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/Infrastructure/ITestEndpointFactory.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/Infrastructure/ITestEndpointFactory.cs deleted file mode 100644 index b53fd64..0000000 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/Infrastructure/ITestEndpointFactory.cs +++ /dev/null @@ -1,118 +0,0 @@ -using Amazon.Runtime; -using Amazon.SimpleNotificationService; -using Amazon.SQS; -using NServiceBus.Transport; - -namespace BuslyCLI.Console.Tests.EndToEnd.Infrastructure; - -public class TestEndpointFactory -{ - /// - /// Generates a unique endpoint name for testing purposes. - /// - /// Optional prefix for the endpoint name. Defaults to "TestEndpoint". - /// A unique endpoint name with the format "{prefix}-{guid}" - public static string GenerateUniqueEndpointName(string prefix = "TestEndpoint") - { - return $"{prefix}-{Guid.NewGuid():N}"; - } - - public async Task CreateRabbitMQTestEndpoint(string transportConnectionString, - string managementApiUrl) - { - var name = GenerateUniqueEndpointName(); - var transport = new RabbitMQTransport(RoutingTopology.Conventional(QueueType.Quorum), transportConnectionString) - { - ManagementApiConfiguration = new ManagementApiConfiguration(managementApiUrl) - }; - return await InternalCreateTestEndpoint(name, transport); - } - - public async Task CreateAmazonSQSTestEndpoint(string transportConnectionString) - { - var name = GenerateUniqueEndpointName(); - - // Set up AWS credentials and region - var credentials = new BasicAWSCredentials("test", "test"); - - var sqsClient = new AmazonSQSClient(credentials, new AmazonSQSConfig - { - ServiceURL = transportConnectionString, - AuthenticationRegion = "us-east-1", - }); - - var snsClient = new AmazonSimpleNotificationServiceClient(credentials, new AmazonSimpleNotificationServiceConfig - { - ServiceURL = transportConnectionString, - AuthenticationRegion = "us-east-1", - }); - - return await InternalCreateTestEndpoint(name, new SqsTransport(sqsClient, snsClient)); - } - - public async Task CreateLearningTestEndpoint(string storageDirectory) - { - var name = GenerateUniqueEndpointName(); - return await InternalCreateTestEndpoint(name, new LearningTransport() - { - StorageDirectory = storageDirectory - }); - } - - public async Task CreateAzureServiceBusTestEndpoint(string endpointName, string connectionString) - { - return await InternalCreateTestEndpoint(endpointName, new AzureServiceBusTransport(connectionString, TopicTopology.Default)); - } - - private static async Task InternalCreateTestEndpoint(string endpointName, - TransportDefinition transport) - { - - var hostSettings = new HostSettings( - endpointName, - endpointName, - new StartupDiagnosticEntries(), - criticalErrorAction: (message, exception, token) => - { - TestContext.Out.WriteLine("Critical error: " + exception); - }, - // TODO: This needs to be false for "Azure Service Bus Emulator" tests to pass - transport is not AzureServiceBusTransport - ); - - var infrastructure = await transport.Initialize(hostSettings, [ - new ReceiveSettings( - "Primary", - new QueueAddress(endpointName), - true, - false, - "error") - ], []); - - - return new TestEndpoint(infrastructure); - } - - public async Task CreateSqlServerTestEndpoint(string sqlConnectionString) - { - var name = GenerateUniqueEndpointName(); - var transport = new SqlServerTransport(sqlConnectionString); - return await InternalCreateTestEndpoint(name, transport); - } - - public async Task CreatePostgreSqlTransport(string connectionString) - { - var name = GenerateUniqueEndpointName(); - var transport = new PostgreSqlTransport(connectionString); - return await InternalCreateTestEndpoint(name, transport); - } - - public async Task CreateAzureStorageQueuesTestEndpoint(string connectionString) - { - var name = GenerateUniqueEndpointName(); - var transport = new AzureStorageQueueTransport(connectionString); - transport.MessageWrapperSerializationDefinition = new SystemJsonSerializer(); - - return await InternalCreateTestEndpoint(name, transport); - } -} \ No newline at end of file diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/Infrastructure/TestEndpoint.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/Infrastructure/TestEndpoint.cs deleted file mode 100644 index af9def4..0000000 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/Infrastructure/TestEndpoint.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System.Collections.Concurrent; -using System.Reflection; -using System.Reflection.Emit; -using NServiceBus.Extensibility; -using NServiceBus.Transport; -using NServiceBus.Unicast.Messages; - -namespace BuslyCLI.Console.Tests.EndToEnd.Infrastructure; - -public class TestEndpoint -{ - private static readonly TimeSpan IncomingMessageTimeout = TimeSpan.FromSeconds(5); - private readonly TransportInfrastructure _infrastructure; - private readonly BlockingCollection _receivedMessages = new(); - private IMessageReceiver _messageReceiver; - private ISubscriptionManager _subscriptionManager; - - public TestEndpoint(TransportInfrastructure infrastructure) - { - _infrastructure = infrastructure; - } - - /// - /// Gets the name of this test endpoint. - /// - public string EndpointName => _messageReceiver.ReceiveAddress; - - public async Task StartEndpoint() - { - _messageReceiver = _infrastructure.Receivers["Primary"]; - _subscriptionManager = _messageReceiver.Subscriptions; - await _messageReceiver.Initialize(new PushRuntimeSettings(1), - OnMessage, - OnError); - - await _messageReceiver.StartReceive(); - } - - public async Task StopReceive() - { - await _messageReceiver.StopReceive(); - } - - public async Task ShutDownAndCleanUp() - { - await _messageReceiver.StopReceive(); - await _infrastructure.Shutdown(); - } - - private static Type CreateTypeFromString(string typeAsString) - { - var typeSignature = typeAsString; - var an = new AssemblyName(typeSignature); - var assemblyBuilder = - AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), - AssemblyBuilderAccess.Run); - var moduleBuilder = assemblyBuilder.DefineDynamicModule("MainModule"); - - - var type = moduleBuilder.DefineType(typeSignature, - TypeAttributes.Public | - TypeAttributes.Class | - TypeAttributes.AutoClass | - TypeAttributes.AnsiClass | - TypeAttributes.BeforeFieldInit | - TypeAttributes.AutoLayout, - null).GetTypeInfo().AsType(); - return type; - } - - public async Task Subscribe(string eventType, CancellationToken cancellationToken = default) - { - await _subscriptionManager.SubscribeAll([new MessageMetadata(CreateTypeFromString(eventType))], - new ContextBag(), cancellationToken); - } - - public Task OnMessage(MessageContext messageContext, CancellationToken cancellationToken) - { - _receivedMessages.Add( - new IncomingMessage(messageContext.NativeMessageId, messageContext.Headers, messageContext.Body), - cancellationToken); - return Task.CompletedTask; - } - - public Task OnError(ErrorContext errorContext, CancellationToken cancellationToken) - { - return Task.FromResult(ErrorHandleResult.RetryRequired); - } - - public IncomingMessage TryReceiveMessage() - { - if (_receivedMessages.TryTake(out var incomingMessage, IncomingMessageTimeout)) return incomingMessage; - throw new TimeoutException($"The message did not arrive within {IncomingMessageTimeout.TotalSeconds} seconds."); - } -} \ No newline at end of file diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs index 75bbc75..646cd66 100644 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs +++ b/tests/BuslyCLI.Console.Tests/EndToEnd/Learning/SendCommandEndToEndLearningTests.cs @@ -1,8 +1,9 @@ using System.Text; using System.Text.Json; -using BuslyCLI.Console.Tests.EndToEnd.Infrastructure; +using BuslyCLI.Config; using BuslyCLI.Console.Tests.TestHelpers; using BuslyCLI.DependencyInjection; +using BuslyCLI.Factories; using BuslyCLI.Spectre; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli.Extensions.DependencyInjection; @@ -106,9 +107,16 @@ await RunWithTestEndpoint(async testEndpoint => }); } - private async Task RunWithTestEndpoint(Func testAction) + private async Task RunWithTestEndpoint(Func testAction) { - var testEndpoint = await new TestEndpointFactory().CreateLearningTestEndpoint("./.learningtransport"); + var testEndpoint = await new RawEndpointFactory().CreateRawEndpoint(TestEndpointNameGenerator.GenerateUniqueEndpointName(), new TransportConfig() + { + LearningTransportConfig = new LearningTransportConfig() + { + StorageDirectory = "./.learningtransport", + } + }); + try { diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/PostgreSql/SendCommandPostgreSqlEndToEndTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/PostgreSql/SendCommandPostgreSqlEndToEndTests.cs index fb65e95..c7a2497 100644 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/PostgreSql/SendCommandPostgreSqlEndToEndTests.cs +++ b/tests/BuslyCLI.Console.Tests/EndToEnd/PostgreSql/SendCommandPostgreSqlEndToEndTests.cs @@ -1,8 +1,9 @@ using System.Text; using System.Text.Json; -using BuslyCLI.Console.Tests.EndToEnd.Infrastructure; +using BuslyCLI.Config; using BuslyCLI.Console.Tests.TestHelpers; using BuslyCLI.DependencyInjection; +using BuslyCLI.Factories; using BuslyCLI.Spectre; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli.Extensions.DependencyInjection; @@ -110,9 +111,16 @@ await RunWithTestEndpoint(async testEndpoint => // Test Endpoint // Example of how to wait for and get messages // https://github.com/Particular/NServiceBus.RabbitMQ/blob/dba627a5a2c50519d7a2466efe3f76c8d5c8828d/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs#L41 - private async Task RunWithTestEndpoint(Func testAction) + private async Task RunWithTestEndpoint(Func testAction) { - var testEndpoint = await new TestEndpointFactory().CreatePostgreSqlTransport(Container.GetConnectionString()); + var testEndpoint = await new RawEndpointFactory().CreateRawEndpoint(TestEndpointNameGenerator.GenerateUniqueEndpointName(), new TransportConfig() + { + PostgreSqlTransportConfig = new PostgreSqlTransportConfig() + { + ConnectionString = Container.GetConnectionString() + } + }); + await testAction(testEndpoint); await testEndpoint.ShutDownAndCleanUp(); diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs index 2b1e906..418a58c 100644 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs +++ b/tests/BuslyCLI.Console.Tests/EndToEnd/RabbitMQ/SendCommandRabbitMqEndToEndTests.cs @@ -1,8 +1,9 @@ using System.Text; using System.Text.Json; -using BuslyCLI.Console.Tests.EndToEnd.Infrastructure; +using BuslyCLI.Config; using BuslyCLI.Console.Tests.TestHelpers; using BuslyCLI.DependencyInjection; +using BuslyCLI.Factories; using BuslyCLI.Spectre; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli.Extensions.DependencyInjection; @@ -113,10 +114,19 @@ await RunWithTestEndpoint(async testEndpoint => // Test Endpoint // Example of how to wait for and get messages // https://github.com/Particular/NServiceBus.RabbitMQ/blob/dba627a5a2c50519d7a2466efe3f76c8d5c8828d/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs#L41 - private async Task RunWithTestEndpoint(Func testAction) + private async Task RunWithTestEndpoint(Func testAction) { - var testEndpoint = await new TestEndpointFactory().CreateRabbitMQTestEndpoint(Container.GetConnectionString(), - $"http://{Container.Hostname}:{Container.GetMappedPublicPort(15672)}"); + var testEndpoint = await new RawEndpointFactory().CreateRawEndpoint(TestEndpointNameGenerator.GenerateUniqueEndpointName(), new TransportConfig() + { + RabbitmqTransportConfig = new RabbitmqTransportConfig() + { + AmqpConnectionString = Container.GetConnectionString(), + ManagementApi = new ManagementApi + { + Url = $"http://{Container.Hostname}:{Container.GetMappedPublicPort(15672)}" + } + } + }); await testAction(testEndpoint); await testEndpoint.ShutDownAndCleanUp(); diff --git a/tests/BuslyCLI.Console.Tests/EndToEnd/SqlServer/SendCommandSqlServerEndToEndTests.cs b/tests/BuslyCLI.Console.Tests/EndToEnd/SqlServer/SendCommandSqlServerEndToEndTests.cs index e3e4d85..18027d4 100644 --- a/tests/BuslyCLI.Console.Tests/EndToEnd/SqlServer/SendCommandSqlServerEndToEndTests.cs +++ b/tests/BuslyCLI.Console.Tests/EndToEnd/SqlServer/SendCommandSqlServerEndToEndTests.cs @@ -1,8 +1,9 @@ using System.Text; using System.Text.Json; -using BuslyCLI.Console.Tests.EndToEnd.Infrastructure; +using BuslyCLI.Config; using BuslyCLI.Console.Tests.TestHelpers; using BuslyCLI.DependencyInjection; +using BuslyCLI.Factories; using BuslyCLI.Spectre; using Microsoft.Extensions.DependencyInjection; using Spectre.Console.Cli.Extensions.DependencyInjection; @@ -109,9 +110,15 @@ await RunWithTestEndpoint(async testEndpoint => // Test Endpoint // Example of how to wait for and get messages // https://github.com/Particular/NServiceBus.RabbitMQ/blob/dba627a5a2c50519d7a2466efe3f76c8d5c8828d/src/NServiceBus.Transport.RabbitMQ.Tests/RabbitMqContext.cs#L41 - private async Task RunWithTestEndpoint(Func testAction) + private async Task RunWithTestEndpoint(Func testAction) { - var testEndpoint = await new TestEndpointFactory().CreateSqlServerTestEndpoint(Container.GetConnectionString()); + var testEndpoint = await new RawEndpointFactory().CreateRawEndpoint(TestEndpointNameGenerator.GenerateUniqueEndpointName(), new TransportConfig() + { + SqlServerTransportConfig = new SqlServerTransportConfig() + { + ConnectionString = Container.GetConnectionString(), + } + }); await testAction(testEndpoint); await testEndpoint.ShutDownAndCleanUp(); diff --git a/tests/BuslyCLI.Console.Tests/TestEndpointNameGenerator.cs b/tests/BuslyCLI.Console.Tests/TestEndpointNameGenerator.cs new file mode 100644 index 0000000..ad42c84 --- /dev/null +++ b/tests/BuslyCLI.Console.Tests/TestEndpointNameGenerator.cs @@ -0,0 +1,9 @@ +namespace BuslyCLI.Console.Tests; + +public static class TestEndpointNameGenerator +{ + public static string GenerateUniqueEndpointName(string prefix = "TestEndpoint") + { + return $"{prefix}-{Guid.NewGuid():N}"; + } +} \ No newline at end of file