From f5b72703c2a7f1da544102dff95f36e9ebc941f7 Mon Sep 17 00:00:00 2001 From: Antony Male Date: Sat, 20 Jun 2020 12:05:15 +0100 Subject: [PATCH] Fix bug in EventAggregator Publishing to multiple channels would only deliver messages to subscribers subcribed to all of those channels, not any of them. Fixes #127 --- Stylet/EventAggregator.cs | 2 +- StyletUnitTests/EventAggregatorTests.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Stylet/EventAggregator.cs b/Stylet/EventAggregator.cs index 893abaa..c9aac79 100644 --- a/Stylet/EventAggregator.cs +++ b/Stylet/EventAggregator.cs @@ -183,7 +183,7 @@ namespace Stylet channels = DefaultChannelArray; // We're not subscribed to any of the channels - if (!channels.All(x => this.channels.Contains(x))) + if (!channels.Any(x => this.channels.Contains(x))) return Enumerable.Empty(); return this.invokers.Where(x => x.CanInvoke(messageType)); diff --git a/StyletUnitTests/EventAggregatorTests.cs b/StyletUnitTests/EventAggregatorTests.cs index b80f819..fc03478 100644 --- a/StyletUnitTests/EventAggregatorTests.cs +++ b/StyletUnitTests/EventAggregatorTests.cs @@ -254,6 +254,18 @@ namespace StyletUnitTests Assert.AreEqual(1, target.ReceivedMessageCount); } + [Test] + public void MessagePublishedToMultipleChannelsGetsDeliveredToSubscribersOnSingleChannels() + { + var target = new C1(); + this.ea.Subscribe(target, "C1"); + + var message = new M1(); + this.ea.Publish(message, "C1", "C2"); + + Assert.AreEqual(1, target.ReceivedMessageCount); + } + [Test] public void PublishingInsideHandlerDoesNotThrow() {