@@ -247,23 +247,23 @@ public void ConnectionNameWinsOverConfigSection(bool useKeyed, int clientIndex)
247
247
248
248
private static void RetrieveAndAssert ( bool useKeyed , int clientIndex , IHost host )
249
249
{
250
- var client = RetrieveClient ( useKeyed , clientIndex , host ) ;
250
+ var client = RetrieveClient ( useKeyed ? "eh" : null , clientIndex , host ) ;
251
251
252
- AssertFullyQualifiedNamespace ( client ) ;
252
+ AssertFullyQualifiedNamespace ( FullyQualifiedNamespace , client ) ;
253
253
}
254
254
255
- private static object RetrieveClient ( bool useKeyed , int clientIndex , IHost host )
255
+ private static object RetrieveClient ( object ? key , int clientIndex , IHost host )
256
256
{
257
- var client = useKeyed ?
258
- host . Services . GetRequiredKeyedService ( s_clientTypes [ clientIndex ] , "eh" ) :
257
+ var client = key is not null ?
258
+ host . Services . GetRequiredKeyedService ( s_clientTypes [ clientIndex ] , key ) :
259
259
host . Services . GetRequiredService ( s_clientTypes [ clientIndex ] ) ;
260
260
261
261
return client ;
262
262
}
263
263
264
- private static void AssertFullyQualifiedNamespace ( object client )
264
+ private static void AssertFullyQualifiedNamespace ( string expectedNamespace , object client )
265
265
{
266
- Assert . Equal ( FullyQualifiedNamespace , client switch
266
+ Assert . Equal ( expectedNamespace , client switch
267
267
{
268
268
EventHubProducerClient producer => producer . FullyQualifiedNamespace ,
269
269
EventHubConsumerClient consumer => consumer . FullyQualifiedNamespace ,
@@ -324,6 +324,50 @@ public void NamespaceWorksInConnectionStrings(bool useKeyed, int clientIndex)
324
324
RetrieveAndAssert ( useKeyed , clientIndex , host ) ;
325
325
}
326
326
327
+ [ Theory ]
328
+ [ InlineData ( EventHubProducerClientIndex ) ]
329
+ [ InlineData ( EventHubConsumerClientIndex ) ]
330
+ [ InlineData ( EventProcessorClientIndex ) ]
331
+ [ InlineData ( PartitionReceiverIndex ) ]
332
+ public void CanAddMultipleKeyedServices ( int clientIndex )
333
+ {
334
+ var builder = Host . CreateEmptyApplicationBuilder ( null ) ;
335
+ builder . Configuration . AddInMemoryCollection ( [
336
+ new KeyValuePair < string , string ? > ( "ConnectionStrings:eh1" , EhConnectionString ) ,
337
+ new KeyValuePair < string , string ? > ( $ "Aspire:Azure:Messaging:EventHubs:{ s_clientTypes [ clientIndex ] . Name } :BlobContainerName", "checkpoints" ) ,
338
+ new KeyValuePair < string , string ? > ( $ "Aspire:Azure:Messaging:EventHubs:{ s_clientTypes [ clientIndex ] . Name } :PartitionId", "foo" ) ,
339
+
340
+ new KeyValuePair < string , string ? > ( "ConnectionStrings:eh2" , EhConnectionString . Replace ( "aspireeventhubstests" , "aspireeventhubstests2" ) ) ,
341
+ new KeyValuePair < string , string ? > ( $ "Aspire:Azure:Messaging:EventHubs:{ s_clientTypes [ clientIndex ] . Name } :eh2:BlobContainerName", "checkpoints" ) ,
342
+ new KeyValuePair < string , string ? > ( $ "Aspire:Azure:Messaging:EventHubs:{ s_clientTypes [ clientIndex ] . Name } :eh2:PartitionId", "foo" ) ,
343
+
344
+ new KeyValuePair < string , string ? > ( "ConnectionStrings:eh3" , EhConnectionString . Replace ( "aspireeventhubstests" , "aspireeventhubstests3" ) ) ,
345
+ new KeyValuePair < string , string ? > ( $ "Aspire:Azure:Messaging:EventHubs:{ s_clientTypes [ clientIndex ] . Name } :eh3:BlobContainerName", "checkpoints" ) ,
346
+ new KeyValuePair < string , string ? > ( $ "Aspire:Azure:Messaging:EventHubs:{ s_clientTypes [ clientIndex ] . Name } :eh3:PartitionId", "foo" ) ,
347
+ ] ) ;
348
+
349
+ ConfigureBlobServiceClient ( useKeyed : false , builder . Services ) ;
350
+
351
+ s_clientAdders [ clientIndex ] ( builder , "eh1" , null ) ;
352
+ s_keyedClientAdders [ clientIndex ] ( builder , "eh2" , null ) ;
353
+ s_keyedClientAdders [ clientIndex ] ( builder , "eh3" , null ) ;
354
+
355
+ using var host = builder . Build ( ) ;
356
+
357
+ // Unkeyed services don't work with keyed services. See https://github.com/dotnet/aspire/issues/3890
358
+ //var client1 = RetrieveClient(key: null, clientIndex, host);
359
+ var client2 = RetrieveClient ( key : "eh2" , clientIndex , host ) ;
360
+ var client3 = RetrieveClient ( key : "eh3" , clientIndex , host ) ;
361
+
362
+ //Assert.NotSame(client1, client2);
363
+ //Assert.NotSame(client1, client3);
364
+ Assert . NotSame ( client2 , client3 ) ;
365
+
366
+ //AssertFullyQualifiedNamespace("aspireeventhubstests.servicebus.windows.net", client1);
367
+ AssertFullyQualifiedNamespace ( "aspireeventhubstests2.servicebus.windows.net" , client2 ) ;
368
+ AssertFullyQualifiedNamespace ( "aspireeventhubstests3.servicebus.windows.net" , client3 ) ;
369
+ }
370
+
327
371
public static string CreateConfigKey ( string prefix , string ? key , string suffix )
328
372
=> string . IsNullOrEmpty ( key ) ? $ "{ prefix } :{ suffix } " : $ "{ prefix } :{ key } :{ suffix } ";
329
373
}
0 commit comments