public void child_invokes_parent_and_child_handlers_once()
        {
            using (var sub = new TestInheritedMessageSubscriber(Bus))
            {
                var subscription = sub;
                TestQueue.Clear();
                Bus.Publish(new ChildTestDomainEvent(TestCorrelationId, ChildMsgId));

                BusMessages
                .AssertNext <ChildTestDomainEvent>(TestCorrelationId)
                .AssertEmpty();

                Assert.IsOrBecomesTrue(() => subscription.Starving, 3000);

                Assert.IsOrBecomesTrue(() => subscription.TestDomainEventHandleCount == 0,
                                       1000,
                                       $"Expected 0 Test Domain Event Handled, found {subscription.TestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscription.GrandChildTestDomainEventHandleCount) == 0,
                    1000,
                    $"Expected 0 GrandChildTestDomainEvent handled , found {subscription.ChildTestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscription.ChildTestDomainEventHandleCount) == 1,
                    1000,
                    $"Expected 1 ChildTestDomainEvent handled , found {subscription.ChildTestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscription.ParentTestDomainEventHandleCount) == 1,
                    1000,
                    $"Expected 1 Parent Test Domain Event handled, found {subscription.ParentTestDomainEventHandleCount}");
            }
        }
        public void grand_child_invokes_all_handlers_thrice()
        {
            using (var sub = new TestInheritedMessageSubscriber(Bus, false))
            {
                var subscriber = sub;
                TestQueue.Clear();
                Bus.Publish(new GrandChildTestDomainEvent(TestCorrelationId, ChildMsgId));

                BusMessages
                .AssertNext <GrandChildTestDomainEvent>(TestCorrelationId)
                .AssertEmpty();

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.TestDomainEventHandleCount) == 0,
                    2000,
                    $"Expected 0 Test Domain Event Handled, found {subscriber.TestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.GrandChildTestDomainEventHandleCount) == 3,
                    3000,
                    $"Expected 3 GrandChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.ChildTestDomainEventHandleCount) == 3,
                    3000,
                    $"Expected 3 ChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.ParentTestDomainEventHandleCount) == 3,
                    3000,
                    $"Expected 3 Parent Test Domain Event handled, found {subscriber.ParentTestDomainEventHandleCount}");
            }
        }
 protected override void Given()
 {
     //n.b the subscriber subscribes to the following
     // Subscribe<TestDomainEvent>(this);
     //Subscribe<ParentTestDomainEvent>(this);
     //Subscribe<ChildTestDomainEvent>(this);
     //Subscribe<GrandChildTestDomainEvent>(this);
     MessageSubscriber = new TestInheritedMessageSubscriber(Bus, false);
 }
        public void grand_child_invokes_all_handlers_four_times()
        {
            //n.b. the number of duplications matched the number of times we have subscribed to the hierarchy
            //see the next test where we do not subscribe to Message
            // the subscription to Test Event does not matter because it tis outside the heirarchy
            using (var sub = new TestInheritedMessageSubscriber(Bus, false))
            {
                var subscriber = sub;
                subscriber.Subscribe <Message>(subscriber);

                TestQueue.Clear();
                Bus.Publish(new GrandChildTestDomainEvent(TestCorrelationId, ChildMsgId));

                BusMessages
                .AssertNext <GrandChildTestDomainEvent>(TestCorrelationId)
                .AssertEmpty();

                Assert.IsOrBecomesTrue(() => subscriber.Starving, 3000);

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.TestDomainEventHandleCount) == 0,
                    1000,
                    $"Expected 0 Test Domain Event Handled, found {subscriber.TestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.GrandChildTestDomainEventHandleCount) == 4,
                    3000,
                    $"Expected 4 GrandChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.ChildTestDomainEventHandleCount) == 4,
                    3000,
                    $"Expected 4 ChildTestDomainEvent handled , found {subscriber.ChildTestDomainEventHandleCount}");

                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.ParentTestDomainEventHandleCount) == 4,
                    3000,
                    $"Expected 4 Parent Test Domain Event handled, found {subscriber.ParentTestDomainEventHandleCount}");
                Assert.IsOrBecomesTrue(
                    () => Interlocked.Read(ref subscriber.MessageHandleCount) == 4,
                    3000,
                    $"Expected 4 Message Test Domain Event handled, found {subscriber.MessageHandleCount}");
            }
        }
 protected override void Given()
 {
     MessageSubscriber = new TestInheritedMessageSubscriber(Bus);
 }