Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Redbus/Redbus.Tests/EventBusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ public void PublishDontThrowSubscriberExceptionTest()
Assert.IsTrue(thirdSubscriberHit); // Third subscriber will be hit, because we didn't throw.
}

[TestMethod]
public void PublishCustomEventAsSubtype()
{
var eventBus = new EventBus();
bool subscriberHit = false;
eventBus.Subscribe<CustomTestEvent>(s => { subscriberHit = true; });

eventBus.Publish((EventBase)(new CustomTestEvent()));

Assert.IsTrue(subscriberHit);
}

private void CustomTestEventMethodHandler(CustomTestEvent customTestEvent)
{
Assert.AreEqual("Custom Event", customTestEvent.Name);
Expand Down
4 changes: 2 additions & 2 deletions src/Redbus/Redbus/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void Publish<TEventBase>(TEventBase eventItem) where TEventBase : EventBa
var allSubscriptions = new List<ISubscription>();
lock (SubscriptionsLock)
{
if (_subscriptions.ContainsKey(typeof(TEventBase)))
allSubscriptions = _subscriptions[typeof(TEventBase)].ToList();
if (_subscriptions.ContainsKey(eventItem.GetType()))
allSubscriptions = _subscriptions[eventItem.GetType()].ToList();
}

for (var index = 0; index < allSubscriptions.Count; index++)
Expand Down