public void ShouldForwardUnhandledMessagesToDeadLetterProcessing() { var deadLetters = new ConcurrentBag <object>(); Action <object> deadLetterMethod = msg => { deadLetters.Add(msg); }; _transport = new InMemoryMessageTransport(deadLetterMethod); var sendMessage = _transport.CreateSenderMethod(_source.Token) .WithOutboundMessageHandler(msg => { // Ignore the responses send to the outbox; we only care about the // messages sent to the dead letter queue }); var nonexistentActorId = Guid.NewGuid(); var unhandledMessage = "Hello, World"; sendMessage(new TargetedMessage(nonexistentActorId, unhandledMessage)); Thread.Sleep(500); Assert.True(deadLetters.Count(msg => msg is TargetedMessage) == 1); var targetedMessage = (TargetedMessage)deadLetters.First(); var actualMessage = targetedMessage.Message; Assert.Equal(nonexistentActorId, targetedMessage.TargetActorId); Assert.Equal(targetedMessage.Message, actualMessage); }
public void ShouldForwardNonTargetedMessagesToDeadLetterProcessing() { var deadLetters = new ConcurrentBag <object>(); Action <object> deadLetterMethod = msg => { deadLetters.Add(msg); }; _transport = new InMemoryMessageTransport(deadLetterMethod); var sendMessage = _transport.CreateSenderMethod(_source.Token) .WithOutboundMessageHandler(msg => { // Ignore the responses send to the outbox; we only care about the // messages sent to the dead letter queue }); var unhandledMessage = "Hello, World!"; sendMessage(unhandledMessage); Thread.Sleep(500); Assert.True(deadLetters.Count(msg => msg is string) == 1); var actualMessage = deadLetters.Cast <string>().First(); Assert.Equal(unhandledMessage, actualMessage); }
public void Dispose() { _transport = null; _source?.Cancel(); _source = null; }
public MessageTransportTests() { _transport = new InMemoryMessageTransport(); _source = new CancellationTokenSource(); }