public void TestParentTestMessage() { // When subscribing to ParentTest Event the appropriate handler will be invoked when // child (descendant) message types are published. _bus.Subscribe <ParentTestEvent>(this); var parentTestEvent = new ParentTestEvent(); _bus.Publish(parentTestEvent); AssertEx.IsOrBecomesTrue(() => _testEventCount == 0, msg: $"Expected 0 got {_testEventCount}"); AssertEx.IsOrBecomesTrue(() => _parentTestEventCount == 1, msg: $"Expected 1 got {_parentTestEventCount}"); AssertEx.IsOrBecomesTrue(() => _childTestEventCount == 0, msg: $"Expected 0 got {_childTestEventCount}"); AssertEx.IsOrBecomesTrue(() => _grandChildTestEventCount == 0, msg: $"Expected 0 got {_grandChildTestEventCount}"); _bus.Subscribe <ChildTestEvent>(this); var childTestEvent = new ChildTestEvent(); _bus.Publish(childTestEvent); AssertEx.IsOrBecomesTrue(() => _testEventCount == 0, msg: $"Expected 0 got {_testEventCount}"); AssertEx.IsOrBecomesTrue(() => _parentTestEventCount == 2, msg: $"Expected 2 got {_parentTestEventCount}"); AssertEx.IsOrBecomesTrue(() => _childTestEventCount == 1, msg: $"Expected 1 got {_childTestEventCount}"); AssertEx.IsOrBecomesTrue(() => _grandChildTestEventCount == 0, msg: $"Expected 0 got {_grandChildTestEventCount}"); _bus.Subscribe <GrandChildTestEvent>(this); var grandChildTestEvent = new GrandChildTestEvent(); _bus.Publish(grandChildTestEvent); AssertEx.IsOrBecomesTrue(() => _testEventCount == 0, msg: $"Expected 0 got {_testEventCount}"); AssertEx.IsOrBecomesTrue(() => _parentTestEventCount == 3, msg: $"Expected 3 got {_parentTestEventCount}"); AssertEx.IsOrBecomesTrue(() => _childTestEventCount == 2, msg: $"Expected 2 got {_childTestEventCount}"); AssertEx.IsOrBecomesTrue(() => _grandChildTestEventCount == 1, msg: $"Expected 1 got {_grandChildTestEventCount}"); }
void IHandle <ChildTestEvent> .Handle(ChildTestEvent message) => Interlocked.Increment(ref _childTestEventCount);