@@ -7,6 +7,8 @@ public sealed class EventHubsBuilder : ContainerBuilder<EventHubsBuilder, EventH
77 public const string EventHubsImage = "mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest" ;
88
99 public const ushort EventHubsPort = 5672 ;
10+
11+ public const string AzuriteNetworkAlias = "azurite" ;
1012
1113 private const string AcceptLicenseAgreementEnvVar = "ACCEPT_EULA" ;
1214
@@ -50,39 +52,45 @@ public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurat
5052 }
5153
5254 /// <summary>
53- /// Sets the endpoint of the azurite blob service
55+ /// Accepts the license agreement.
5456 /// </summary>
55- /// <param name="azuriteBlobEndpoint"></param>
56- /// <returns></returns>
57- public EventHubsBuilder WithAzuriteBlobEndpoint ( string azuriteBlobEndpoint )
57+ /// <remarks>
58+ /// When <paramref name="acceptLicenseAgreement" /> is set to <c>true</c>, the Azure Event Hubs Emulator <see href="https://github.com/Azure/azure-event-hubs-emulator-installer/blob/main/EMULATOR_EULA.md">license</see> is accepted.
59+ /// </remarks>
60+ /// <param name="acceptLicenseAgreement">A boolean value indicating whether the Azure Event Hubs Emulator license agreement is accepted.</param>
61+ /// <returns>A configured instance of <see cref="EventHubsBuilder" />.</returns>
62+ public EventHubsBuilder WithAcceptLicenseAgreement ( bool acceptLicenseAgreement )
5863 {
59- return Merge ( DockerResourceConfiguration , new EventHubsConfiguration ( azuriteBlobEndpoint : azuriteBlobEndpoint ) )
60- . WithEnvironment ( "BLOB_SERVER" , azuriteBlobEndpoint ) ;
64+ var licenseAgreement = acceptLicenseAgreement ? AcceptLicenseAgreement : DeclineLicenseAgreement ;
65+ return WithEnvironment ( AcceptLicenseAgreementEnvVar , licenseAgreement ) ;
6166 }
6267
6368 /// <summary>
64- /// Sets the endpoint of the azurite table service
69+ /// Sets the Azurite container for the Event Hubs Emulator.
6570 /// </summary>
66- /// <param name="azuriteTableEndpoint"></param>
71+ /// <param name="azuriteContainer">docker container</param>
72+ /// <param name="blobEndpoint">blob endpoint</param>
73+ /// <param name="tableEndpoint">table endpoint</param>
6774 /// <returns></returns>
68- public EventHubsBuilder WithAzuriteTableEndpoint ( string azuriteTableEndpoint )
75+ public EventHubsBuilder WithAzurite ( AzuriteContainer azuriteContainer , string blobEndpoint , string tableEndpoint )
6976 {
70- return Merge ( DockerResourceConfiguration , new EventHubsConfiguration ( azuriteTableEndpoint : azuriteTableEndpoint ) )
71- . WithEnvironment ( "METADATA_SERVER" , azuriteTableEndpoint ) ;
77+ return Merge ( DockerResourceConfiguration , new EventHubsConfiguration ( azuriteContainer : azuriteContainer ) )
78+ . DependsOn ( azuriteContainer )
79+ . WithEnvironment ( "BLOB_SERVER" , blobEndpoint )
80+ . WithEnvironment ( "METADATA_SERVER" , tableEndpoint ) ;
7281 }
7382
7483 /// <summary>
75- /// Accepts the license agreement .
84+ /// Sets the default Azurite container for the Event Hubs Emulator .
7685 /// </summary>
77- /// <remarks>
78- /// When <paramref name="acceptLicenseAgreement" /> is set to <c>true</c>, the Azure Event Hubs Emulator <see href="https://github.com/Azure/azure-event-hubs-emulator-installer/blob/main/EMULATOR_EULA.md">license</see> is accepted.
79- /// </remarks>
80- /// <param name="acceptLicenseAgreement">A boolean value indicating whether the Azure Event Hubs Emulator license agreement is accepted.</param>
81- /// <returns>A configured instance of <see cref="EventHubsBuilder" />.</returns>
82- public EventHubsBuilder WithAcceptLicenseAgreement ( bool acceptLicenseAgreement )
86+ public EventHubsBuilder WithAzurite ( )
8387 {
84- var licenseAgreement = acceptLicenseAgreement ? AcceptLicenseAgreement : DeclineLicenseAgreement ;
85- return WithEnvironment ( AcceptLicenseAgreementEnvVar , licenseAgreement ) ;
88+ var azuriteContainer = new AzuriteBuilder ( )
89+ . WithNetwork ( DockerResourceConfiguration . Networks . Single ( ) )
90+ . WithNetworkAliases ( AzuriteNetworkAlias )
91+ . Build ( ) ;
92+
93+ return WithAzurite ( azuriteContainer , AzuriteNetworkAlias , AzuriteNetworkAlias ) ;
8694 }
8795
8896 /// <inheritdoc />
@@ -105,31 +113,22 @@ protected override void Validate()
105113 nameof ( DockerResourceConfiguration . ConfigurationBuilder ) )
106114 . NotNull ( )
107115 . ThrowIf ( x => ! x . Value . Validate ( ) , _ => throw new ArgumentException ( "ConfigurationBuilder is invalid." ) ) ;
108-
109- _ = Guard . Argument ( DockerResourceConfiguration . AzuriteBlobEndpoint ,
110- nameof ( DockerResourceConfiguration . AzuriteBlobEndpoint ) )
111- . NotNull ( )
112- . NotEmpty ( ) ;
113116
114- _ = Guard . Argument ( DockerResourceConfiguration . AzuriteTableEndpoint ,
115- nameof ( DockerResourceConfiguration . AzuriteTableEndpoint ) )
116- . NotNull ( )
117- . NotEmpty ( ) ;
118117 return ;
119118
120119 bool LicenseAgreementNotAccepted ( EventHubsConfiguration value ) =>
121120 ! value . Environments . TryGetValue ( AcceptLicenseAgreementEnvVar , out var licenseAgreementValue ) ||
122121 ! AcceptLicenseAgreement . Equals ( licenseAgreementValue , StringComparison . Ordinal ) ;
123122 }
124123
125-
126-
127124 /// <inheritdoc />
128125 protected override EventHubsBuilder Init ( )
129126 {
130127 return base . Init ( )
131128 . WithImage ( EventHubsImage )
129+ . WithNetwork ( new NetworkBuilder ( ) . Build ( ) )
132130 . WithPortBinding ( EventHubsPort , true )
131+ . WithAzurite ( )
133132 . WithWaitStrategy ( Wait . ForUnixContainer ( )
134133 . UntilMessageIsLogged ( "Emulator Service is Successfully Up!" )
135134 . AddCustomWaitStrategy ( new WaitTwoSeconds ( ) ) ) ; ;
0 commit comments