@@ -22,7 +22,9 @@ namespace DotNet.Testcontainers.Builders
2222 /// <typeparam name="TContainerEntity">The resource entity.</typeparam>
2323 /// <typeparam name="TConfigurationEntity">The configuration entity.</typeparam>
2424 [ PublicAPI ]
25- public abstract class ContainerBuilder < TBuilderEntity , TContainerEntity , TConfigurationEntity > : AbstractBuilder < TBuilderEntity , TContainerEntity , CreateContainerParameters , TConfigurationEntity > , IContainerBuilder < TBuilderEntity , TContainerEntity >
25+ public abstract class ContainerBuilder < TBuilderEntity , TContainerEntity , TConfigurationEntity > :
26+ AbstractBuilder < TBuilderEntity , TContainerEntity , CreateContainerParameters , TConfigurationEntity > ,
27+ IContainerBuilder < TBuilderEntity , TContainerEntity >
2628 where TBuilderEntity : ContainerBuilder < TBuilderEntity , TContainerEntity , TConfigurationEntity >
2729 where TContainerEntity : IContainer
2830 where TConfigurationEntity : IContainerConfiguration
@@ -172,7 +174,8 @@ public TBuilderEntity WithPortBinding(int port, bool assignRandomHostPort = fals
172174 /// <inheritdoc />
173175 public TBuilderEntity WithPortBinding ( int hostPort , int containerPort )
174176 {
175- return WithPortBinding ( hostPort . ToString ( CultureInfo . InvariantCulture ) , containerPort . ToString ( CultureInfo . InvariantCulture ) ) ;
177+ return WithPortBinding ( hostPort . ToString ( CultureInfo . InvariantCulture ) ,
178+ containerPort . ToString ( CultureInfo . InvariantCulture ) ) ;
176179 }
177180
178181 /// <inheritdoc />
@@ -201,15 +204,24 @@ public TBuilderEntity WithResourceMapping(IResourceMapping resourceMapping)
201204 }
202205
203206 /// <inheritdoc />
204- public TBuilderEntity WithResourceMapping ( byte [ ] resourceContent , string filePath , UnixFileModes fileMode = Unix . FileMode644 )
207+ public TBuilderEntity WithResourceMapping ( byte [ ] resourceContent , string filePath ,
208+ UnixFileModes fileMode = Unix . FileMode644 )
205209 {
206210 return WithResourceMapping ( new BinaryResourceMapping ( resourceContent , filePath , fileMode ) ) ;
207211 }
208212
213+ /// <inheritdoc />
214+ public TBuilderEntity WithResourceMapping ( byte [ ] resourceContent , FileInfo filePath ,
215+ UnixFileModes fileMode = Unix . FileMode644 )
216+ {
217+ return WithResourceMapping ( new BinaryResourceMapping ( resourceContent , filePath . FullName , fileMode ) ) ;
218+ }
219+
209220 /// <inheritdoc />
210221 public TBuilderEntity WithResourceMapping ( string source , string target , UnixFileModes fileMode = Unix . FileMode644 )
211222 {
212- if ( Uri . IsWellFormedUriString ( source , UriKind . Absolute ) && Uri . TryCreate ( source , UriKind . Absolute , out var uri ) && new [ ] { Uri . UriSchemeHttp , Uri . UriSchemeHttps , Uri . UriSchemeFile } . Contains ( uri . Scheme ) )
223+ if ( Uri . IsWellFormedUriString ( source , UriKind . Absolute ) && Uri . TryCreate ( source , UriKind . Absolute , out var uri ) &&
224+ new [ ] { Uri . UriSchemeHttp , Uri . UriSchemeHttps , Uri . UriSchemeFile } . Contains ( uri . Scheme ) )
213225 {
214226 return WithResourceMapping ( uri , target , fileMode ) ;
215227 }
@@ -227,19 +239,35 @@ public TBuilderEntity WithResourceMapping(string source, string target, UnixFile
227239 }
228240
229241 /// <inheritdoc />
230- public TBuilderEntity WithResourceMapping ( DirectoryInfo source , string target , UnixFileModes fileMode = Unix . FileMode644 )
242+ public TBuilderEntity WithResourceMapping ( DirectoryInfo source , string target ,
243+ UnixFileModes fileMode = Unix . FileMode644 )
231244 {
232245 return WithResourceMapping ( new FileResourceMapping ( source . FullName , target , fileMode ) ) ;
233246 }
234247
248+ /// <inheritdoc />
249+ public TBuilderEntity WithResourceMapping ( DirectoryInfo source , DirectoryInfo target ,
250+ UnixFileModes fileMode = Unix . FileMode644 )
251+ {
252+ return WithResourceMapping ( new FileResourceMapping ( source . FullName , target . FullName , fileMode ) ) ;
253+ }
254+
235255 /// <inheritdoc />
236256 public TBuilderEntity WithResourceMapping ( FileInfo source , string target , UnixFileModes fileMode = Unix . FileMode644 )
237257 {
238258 return WithResourceMapping ( new FileResourceMapping ( source . FullName , target , fileMode ) ) ;
239259 }
240260
241261 /// <inheritdoc />
242- public TBuilderEntity WithResourceMapping ( FileInfo source , FileInfo target , UnixFileModes fileMode = Unix . FileMode644 )
262+ public TBuilderEntity WithResourceMapping ( FileInfo source , DirectoryInfo target ,
263+ UnixFileModes fileMode = Unix . FileMode644 )
264+ {
265+ return WithResourceMapping ( new FileResourceMapping ( source . FullName , target . FullName , fileMode ) ) ;
266+ }
267+
268+ /// <inheritdoc />
269+ public TBuilderEntity WithResourceMapping ( FileInfo source , FileInfo target ,
270+ UnixFileModes fileMode = Unix . FileMode644 )
243271 {
244272 using ( var fileStream = source . Open ( FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
245273 {
@@ -253,15 +281,31 @@ public TBuilderEntity WithResourceMapping(FileInfo source, FileInfo target, Unix
253281
254282 /// <inheritdoc />
255283 public TBuilderEntity WithResourceMapping ( Uri source , string target , UnixFileModes fileMode = Unix . FileMode644 )
284+ {
285+ return WithResourceMapping ( source , new DirectoryInfo ( target ) , fileMode ) ;
286+ }
287+
288+ /// <inheritdoc />
289+ public TBuilderEntity WithResourceMapping ( Uri source , DirectoryInfo target ,
290+ UnixFileModes fileMode = Unix . FileMode644 )
256291 {
257292 if ( source . IsFile )
258293 {
259- return WithResourceMapping ( new FileResourceMapping ( source . AbsolutePath , target , fileMode ) ) ;
294+ return WithResourceMapping ( new FileResourceMapping ( source . AbsolutePath , target . FullName , fileMode ) ) ;
260295 }
261- else
296+
297+ return WithResourceMapping ( new UriResourceMapping ( source , target . FullName , fileMode ) ) ;
298+ }
299+
300+ /// <inheritdoc />
301+ public TBuilderEntity WithResourceMapping ( Uri source , FileInfo target , UnixFileModes fileMode = Unix . FileMode644 )
302+ {
303+ if ( source . IsFile )
262304 {
263- return WithResourceMapping ( new UriResourceMapping ( source , target , fileMode ) ) ;
305+ return WithResourceMapping ( new FileInfo ( source . AbsolutePath ) , target , fileMode ) ;
264306 }
307+
308+ return WithResourceMapping ( new UriResourceMapping ( source , target . FullName , fileMode ) ) ;
265309 }
266310
267311 /// <inheritdoc />
@@ -380,13 +424,16 @@ public TBuilderEntity WithWaitStrategy(IWaitForContainerOS waitStrategy)
380424 /// <inheritdoc />
381425 public TBuilderEntity WithStartupCallback ( Func < TContainerEntity , CancellationToken , Task > startupCallback )
382426 {
383- return Clone ( new ContainerConfiguration ( startupCallback : ( container , ct ) => startupCallback ( ( TContainerEntity ) container , ct ) ) ) ;
427+ return Clone ( new ContainerConfiguration ( startupCallback : ( container , ct ) =>
428+ startupCallback ( ( TContainerEntity ) container , ct ) ) ) ;
384429 }
385430
386431 /// <inheritdoc />
387432 protected override TBuilderEntity Init ( )
388433 {
389- return base . Init ( ) . WithImagePullPolicy ( PullPolicy . Missing ) . WithPortForwarding ( ) . WithOutputConsumer ( Consume . DoNotConsumeStdoutAndStderr ( ) ) . WithWaitStrategy ( Wait . ForUnixContainer ( ) ) . WithStartupCallback ( ( _ , _ ) => Task . CompletedTask ) ;
434+ return base . Init ( ) . WithImagePullPolicy ( PullPolicy . Missing ) . WithPortForwarding ( )
435+ . WithOutputConsumer ( Consume . DoNotConsumeStdoutAndStderr ( ) ) . WithWaitStrategy ( Wait . ForUnixContainer ( ) )
436+ . WithStartupCallback ( ( _ , _ ) => Task . CompletedTask ) ;
390437 }
391438
392439 /// <inheritdoc />
@@ -396,7 +443,10 @@ protected override void Validate()
396443
397444 const string reuseNotSupported = "Reuse cannot be used in conjunction with WithAutoRemove(true)." ;
398445 _ = Guard . Argument ( DockerResourceConfiguration , nameof ( IContainerConfiguration . Reuse ) )
399- . ThrowIf ( argument => argument . Value . Reuse . HasValue && argument . Value . Reuse . Value && argument . Value . AutoRemove . HasValue && argument . Value . AutoRemove . Value , argument => new ArgumentException ( reuseNotSupported , argument . Name ) ) ;
446+ . ThrowIf (
447+ argument => argument . Value . Reuse . HasValue && argument . Value . Reuse . Value &&
448+ argument . Value . AutoRemove . HasValue && argument . Value . AutoRemove . Value ,
449+ argument => new ArgumentException ( reuseNotSupported , argument . Name ) ) ;
400450
401451 _ = Guard . Argument ( DockerResourceConfiguration . Image , nameof ( IContainerConfiguration . Image ) )
402452 . NotNull ( ) ;
@@ -411,10 +461,13 @@ protected virtual void ValidateLicenseAgreement()
411461 const string message = "The image '{0}' requires you to accept a license agreement." ;
412462
413463 Predicate < TConfigurationEntity > licenseAgreementNotAccepted = value =>
414- ! value . Environments . TryGetValue ( AcceptLicenseAgreementEnvVar , out var licenseAgreementValue ) || ! AcceptLicenseAgreement . Equals ( licenseAgreementValue , StringComparison . Ordinal ) ;
464+ ! value . Environments . TryGetValue ( AcceptLicenseAgreementEnvVar , out var licenseAgreementValue ) ||
465+ ! AcceptLicenseAgreement . Equals ( licenseAgreementValue , StringComparison . Ordinal ) ;
415466
416467 _ = Guard . Argument ( DockerResourceConfiguration , nameof ( DockerResourceConfiguration . Image ) )
417- . ThrowIf ( argument => licenseAgreementNotAccepted ( argument . Value ) , argument => throw new ArgumentException ( string . Format ( message , DockerResourceConfiguration . Image . FullName ) , argument . Name ) ) ;
468+ . ThrowIf ( argument => licenseAgreementNotAccepted ( argument . Value ) ,
469+ argument => throw new ArgumentException ( string . Format ( message , DockerResourceConfiguration . Image . FullName ) ,
470+ argument . Name ) ) ;
418471 }
419472
420473 /// <summary>
@@ -427,7 +480,10 @@ protected virtual void ValidateLicenseAgreement()
427480 private TBuilderEntity WithPortForwarding ( )
428481 {
429482 const string hostname = "host.testcontainers.internal" ;
430- return PortForwardingContainer . Instance != null && TestcontainersStates . Running . Equals ( PortForwardingContainer . Instance . State ) ? WithExtraHost ( hostname , PortForwardingContainer . Instance . IpAddress ) : Clone ( new ContainerConfiguration ( ) ) ;
483+ return PortForwardingContainer . Instance != null &&
484+ TestcontainersStates . Running . Equals ( PortForwardingContainer . Instance . State )
485+ ? WithExtraHost ( hostname , PortForwardingContainer . Instance . IpAddress )
486+ : Clone ( new ContainerConfiguration ( ) ) ;
431487 }
432488
433489 /// <inheritdoc cref="NetworkBuilder" />
0 commit comments