public async Task IncomingMessageHasNoHeaders() { var gotMessage = false; _adapter.Handle <string>(async str => gotMessage = true); var body = BodyWith("hej med dig min ven"); var headersWithoutMessageId = new Dictionary <string, string>(); _network.Deliver("test", new TransportMessage(headersWithoutMessageId, body).ToInMemTransportMessage()); await Task.Delay(1000); PrintLogs(); Assert.That(gotMessage, Is.False, "Did not expect to receive the message"); var loggedErrors = _listLoggerFactory .Where(l => l.Level == LogLevel.Error) .ToList(); Assert.That(loggedErrors.Count, Is.EqualTo(1)); var errorLogLine = loggedErrors.Single(e => e.Level == LogLevel.Error); Assert.That(errorLogLine.Text, Contains.Substring( $"Received message with empty or absent '{Headers.MessageId}' header")); }
public void LogsWarningWhenRouteIsOverwritten() { _router.Map <string>("some_endpoint"); _loggerFactory.Clear(); _router.Map <string>("another_endpoint"); var logLines = _loggerFactory .Where(l => l.Level == LogLevel.Warn) .ToList(); Assert.That(logLines.Count, Is.EqualTo(1)); }
public void DoesNotBarfInTheBackground() { var doneHandlingMessage = new ManualResetEvent(false); _activator.Handle <string>(async str => { for (var count = 0; count < 5; count++) { Console.WriteLine("waiting..."); await Task.Delay(TimeSpan.FromSeconds(20)); } Console.WriteLine("done waiting!"); doneHandlingMessage.Set(); }); _activator.Bus.SendLocal("hej med dig min ven!").Wait(); doneHandlingMessage.WaitOrDie(TimeSpan.FromMinutes(2)); var logLinesAboveInformation = _loggerFactory .Where(l => l.Level >= LogLevel.Warn) .ToList(); Assert.That(!logLinesAboveInformation.Any(), "Expected no warnings - got this: {0}", string.Join(Environment.NewLine, logLinesAboveInformation)); }
public async Task DoesNotFailWhenNoAbortOrCleanupHandlerIsAdded() { _uowActivator.Handle <string>(async str => { }); _uowActivator.Bus.SendLocal("hej med dig min ven!!").Wait(); Thread.Sleep(2000); var logLinesAboveInfo = _loggerFactory.Where(l => l.Level > LogLevel.Info).ToList(); Assert.That(logLinesAboveInfo.Any(), Is.False, "Got the following: {0}", string.Join(Environment.NewLine, logLinesAboveInfo)); }
public void DoesNotLogWarningsUnderNormalUse() { var counter = new SharedCounter(3); _activator.Handle <string>(async str => counter.Decrement()); _activator.Bus.SendLocal("hej").Wait(); _activator.Bus.SendLocal("med").Wait(); _activator.Bus.SendLocal("dig").Wait(); counter.WaitForResetEvent(); CleanUpDisposables(); var logLinesWarnLevelOrAbove = _logs.Where(l => l.Level >= LogLevel.Warn).ToList(); Assert.That(logLinesWarnLevelOrAbove.Any(), Is.False, $@"Got the following log lines >= WARN: {string.Join(Environment.NewLine, logLinesWarnLevelOrAbove)}"); }
public void OutputsSagaDataSnapshotsToLog() { var logger = new ListLoggerFactory(true); RunTheTest(logger); var lines = logger .Where(line => line.Text.Contains("\"CorrelationId\":\"hej\"")) .ToList(); Assert.That(lines.Count, Is.EqualTo(3)); Console.WriteLine($@" Here we have the logged saga data snapshots: {string.Join(Environment.NewLine, lines)} "); }
public async Task CanDeadLetterMessageManuallyWithoutAnyNoise() { var listLoggerFactory = new ListLoggerFactory(outputToConsole: true); var activator = Using(new BuiltinHandlerActivator()); activator.Handle <string>(async(bus, message) => { await bus.Advanced.TransportMessage.Deadletter(errorDetails: "has been manually dead-lettered"); }); var fakeErrorHandler = new FakeErrorHandler(); Configure.With(activator) .Logging(l => l.Use(listLoggerFactory)) .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "manual-deadlettering")) .Options(o => o.Register <IErrorHandler>(c => fakeErrorHandler)) //< provide our own implementation here, so we'll know what gets dead-lettered .Start(); await activator.Bus.SendLocal("HEJ MED DIG MIN VEN"); var poisonMessage = await fakeErrorHandler.GetNextPoisonMessage(timeoutSeconds : 2); Assert.That(poisonMessage.Item1.Headers, Contains.Key(Headers.ErrorDetails).And.ContainValue("has been manually dead-lettered")); Assert.That(poisonMessage.Item1.Headers, Contains.Key(Headers.SourceQueue).And.ContainValue("manual-deadlettering")); Console.WriteLine("Exception passed to error handler:"); Console.WriteLine(poisonMessage.Item2); var linesAboveInfo = listLoggerFactory.Where(log => log.Level > LogLevel.Info).ToList(); if (linesAboveInfo.Any()) { throw new AssertionException($@"Didn't expect NOISE in the log, but the following lines were > INFO: {string.Join(Environment.NewLine, linesAboveInfo)}"); } }