Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BuslyCLI.Console/Factories/IRawEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BuslyCLI.Factories;

public interface IRawEndpointFactory
{
Task<RawEndpoint> CreateRawEndpoint(string endpointName, TransportConfig transportConfig);
Task<RawEndpoint> CreateRawEndpoint(string endpointName, TransportConfig transportConfig, bool setupInfrastructure = true);

Task<RawSendOnlyEndpoint> CreateRawSendOnlyEndpoint(string endpointName, TransportConfig transportConfig);
}
2 changes: 1 addition & 1 deletion src/BuslyCLI.Console/Factories/RawEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IncomingMessage> _receivedMessages = new();
Expand Down
22 changes: 13 additions & 9 deletions src/BuslyCLI.Console/Factories/RawEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace BuslyCLI.Factories;

public class RawEndpointFactory : IRawEndpointFactory
{
public async Task<RawEndpoint> CreateRawEndpoint(string endpointName, TransportConfig transportConfig)
public async Task<RawEndpoint> 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<RawSendOnlyEndpoint> CreateRawSendOnlyEndpoint(string endpointName, TransportConfig transportConfig)
Expand Down Expand Up @@ -148,14 +148,16 @@ private AzureServiceBusTransport CreateAzureServiceBusTransport(string transport

private static async Task<RawEndpoint> 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<RawSendOnlyEndpoint> InternalCreateSendOnlyEndpoint(
Expand All @@ -165,15 +167,17 @@ private static async Task<RawSendOnlyEndpoint> 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<TransportInfrastructure> InternalCreateInfrastructure(
string endpointName,
TransportDefinition transport,
bool isReceiveEnabled)
bool isReceiveEnabled,
bool setupInfrastructure)
{
var hostSettings = new HostSettings(
endpointName,
Expand All @@ -183,7 +187,7 @@ private static async Task<TransportInfrastructure> InternalCreateInfrastructure(
{
// Console.WriteLine("Critical error: " + exception);
},
isReceiveEnabled);
setupInfrastructure);

var infrastructure = await transport.Initialize(hostSettings,
isReceiveEnabled
Expand Down
4 changes: 3 additions & 1 deletion src/BuslyCLI.Console/Factories/RawSendOnlyEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -110,9 +111,19 @@ await RunWithTestEndpoint(async testEndpoint =>
});
}

private async Task RunWithTestEndpoint(Func<TestEndpoint, Task> testAction)
private async Task RunWithTestEndpoint(Func<RawEndpoint, Task> 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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -116,11 +117,17 @@ await RunWithTestEndpoint(async testEndpoint =>
});
}

private async Task RunWithTestEndpoint(Func<TestEndpoint, Task> testAction)
private async Task RunWithTestEndpoint(Func<RawEndpoint, Task> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<TestEndpoint, Task> testAction)
private async Task RunWithTestEndpoint(Func<RawEndpoint, Task> 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();
Expand Down

This file was deleted.

Loading