Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Feb 1, 2025
1 parent 8c88939 commit ce7627f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/WireMock.Net.Testcontainers/WireMockConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public WireMockConfiguration(WireMockConfiguration oldValue, WireMockConfigurati
StaticMappingsPath = BuildConfiguration.Combine(oldValue.StaticMappingsPath, newValue.StaticMappingsPath);
WatchStaticMappings = BuildConfiguration.Combine(oldValue.WatchStaticMappings, newValue.WatchStaticMappings);
WatchStaticMappingsInSubdirectories = BuildConfiguration.Combine(oldValue.WatchStaticMappingsInSubdirectories, newValue.WatchStaticMappingsInSubdirectories);
AdditionalUrls = BuildConfiguration.Combine(oldValue.AdditionalUrls.AsEnumerable(), newValue.AdditionalUrls.AsEnumerable()).ToList();
ProtoDefinitions = BuildConfiguration.Combine(oldValue.ProtoDefinitions, newValue.ProtoDefinitions);
AdditionalUrls = Combine(oldValue.AdditionalUrls, newValue.AdditionalUrls);
ProtoDefinitions = Combine(oldValue.ProtoDefinitions, newValue.ProtoDefinitions);
}

/// <summary>
Expand Down Expand Up @@ -130,4 +130,16 @@ public WireMockConfiguration AddProtoDefinition(string id, params string[] proto

return this;
}

private static List<T> Combine<T>(List<T> oldValue, List<T> newValue)
{
return oldValue.Concat(newValue).ToList();
}

private static Dictionary<TKey, TValue> Combine<TKey, TValue>(Dictionary<TKey, TValue> oldValue, Dictionary<TKey, TValue> newValue)
{
return newValue
.Concat(oldValue.Where(item => !newValue.Keys.Contains(item.Key)))
.ToDictionary(item => item.Key, item => item.Value);
}
}
9 changes: 7 additions & 2 deletions src/WireMock.Net.Testcontainers/WireMockContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ private async Task WireMockContainerStartedAsync(object sender, EventArgs e)
{
_adminApi = CreateWireMockAdminClient();

RegisterEnhancedFileSystemWatcher();

await CallAdditionalActionsAfterStartedAsync();
}

private void RegisterEnhancedFileSystemWatcher()
{
if (!_configuration.WatchStaticMappings || string.IsNullOrEmpty(_configuration.StaticMappingsPath))
{
return;
Expand All @@ -211,8 +218,6 @@ private async Task WireMockContainerStartedAsync(object sender, EventArgs e)
_enhancedFileSystemWatcher.Changed += FileCreatedChangedOrDeleted;
_enhancedFileSystemWatcher.Deleted += FileCreatedChangedOrDeleted;
_enhancedFileSystemWatcher.EnableRaisingEvents = true;

await CallAdditionalActionsAfterStartedAsync();
}

private async Task CallAdditionalActionsAfterStartedAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"Response": {
"BodyAsJson": {
"message": "hello {{request.BodyAsJson.name}}"
"message": "hello {{request.BodyAsJson.name}} {{request.method}}"
},
"UseTransformer": true,
"TransformerType": "Handlebars",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"Response": {
"BodyAsJson": {
"message": "hello {{request.BodyAsJson.name}}"
"message": "hello {{request.BodyAsJson.name}} {{request.method}}"
},
"UseTransformer": true,
"TransformerType": "Handlebars",
Expand Down

0 comments on commit ce7627f

Please sign in to comment.