mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-27 11:51:56 +01:00
public event NotifyCollectionChangedEventHandler LogEntriesChanged (#355)
This commit is contained in:
@@ -19,7 +19,21 @@ namespace WireMock.Server
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
||||||
{
|
{
|
||||||
add => _options.LogEntries.CollectionChanged += value;
|
add
|
||||||
|
{
|
||||||
|
_options.LogEntries.CollectionChanged += (sender, eventRecordArgs) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
value(sender, eventRecordArgs);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
_options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
remove => _options.LogEntries.CollectionChanged -= value;
|
remove => _options.LogEntries.CollectionChanged -= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,48 @@ using System.Net;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Moq;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
|
using WireMock.Logging;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
|
using WireMock.Settings;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests
|
namespace WireMock.Net.Tests
|
||||||
{
|
{
|
||||||
public class ObservableLogEntriesTest
|
public class ObservableLogEntriesTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public async void FluentMockServer_LogEntriesChanged_WithException_Should_LogError()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string path = $"/log_{Guid.NewGuid()}";
|
||||||
|
var loggerMock = new Mock<IWireMockLogger>();
|
||||||
|
loggerMock.Setup(l => l.Error(It.IsAny<string>(), It.IsAny<object[]>()));
|
||||||
|
var settings = new FluentMockServerSettings
|
||||||
|
{
|
||||||
|
Logger = loggerMock.Object
|
||||||
|
};
|
||||||
|
var server = FluentMockServer.Start(settings);
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.WithPath(path)
|
||||||
|
.UsingGet())
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||||
|
|
||||||
|
server.LogEntriesChanged += (sender, args) => throw new Exception();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await new HttpClient().GetAsync($"http://localhost:{server.Ports[0]}{path}");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
loggerMock.Verify(l => l.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void FluentMockServer_LogEntriesChanged()
|
public async void FluentMockServer_LogEntriesChanged()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user