mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 07:51:41 +02:00
Add ProtoDefinition to WireMockContainer (#1250)
* AddProtoDefinitionAsync * ... * Body * " * . * . * . * [Fact(Skip = "new docker is needed")] * x
This commit is contained in:
@@ -12,6 +12,7 @@ using DotNet.Testcontainers.Containers;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RestEase;
|
||||
using Stef.Validation;
|
||||
using WireMock.Client;
|
||||
using WireMock.Client.Extensions;
|
||||
using WireMock.Http;
|
||||
@@ -40,9 +41,9 @@ public sealed class WireMockContainer : DockerContainer
|
||||
/// <param name="configuration">The container configuration.</param>
|
||||
public WireMockContainer(WireMockConfiguration configuration) : base(configuration)
|
||||
{
|
||||
_configuration = Stef.Validation.Guard.NotNull(configuration);
|
||||
_configuration = Guard.NotNull(configuration);
|
||||
|
||||
Started += WireMockContainer_Started;
|
||||
Started += async (sender, eventArgs) => await WireMockContainerStartedAsync(sender, eventArgs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -175,8 +176,6 @@ public sealed class WireMockContainer : DockerContainer
|
||||
_enhancedFileSystemWatcher = null;
|
||||
}
|
||||
|
||||
Started -= WireMockContainer_Started;
|
||||
|
||||
return base.DisposeAsyncCore();
|
||||
}
|
||||
|
||||
@@ -195,10 +194,17 @@ public sealed class WireMockContainer : DockerContainer
|
||||
}
|
||||
}
|
||||
|
||||
private void WireMockContainer_Started(object sender, EventArgs e)
|
||||
private async Task WireMockContainerStartedAsync(object sender, EventArgs e)
|
||||
{
|
||||
_adminApi = CreateWireMockAdminClient();
|
||||
|
||||
RegisterEnhancedFileSystemWatcher();
|
||||
|
||||
await CallAdditionalActionsAfterStartedAsync();
|
||||
}
|
||||
|
||||
private void RegisterEnhancedFileSystemWatcher()
|
||||
{
|
||||
if (!_configuration.WatchStaticMappings || string.IsNullOrEmpty(_configuration.StaticMappingsPath))
|
||||
{
|
||||
return;
|
||||
@@ -214,6 +220,25 @@ public sealed class WireMockContainer : DockerContainer
|
||||
_enhancedFileSystemWatcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
private async Task CallAdditionalActionsAfterStartedAsync()
|
||||
{
|
||||
foreach (var kvp in _configuration.ProtoDefinitions)
|
||||
{
|
||||
Logger.LogInformation("Adding ProtoDefinition {Id}", kvp.Key);
|
||||
foreach (var protoDefinition in kvp.Value)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _adminApi!.AddProtoDefinitionAsync(kvp.Key, protoDefinition);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Error adding ProtoDefinition '{Id}'.", kvp.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void FileCreatedChangedOrDeleted(object sender, FileSystemEventArgs args)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user