public void ExecuteAndTraceConsumerAction_EnterAndExitLogged(bool mustFail) { var consumer = _serviceProvider.GetRequiredService <TestBroker>() .AddConsumer(TestConsumerEndpoint.GetDefault()); var expectedEnterMessage = $"Enter A 42 True | consumerId: {consumer.Id}, endpointName: test"; var expectedExitMessage = $"Exit A 42 True | consumerId: {consumer.Id}, endpointName: test"; var executed = false; Action act = () => _silverbackLogger.ExecuteAndTraceConsumerAction( consumer, () => { _loggerSubstitute.Received(LogLevel.Trace, null, expectedEnterMessage, 1999); executed = true; if (mustFail) { throw new InvalidCastException(); } }, "Enter {string} {int} {bool}", "Exit {string} {int} {bool}", () => new object[] { "A", 42, true }); if (mustFail) { act.Should().Throw <InvalidCastException>(); } else { act.Should().NotThrow(); } _loggerSubstitute.Received( LogLevel.Trace, mustFail ? typeof(InvalidCastException) : null, expectedExitMessage, 1999); executed.Should().BeTrue(); }