@@ -617,6 +617,72 @@ public void WithEndpoint_WithAllArguments_ForwardsAllArguments()
617617 Assert . Equal ( System . Net . Sockets . ProtocolType . Tcp , endpoint . Protocol ) ;
618618 }
619619
620+ [ Fact ]
621+ public async Task LocalhostTopLevelDomainSetsAnnotationValues ( )
622+ {
623+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
624+
625+ var tcs = new TaskCompletionSource ( ) ;
626+ var projectA = builder . AddProject < ProjectA > ( "projecta" )
627+ . WithHttpsEndpoint ( )
628+ . WithEndpoint ( "https" , e => e . TargetHost = "example.localhost" , createIfNotExists : false )
629+ . OnBeforeResourceStarted ( ( _ , _ , _ ) =>
630+ {
631+ tcs . SetResult ( ) ;
632+ return Task . CompletedTask ;
633+ } ) ;
634+
635+ var app = await builder . BuildAsync ( ) ;
636+ await app . StartAsync ( ) ;
637+ await tcs . Task ;
638+
639+ var urls = projectA . Resource . Annotations . OfType < ResourceUrlAnnotation > ( ) ;
640+ Assert . Collection ( urls ,
641+ url => Assert . StartsWith ( "https://localhost:" , url . Url ) ,
642+ url => Assert . StartsWith ( "https://example.localhost:" , url . Url ) ) ;
643+
644+ EndpointAnnotation endpoint = Assert . Single ( projectA . Resource . Annotations . OfType < EndpointAnnotation > ( ) ) ;
645+ Assert . NotNull ( endpoint . AllocatedEndpoint ) ;
646+ Assert . Equal ( EndpointBindingMode . SingleAddress , endpoint . AllocatedEndpoint . BindingMode ) ;
647+ Assert . Equal ( "localhost" , endpoint . AllocatedEndpoint . Address ) ;
648+
649+ await app . StopAsync ( ) ;
650+ }
651+
652+ [ Theory ]
653+ [ InlineData ( "0.0.0.0" , EndpointBindingMode . IPv4AnyAddresses ) ]
654+ //[InlineData("::", EndpointBindingMode.IPv6AnyAddresses)] // Need to figure out a good way to check that Ipv6 binding is supported
655+ public async Task TopLevelDomainSetsAnnotationValues ( string host , EndpointBindingMode endpointBindingMode )
656+ {
657+ using var builder = TestDistributedApplicationBuilder . Create ( ) ;
658+
659+ var tcs = new TaskCompletionSource ( ) ;
660+ var projectA = builder . AddProject < ProjectA > ( "projecta" )
661+ . WithHttpsEndpoint ( )
662+ . WithEndpoint ( "https" , e => e . TargetHost = host , createIfNotExists : false )
663+ . OnBeforeResourceStarted ( ( _ , _ , _ ) =>
664+ {
665+ tcs . SetResult ( ) ;
666+ return Task . CompletedTask ;
667+ } ) ;
668+
669+ var app = await builder . BuildAsync ( ) ;
670+ await app . StartAsync ( ) ;
671+ await tcs . Task ;
672+
673+ var urls = projectA . Resource . Annotations . OfType < ResourceUrlAnnotation > ( ) ;
674+ Assert . Collection ( urls ,
675+ url => Assert . StartsWith ( "https://localhost:" , url . Url ) ,
676+ url => Assert . StartsWith ( $ "https://{ Environment . MachineName } :", url . Url ) ) ;
677+
678+ EndpointAnnotation endpoint = Assert . Single ( projectA . Resource . Annotations . OfType < EndpointAnnotation > ( ) ) ;
679+ Assert . NotNull ( endpoint . AllocatedEndpoint ) ;
680+ Assert . Equal ( endpointBindingMode , endpoint . AllocatedEndpoint . BindingMode ) ;
681+ Assert . Equal ( "localhost" , endpoint . AllocatedEndpoint . Address ) ;
682+
683+ await app . StopAsync ( ) ;
684+ }
685+
620686 private sealed class TestProject : IProjectMetadata
621687 {
622688 public string ProjectPath => "projectpath" ;
0 commit comments