@@ -40,6 +40,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
40
40
} ) ;
41
41
42
42
private OSPlatform ? _imageOS ;
43
+ private string ? _staticMappingsPath ;
43
44
44
45
/// <summary>
45
46
/// Initializes a new instance of the <see cref="ContainerBuilder" /> class.
@@ -142,13 +143,9 @@ public WireMockContainerBuilder WithWatchStaticMappings(bool includeSubDirectori
142
143
[ PublicAPI ]
143
144
public WireMockContainerBuilder WithMappings ( string path , bool includeSubDirectories = false )
144
145
{
145
- Guard . NotNullOrEmpty ( path ) ;
146
+ _staticMappingsPath = Guard . NotNullOrEmpty ( path ) ;
146
147
147
- _imageOS ??= _getOSAsLazy . Value . GetAwaiter ( ) . GetResult ( ) ;
148
-
149
- return WithReadStaticMappings ( )
150
- . WithCommand ( $ "--WatchStaticMappingsInSubdirectories { includeSubDirectories } ")
151
- . WithBindMount ( path , _info [ _imageOS . Value ] . MappingsPath ) ;
148
+ return WithReadStaticMappings ( ) . WithCommand ( $ "--WatchStaticMappingsInSubdirectories { includeSubDirectories } ") ;
152
149
}
153
150
154
151
private WireMockContainerBuilder ( WireMockConfiguration dockerResourceConfiguration ) : base ( dockerResourceConfiguration )
@@ -178,11 +175,36 @@ protected override WireMockContainerBuilder Init()
178
175
builder = builder . WithImage ( ) ;
179
176
}
180
177
181
- var waitForContainerOS = _imageOS is null || _imageOS == OSPlatform . Windows ? Wait . ForWindowsContainer ( ) : Wait . ForUnixContainer ( ) ;
182
- return builder
178
+ // In case the _imageOS is not set, determine it from the Image FullName.
179
+ if ( _imageOS == null )
180
+ {
181
+ if ( builder . DockerResourceConfiguration . Image . FullName . IndexOf ( "wiremock.net" , StringComparison . OrdinalIgnoreCase ) < 0 )
182
+ {
183
+ throw new InvalidOperationException ( ) ;
184
+ }
185
+
186
+ if ( builder . DockerResourceConfiguration . Image . FullName . IndexOf ( "windows" , StringComparison . OrdinalIgnoreCase ) >= 0 )
187
+ {
188
+ _imageOS = OSPlatform . Windows ;
189
+ }
190
+ else
191
+ {
192
+ _imageOS = OSPlatform . Linux ;
193
+ }
194
+ }
195
+
196
+ var waitForContainerOS = _imageOS == OSPlatform . Windows ? Wait . ForWindowsContainer ( ) : Wait . ForUnixContainer ( ) ;
197
+ builder
183
198
. WithPortBinding ( WireMockContainer . ContainerPort , true )
184
199
. WithCommand ( $ "--WireMockLogger { DefaultLogger } ")
185
200
. WithWaitStrategy ( waitForContainerOS . UntilMessageIsLogged ( "By Stef Heyenrath" ) ) ;
201
+
202
+ if ( ! string . IsNullOrEmpty ( _staticMappingsPath ) )
203
+ {
204
+ builder = builder . WithBindMount ( _staticMappingsPath , _info [ _imageOS . Value ] . MappingsPath ) ;
205
+ }
206
+
207
+ return builder ;
186
208
}
187
209
188
210
/// <inheritdoc />
0 commit comments