@@ -188,6 +188,7 @@ public async Task VerifyWaitForOnServiceBusEmulatorBlocksDependentResources()
188
188
{
189
189
var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 10 ) ) ;
190
190
using var builder = TestDistributedApplicationBuilder . Create ( output ) ;
191
+
191
192
192
193
var healthCheckTcs = new TaskCompletionSource < HealthCheckResult > ( ) ;
193
194
builder . Services . AddHealthChecks ( ) . AddAsyncCheck ( "blocking_check" , ( ) =>
@@ -231,6 +232,7 @@ public async Task VerifyAzureServiceBusEmulatorResource()
231
232
var cts = new CancellationTokenSource ( TimeSpan . FromMinutes ( 10 ) ) ;
232
233
233
234
using var builder = TestDistributedApplicationBuilder . Create ( ) . WithTestAndResourceLogging ( output ) ;
235
+
234
236
var serviceBus = builder . AddAzureServiceBus ( "servicebusns" )
235
237
. RunAsEmulator ( )
236
238
. WithQueue ( "queue123" ) ;
@@ -267,6 +269,7 @@ public async Task VerifyAzureServiceBusEmulatorResource()
267
269
public void AddAzureServiceBusWithEmulatorGetsExpectedPort ( int ? port = null )
268
270
{
269
271
using var builder = TestDistributedApplicationBuilder . Create ( ) ;
272
+
270
273
var serviceBus = builder . AddAzureServiceBus ( "sb" ) . RunAsEmulator ( configureContainer : builder =>
271
274
{
272
275
builder . WithHostPort ( port ) ;
@@ -601,10 +604,16 @@ public async Task AzureServiceBusEmulatorResourceGeneratesConfigJsonWithCustomiz
601
604
using var builder = TestDistributedApplicationBuilder . Create ( ) ;
602
605
603
606
var serviceBus = builder . AddAzureServiceBus ( "servicebusns" )
604
- . RunAsEmulator ( configure => configure . ConfigureEmulator ( document =>
605
- {
606
- document [ "UserConfig" ] ! [ "Logging" ] = new JsonObject { [ "Type" ] = "Console" } ;
607
- } ) ) ;
607
+ . RunAsEmulator ( configure => configure
608
+ . ConfigureEmulator ( document =>
609
+ {
610
+ document [ "UserConfig" ] ! [ "Logging" ] = new JsonObject { [ "Type" ] = "Console" } ;
611
+ } )
612
+ . ConfigureEmulator ( document =>
613
+ {
614
+ document [ "Custom" ] = JsonValue . Create ( 42 ) ;
615
+ } )
616
+ ) ;
608
617
609
618
using var app = builder . Build ( ) ;
610
619
await app . StartAsync ( ) ;
@@ -627,7 +636,8 @@ public async Task AzureServiceBusEmulatorResourceGeneratesConfigJsonWithCustomiz
627
636
"Logging": {
628
637
"Type": "Console"
629
638
}
630
- }
639
+ },
640
+ "Custom": 42
631
641
}
632
642
""" , configJsonContent ) ;
633
643
@@ -692,4 +702,37 @@ public async Task AzureServiceBusEmulator_WithConfigurationFile()
692
702
{
693
703
}
694
704
}
705
+
706
+ [ Theory ]
707
+ [ InlineData ( true ) ]
708
+ [ InlineData ( false ) ]
709
+ public void AddAzureServiceBusWithEmulator_SetsSqlLifetime ( bool isPersistent )
710
+ {
711
+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
712
+ var lifetime = isPersistent ? ContainerLifetime . Persistent : ContainerLifetime . Session ;
713
+
714
+ var serviceBus = builder . AddAzureServiceBus ( "sb" ) . RunAsEmulator ( configureContainer : builder =>
715
+ {
716
+ builder . WithLifetime ( lifetime ) ;
717
+ } ) ;
718
+
719
+ var sql = builder . Resources . FirstOrDefault ( x => x . Name == "sb-sqledge" ) ;
720
+
721
+ Assert . NotNull ( sql ) ;
722
+
723
+ serviceBus . Resource . TryGetLastAnnotation < ContainerLifetimeAnnotation > ( out var sbLifetimeAnnotation ) ;
724
+ sql . TryGetLastAnnotation < ContainerLifetimeAnnotation > ( out var sqlLifetimeAnnotation ) ;
725
+
726
+ Assert . Equal ( lifetime , sbLifetimeAnnotation ? . Lifetime ) ;
727
+ Assert . Equal ( lifetime , sqlLifetimeAnnotation ? . Lifetime ) ;
728
+ }
729
+
730
+ [ Fact ]
731
+ public void RunAsEmulator_CalledTwice_Throws ( )
732
+ {
733
+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
734
+ var serviceBus = builder . AddAzureServiceBus ( "sb" ) . RunAsEmulator ( ) ;
735
+
736
+ Assert . Throws < InvalidOperationException > ( ( ) => serviceBus . RunAsEmulator ( ) ) ;
737
+ }
695
738
}
0 commit comments