Fix LogEntries: collection was modified exception (#309)

* _options.LogEntries.ToArray()

* .

* update error message
This commit is contained in:
Stef Heyenrath
2019-08-10 16:46:53 +02:00
committed by GitHub
parent 19dd9e113e
commit 65688ee7d3
9 changed files with 44 additions and 12 deletions

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.0.25</VersionPrefix>
<VersionPrefix>1.0.27</VersionPrefix>
</PropertyGroup>
<Choose>

View File

@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --version 1.0.25.0
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --version 1.0.27.0

View File

@@ -80,11 +80,11 @@ namespace WireMock
bool IsAdminInterface { get; }
/// <summary>
/// ResponseToAsync
/// ProvideResponseAsync
/// </summary>
/// <param name="requestMessage">The request message.</param>
/// <returns>The <see cref="ResponseMessage"/>.</returns>
Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage);
Task<ResponseMessage> ProvideResponseAsync(RequestMessage requestMessage);
/// <summary>
/// Gets the RequestMatchResult based on the RequestMessage.

View File

@@ -77,8 +77,8 @@ namespace WireMock
NextState = nextState;
}
/// <inheritdoc cref="IMapping.ResponseToAsync" />
public async Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage)
/// <inheritdoc cref="IMapping.ProvideResponseAsync" />
public async Task<ResponseMessage> ProvideResponseAsync(RequestMessage requestMessage)
{
return await Provider.ProvideResponseAsync(requestMessage, Settings);
}

View File

@@ -118,7 +118,7 @@ namespace WireMock.Owin
await Task.Delay(_options.RequestProcessingDelay.Value);
}
response = await targetMapping.ResponseToAsync(request);
response = await targetMapping.ProvideResponseAsync(request);
if (targetMapping.Scenario != null)
{
@@ -129,7 +129,7 @@ namespace WireMock.Owin
}
catch (Exception ex)
{
_options.Logger.Error("HttpStatusCode set to 500");
_options.Logger.Error($"Providing a Response for Mapping '{result.TargetMapping.Guid}' failed. HttpStatusCode set to 500. Exception: {ex}");
response = ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500);
}
finally

View File

@@ -1,6 +1,3 @@
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
@@ -8,6 +5,9 @@ using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using WireMock.Admin.Mappings;
using WireMock.Admin.Scenarios;
using WireMock.Admin.Settings;

View File

@@ -27,7 +27,7 @@ namespace WireMock.Server
/// Gets the request logs.
/// </summary>
[PublicAPI]
public IEnumerable<LogEntry> LogEntries => new ReadOnlyCollection<LogEntry>(_options.LogEntries);
public IEnumerable<LogEntry> LogEntries => new ReadOnlyCollection<LogEntry>(_options.LogEntries.ToArray());
/// <summary>
/// The search log-entries based on matchers.

View File

@@ -0,0 +1,29 @@
using FastDeepCloner;
using System;
using System.Runtime.Serialization;
namespace WireMock.Util
{
internal static class CloneUtils
{
private static FastDeepClonerSettings settings = new FastDeepCloner.FastDeepClonerSettings()
{
FieldType = FastDeepCloner.FieldType.FieldInfo,
OnCreateInstance = new FastDeepCloner.Extensions.CreateInstance((Type type) =>
{
#if !NETSTANDARD1_3
return FormatterServices.GetUninitializedObject(type);
#else
#endif
})
};
public static T DeepClone<T>(T objectToBeCloned) where T : class
{
//return CloneExtensionsEx.CloneFactory.GetClone(objectToBeCloned);
// Expression.Lambda<Func<object>>(Expression.New(type)).Compile()
return FastDeepCloner.DeepCloner.Clone(objectToBeCloned, settings);
}
}
}

View File

@@ -45,6 +45,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Remove="Util\CloneUtils.cs" />
<Compile Remove="Util\IndexableDictionary.cs" />
<Compile Remove="Util\NamedReaderWriterLocker.cs" />
</ItemGroup>
@@ -64,6 +65,8 @@
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.8" />
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
<!--<PackageReference Include="CloneExtensionsEx" Version="1.0.2" />-->
<!--<PackageReference Include="FastDeepCloner" Version="1.2.5" />-->
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">