public void Log_ConfiguredMessageBasedLogLevelMapping_LogLevelChanged() { var logLevelDictionary = new LogLevelDictionary { { CoreEventIds.BackgroundServiceStarting, (exception, originalLogLevel, message) => { if (message.Value == "TestMessage 10") { return(LogLevel.Error); } return(originalLogLevel); } } }; var internalLogger = new LoggerSubstitute <object>(); var logger = new SilverbackLogger <object>(internalLogger, logLevelDictionary); logger.Log( LogLevel.Information, CoreEventIds.BackgroundServiceStarting, new ArgumentException("param"), "TestMessage {Value}", 10); internalLogger.Received(LogLevel.Error, typeof(ArgumentException), "TestMessage 10"); }
public void Log_ConfiguredMessageBasedLogLevelMapping_LogLevelChanged() { var logLevels = new LogLevelDictionary { { CoreLogEvents.DistributedLockAcquired.EventId, (_, originalLogLevel, message) => { if (message.Value == "Acquired lock name (id).") { return(LogLevel.Error); } return(originalLogLevel); } } }; var logger = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information); var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels); var silverbackLogger = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger); silverbackLogger.LogLockAcquired(new DistributedLockSettings("name", "id")); logger.Received(LogLevel.Error, null, "Acquired lock name (id)."); }
public async Task HandleAsync_ExceptionThrown_ExceptionLogged() { var logger = new LoggerSubstitute <FatalExceptionLoggerConsumerBehavior>(); var integrationLogger = new SilverbackIntegrationLogger <FatalExceptionLoggerConsumerBehavior>( logger, new LogTemplates()); var rawEnvelope = new RawInboundEnvelope( new byte[5], null, TestConsumerEndpoint.GetDefault(), TestConsumerEndpoint.GetDefault().Name, new TestOffset()); try { await new FatalExceptionLoggerConsumerBehavior(integrationLogger).HandleAsync( new ConsumerPipelineContext( rawEnvelope, Substitute.For <IConsumer>(), Substitute.For <ISequenceStore>(), Substitute.For <IServiceProvider>()), _ => throw new InvalidCastException()); } catch { // Ignored } logger.Received(LogLevel.Critical, typeof(InvalidCastException)); }
public void Log_ConfiguredConditionalLogLevelMapping_LogLevelNotChanged() { var logLevelDictionary = new LogLevelDictionary { { CoreEventIds.BackgroundServiceStarting, (exception, originalLogLevel, message) => { if (exception is InvalidOperationException) { return(LogLevel.Error); } return(originalLogLevel); } } }; var internalLogger = new LoggerSubstitute <object>(); var logger = new SilverbackLogger <object>(internalLogger, logLevelDictionary); logger.Log( LogLevel.Information, CoreEventIds.BackgroundServiceStarting, new ArgumentException("param"), "Log Message"); internalLogger.Received(LogLevel.Information, typeof(ArgumentException), "Log Message"); }
public void TestDidNotReceive() { var logger = LoggerSubstitute.Create(); var underTest = new UnderTest(logger); logger.DidNotReceiveWithAnyArgs().Log(default, default);
public void Log_ConfiguredConditionalLogLevelMapping_LogLevelNotChanged() { var logLevels = new LogLevelDictionary { { CoreLogEvents.FailedToAcquireDistributedLock.EventId, (exception, originalLogLevel, _) => { if (exception is InvalidCastException) { return(LogLevel.Error); } return(originalLogLevel); } } }; var logger = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Debug); var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels); var silverbackLogger = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger); silverbackLogger.LogFailedToAcquireLock( new DistributedLockSettings("name", "id"), new InvalidOperationException()); logger.Received( LogLevel.Debug, typeof(InvalidOperationException), "Failed to acquire lock name (id)."); }
public CoreLoggerExtensionsTests() { var logLevels = new LogLevelDictionary(); _logger = new LoggerSubstitute <CoreLoggerExtensionsTests>(LogLevel.Trace); var mappedLevelsLogger = new MappedLevelsLogger <CoreLoggerExtensionsTests>(_logger, logLevels); _silverbackLogger = new SilverbackLogger <CoreLoggerExtensionsTests>(mappedLevelsLogger); }
public void Log_EmptyLogLevelMapping_LogLevelNotChanged() { var logLevelDictionary = new LogLevelDictionary(); var internalLogger = new LoggerSubstitute <object>(); var logger = new SilverbackLogger <object>(internalLogger, logLevelDictionary); logger.Log(LogLevel.Information, CoreEventIds.BackgroundServiceStarting, "Log Message"); internalLogger.Received(LogLevel.Information, null, "Log Message"); }
public void Log_EmptyLogLevelMapping_LogLevelNotChanged() { var logLevels = new LogLevelDictionary(); var logger = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information); var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels); var silverbackLogger = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger); silverbackLogger.LogLockAcquired(new DistributedLockSettings("name", "id")); logger.Received(LogLevel.Information, null, "Acquired lock name (id)."); }
public void Log_EventIdNotConfigured_LogLevelNotChanged() { var logLevelDictionary = new LogLevelDictionary { { CoreEventIds.BackgroundServiceStarting, (e, l, m) => LogLevel.Error } }; var internalLogger = new LoggerSubstitute <object>(); var logger = new SilverbackLogger <object>(internalLogger, logLevelDictionary); logger.Log(LogLevel.Information, CoreEventIds.BackgroundServiceLockAcquired, "Log Message"); internalLogger.Received(LogLevel.Information, null, "Log Message"); }
public void Log_ConfiguredLogLevelMapping_LogLevelChanged() { var logLevelDictionary = new LogLevelDictionary { { CoreEventIds.BackgroundServiceStarting, (_, _, _) => LogLevel.Error } }; var internalLogger = new LoggerSubstitute <object>(); var logger = new SilverbackLogger <object>(internalLogger, logLevelDictionary); logger.Log(LogLevel.Information, CoreEventIds.BackgroundServiceStarting, "Log Message"); internalLogger.Received(LogLevel.Error, null, "Log Message"); }
public void TestLogLevelMethodsExclusive() { var logger = LoggerSubstitute.Create(); var underTest = new UnderTest(logger); underTest.LogDebug(); logger.Received().LogDebug("Message"); logger.DidNotReceive().LogTrace(Arg.Any <string>()); logger.DidNotReceive().LogInformation(Arg.Any <string>()); logger.DidNotReceive().LogWarning(Arg.Any <string>()); logger.DidNotReceive().LogError(Arg.Any <string>()); logger.DidNotReceive().LogCritical(Arg.Any <string>()); }
public void Log_EventIdNotConfigured_LogLevelNotChanged() { var logLevels = new LogLevelDictionary { { CoreLogEvents.BackgroundServiceStarting.EventId, (_, _, _) => LogLevel.Error } }; var logger = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information); var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels); var silverbackLogger = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger); silverbackLogger.LogLockAcquired(new DistributedLockSettings("name", "id")); logger.Received(LogLevel.Information, null, "Acquired lock name (id)."); }
public FatalExceptionLoggerConsumerBehaviorTests() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddLoggerSubstitute(LogLevel.Trace) .AddSilverback() .WithConnectionToMessageBroker(options => options.AddBroker <TestBroker>())); _loggerSubstitute = (LoggerSubstitute <FatalExceptionLoggerConsumerBehavior>)serviceProvider .GetRequiredService <ILogger <FatalExceptionLoggerConsumerBehavior> >(); _inboundLogger = serviceProvider .GetRequiredService <IInboundLogger <FatalExceptionLoggerConsumerBehavior> >(); }
public OutboundLoggerTests() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddLoggerSubstitute(LogLevel.Trace) .AddSilverback() .WithConnectionToMessageBroker(options => options.AddKafka())); _loggerSubstitute = (LoggerSubstitute <OutboundLoggerTests>)serviceProvider .GetRequiredService <ILogger <OutboundLoggerTests> >(); _outboundLogger = serviceProvider .GetRequiredService <IOutboundLogger <OutboundLoggerTests> >(); }
public void ShouldLogExceptionIfSslRequiredButCertificateHasNotBeenSet() { var message = new MailMessage(_fromAddress, _toAddress) { Subject = "Subject of email", Body = "Body of the best email ever." }; message.To.Add(_toAddress); message.CC.Add(_toAddress2); Action send = () => SendMessage(message, true); send.ShouldThrow <SmtpException>().WithMessage("Server does not support secure connections."); LoggerSubstitute.Received(1).LogWarning("Stream was closed before QUIT command from server:\nClient has disconnected unexpectedly."); }
public IntegrationLoggerExtensionsTests() { _serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddLoggerSubstitute(LogLevel.Trace) .AddSilverback() .WithConnectionToMessageBroker( options => options .AddBroker <TestBroker>())); _loggerSubstitute = (LoggerSubstitute <IntegrationLoggerExtensionsTests>)_serviceProvider .GetRequiredService <ILogger <IntegrationLoggerExtensionsTests> >(); _silverbackLogger = _serviceProvider .GetRequiredService <ISilverbackLogger <IntegrationLoggerExtensionsTests> >(); }
public ValidatorProducerBehaviorTests() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddLoggerSubstitute(LogLevel.Trace) .AddSilverback() .WithConnectionToMessageBroker( options => options .AddBroker <TestBroker>())); _loggerSubstitute = (LoggerSubstitute <ValidatorProducerBehavior>)serviceProvider .GetRequiredService <ILogger <ValidatorProducerBehavior> >(); _outboundLogger = serviceProvider .GetRequiredService <IOutboundLogger <ValidatorProducerBehavior> >(); }
public ValidatorConsumerBehaviorTests() { var services = new ServiceCollection(); services .AddLoggerSubstitute() .AddSilverback() .WithConnectionToMessageBroker(options => options.AddBroker <TestBroker>()); _serviceProvider = services.BuildServiceProvider(); _loggerSubstitute = (LoggerSubstitute <ValidatorConsumerBehavior>)_serviceProvider .GetRequiredService <ILogger <ValidatorConsumerBehavior> >(); _inboundLogger = _serviceProvider .GetRequiredService <IInboundLogger <ValidatorConsumerBehavior> >(); }
public void IsEnabled_ConfiguredLogLevelMapping_CheckedAccordingToNewLevel() { var logger = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information); var logEvent = CoreLogEvents.AcquiringDistributedLock; logger.IsEnabled(logEvent.Level).Should().BeTrue(); var logLevels = new LogLevelDictionary { { logEvent.EventId, (_, _, _) => LogLevel.Trace } }; var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels); var silverbackLogger = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger); var result = silverbackLogger.IsEnabled(logEvent); result.Should().BeFalse(); }
public SilverbackIntegrationLoggerTests() { _logger = new LoggerSubstitute <SilverbackIntegrationLoggerTests>(); _integrationLogger = new SilverbackIntegrationLogger <SilverbackIntegrationLoggerTests>( _logger, new LogTemplates() .ConfigureAdditionalData <TestConsumerEndpoint>("offset-in") .ConfigureAdditionalData <TestProducerEndpoint>("offset-out")); _singleInboundMessageContext = ConsumerPipelineContextHelper.CreateSubstitute( new InboundEnvelope( new MemoryStream(), new MessageHeaderCollection { new(DefaultMessageHeaders.FailedAttempts, 1), new(DefaultMessageHeaders.MessageType, "Something.Xy"), new(DefaultMessageHeaders.MessageId, "1234") },
public void TestLogLevelMethods() { var logger = LoggerSubstitute.Create(); var underTest = new UnderTest(logger); underTest.LogDebug(); logger.Received().LogDebug("Message"); underTest.LogTrace(); logger.Received().LogTrace("Message"); underTest.LogInformation(); logger.Received().LogInformation("Message"); underTest.LogWarning(); logger.Received().LogWarning("Message"); underTest.LogError(); logger.Received().LogError("Message"); underTest.LogCritical(); logger.Received().LogCritical("Message"); }
public SilverbackIntegrationLoggerTests() { _logger = new LoggerSubstitute <SilverbackIntegrationLoggerTests>(); _integrationLogger = new SilverbackIntegrationLogger <SilverbackIntegrationLoggerTests>( _logger, new LogTemplates() .ConfigureAdditionalData <TestConsumerEndpoint>("offset-in") .ConfigureAdditionalData <TestProducerEndpoint>("offset-out")); _singleInboundMessageContext = ConsumerPipelineContextHelper.CreateSubstitute( new InboundEnvelope( new MemoryStream(), new MessageHeaderCollection { new MessageHeader(DefaultMessageHeaders.FailedAttempts, 1), new MessageHeader(DefaultMessageHeaders.MessageType, "Something.Xy"), new MessageHeader(DefaultMessageHeaders.MessageId, "1234") }, new TestOffset(), new TestConsumerEndpoint("Test"), "TestActual", new Dictionary <string, string> { ["offset-in"] = "9" })); _inboundSequenceContext = ConsumerPipelineContextHelper.CreateSubstitute( new InboundEnvelope( new MemoryStream(), new MessageHeaderCollection { new MessageHeader(DefaultMessageHeaders.FailedAttempts, 1), new MessageHeader(DefaultMessageHeaders.MessageType, "Something.Xy"), new MessageHeader(DefaultMessageHeaders.MessageId, "1234"), new MessageHeader(DefaultMessageHeaders.BatchId, "3"), new MessageHeader(DefaultMessageHeaders.BatchSize, "10") }, new TestOffset(), new TestConsumerEndpoint("Test") { Batch = new BatchSettings { Size = 5 } }, "TestActual", new Dictionary <string, string> { ["offset-in"] = "9" })); var sequence = new BatchSequence("123", _inboundSequenceContext); sequence.AddAsync(_inboundSequenceContext.Envelope, null, false); _inboundSequenceContext.SetSequence(sequence, true); _outboundEnvelope = new RawOutboundEnvelope( new MemoryStream(), new MessageHeaderCollection { new MessageHeader(DefaultMessageHeaders.MessageType, "Something.Xy"), new MessageHeader(DefaultMessageHeaders.MessageId, "1234") }, new TestProducerEndpoint("Test"), null, new Dictionary <string, string> { ["offset-out"] = "9" }); }