|
2 | 2 |
|
3 | 3 | namespace BuslyCLI.Console.Tests.EndToEnd.AzureServiceBus; |
4 | 4 |
|
5 | | -public class AzureServiceBusEndToEndTestBase : EndToEnd.SingletonTestFixtureBase<ServiceBusContainer> |
| 5 | +public class AzureServiceBusEndToEndTestBase : SingletonTestFixtureBase<ServiceBusContainer> |
6 | 6 | { |
7 | 7 | protected ServiceBusContainer ServiceBusContainer => Container; |
8 | 8 |
|
9 | | - protected IList<Tuple<string, string>> GeneratedTestEndpointNamesAndSubscribedEvent = |
10 | | - new List<Tuple<string, string>>(); |
11 | | - |
| 9 | + // GetConnectionString() uses UriBuilder which appends a trailing slash to the endpoint |
| 10 | + // (e.g. "sb://localhost:12345/"). NServiceBus's InjectEmulatorAdminPort does a string replace |
| 11 | + // looking for "Endpoint=sb://localhost:12345;" (no trailing slash), so it never matches and |
| 12 | + // the admin client ends up using the AMQP port instead of port 5300. |
| 13 | + // This method builds the connection string without the trailing slash so port injection works correctly. |
| 14 | + protected string GetNServiceBusConnectionString() |
| 15 | + { |
| 16 | + var amqpPort = Container.GetMappedPublicPort(ServiceBusBuilder.ServiceBusPort); |
| 17 | + return $"Endpoint=sb://{Container.Hostname}:{amqpPort};SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"; |
| 18 | + } |
12 | 19 |
|
13 | 20 | protected override ServiceBusContainer CreateContainer() |
14 | 21 | { |
15 | | - var azureEmulatorConfigFile = CreateAzureEmulatorConfigFile(); |
16 | | - var emulatorConfigFilePath = Path.GetTempFileName(); |
17 | | - File.WriteAllText(emulatorConfigFilePath, azureEmulatorConfigFile); |
18 | 22 | return new ServiceBusBuilder("mcr.microsoft.com/azure-messaging/servicebus-emulator:latest") |
19 | 23 | .WithAcceptLicenseAgreement(true) |
20 | | - // .WithConfig("./EndToEnd/AzureServiceBus/azure-emulator-config.json") |
21 | | - .WithConfig(emulatorConfigFilePath) |
| 24 | + .WithPortBinding(ServiceBusBuilder.ServiceBusHttpPort, ServiceBusBuilder.ServiceBusHttpPort) |
22 | 25 | .Build(); |
23 | 26 | } |
24 | 27 |
|
25 | | - private string CreateAzureEmulatorConfigFile() |
26 | | - { |
27 | | - for (var i = 0; i < 20; i++) |
28 | | - { |
29 | | - GeneratedTestEndpointNamesAndSubscribedEvent.Add(new Tuple<string, string>( |
30 | | - $"TestEndpoint-{Guid.NewGuid():N}", $"MessageContracts.Events.OrderCreated-{Guid.NewGuid():N}")); |
31 | | - } |
32 | | - |
33 | | - // Build queue entries as JSON strings |
34 | | - var queueEntries = GeneratedTestEndpointNamesAndSubscribedEvent.Select(endpoint => $@"{{ |
35 | | - ""Name"": ""{endpoint.Item1}"", |
36 | | - ""Properties"": {{ |
37 | | - ""DeadLetteringOnMessageExpiration"": false, |
38 | | - ""DefaultMessageTimeToLive"": ""PT1H"", |
39 | | - ""LockDuration"": ""PT1M"", |
40 | | - ""MaxDeliveryCount"": 10, |
41 | | - ""RequiresDuplicateDetection"": false, |
42 | | - ""RequiresSession"": false |
43 | | - }} |
44 | | - }}") |
45 | | - .ToList(); |
46 | | - |
47 | | - // Join all queue entries into the queues array |
48 | | - string queuesJson = string.Join(",\n", queueEntries); |
49 | | - |
50 | | - // Create Subscriptions to the event |
51 | | - var topicEntries = GeneratedTestEndpointNamesAndSubscribedEvent.Select(endpoint => $@"{{ |
52 | | - ""Name"": ""{endpoint.Item2}"", |
53 | | - ""Properties"": {{ |
54 | | - ""DefaultMessageTimeToLive"": ""PT1H"", |
55 | | - ""DuplicateDetectionHistoryTimeWindow"": ""PT20S"", |
56 | | - ""RequiresDuplicateDetection"": false |
57 | | - }}, |
58 | | - ""Subscriptions"": [ |
59 | | - {{ |
60 | | - ""Name"": ""{endpoint.Item1}"", |
61 | | - ""Properties"": {{ |
62 | | - ""DeadLetteringOnMessageExpiration"": false, |
63 | | - ""DefaultMessageTimeToLive"": ""PT1H"", |
64 | | - ""LockDuration"": ""PT1M"", |
65 | | - ""MaxDeliveryCount"": 3, |
66 | | - ""ForwardDeadLetteredMessagesTo"": """", |
67 | | - ""ForwardTo"": ""{endpoint.Item1}"", |
68 | | - ""RequiresSession"": false |
69 | | - }}, |
70 | | - ""Rules"": [ |
71 | | - {{ |
72 | | - ""Name"": ""$default"", |
73 | | - ""Properties"": {{ |
74 | | - ""FilterType"": ""Sql"", |
75 | | - ""SqlFilter"": {{ |
76 | | - ""SqlExpression"": ""1=1"" |
77 | | - }} |
78 | | - }} |
79 | | - }} |
80 | | - ] |
81 | | - }} |
82 | | - ] |
83 | | - }}") |
84 | | - .ToList(); |
85 | | - |
86 | | - string topicsJson = string.Join(",\n", topicEntries); |
87 | | - |
88 | | - // Final config string |
89 | | - string emulatorConfig = $@"{{ |
90 | | - ""UserConfig"": {{ |
91 | | - ""Namespaces"": [ |
92 | | - {{ |
93 | | - ""Name"": ""sbemulatorns"", |
94 | | - ""Queues"": [ |
95 | | - {queuesJson} |
96 | | - ], |
97 | | - ""Topics"": [ |
98 | | - {topicsJson} |
99 | | - ] |
100 | | - }} |
101 | | - ], |
102 | | - ""Logging"": {{ |
103 | | - ""Type"": ""File"" |
104 | | - }} |
105 | | - }} |
106 | | - }}"; |
107 | | - // string emulatorConfig = $@"{{ |
108 | | - // ""UserConfig"": {{ |
109 | | - // ""Namespaces"": [ |
110 | | - // {{ |
111 | | - // ""Name"": ""sbemulatorns"", |
112 | | - // ""Queues"": [ |
113 | | - // {queuesJson} |
114 | | - // ], |
115 | | - // ""Topics"": [ |
116 | | - // {{ |
117 | | - // ""Name"": ""MessageContracts.Events.OrderCreated"", |
118 | | - // ""Properties"": {{ |
119 | | - // ""DefaultMessageTimeToLive"": ""PT1H"", |
120 | | - // ""DuplicateDetectionHistoryTimeWindow"": ""PT20S"", |
121 | | - // ""RequiresDuplicateDetection"": false |
122 | | - // }}, |
123 | | - // ""Subscriptions"": [ |
124 | | - // {subscriptionsJson} |
125 | | - // ] |
126 | | - // }} |
127 | | - // ] |
128 | | - // }} |
129 | | - // ], |
130 | | - // ""Logging"": {{ |
131 | | - // ""Type"": ""File"" |
132 | | - // }} |
133 | | - // }} |
134 | | - // }}"; |
135 | | - |
136 | | - return emulatorConfig; |
137 | | - } |
138 | | - |
139 | 28 | protected override async Task StartContainerAsync(ServiceBusContainer container) |
140 | 29 | { |
141 | 30 | await container.StartAsync(); |
|
0 commit comments