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}");
            }
        }
Example #2
0
        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}");
            }
        }
        public void multiple_message_handle_invocations_are_correct()
        {
            BusMessages
            .AssertNext <TestDomainEvent>(TestCorrelationId)
            .AssertNext <ParentTestDomainEvent>(TestCorrelationId)
            .AssertNext <ChildTestDomainEvent>(TestCorrelationId)
            .AssertNext <GrandChildTestDomainEvent>(TestCorrelationId)
            .AssertEmpty();

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

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

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

            Assert.IsOrBecomesTrue(
                () => Interlocked.Read(ref MessageSubscriber.ParentTestDomainEventHandleCount) == 3,
                1000,
                $"Expected 3 Parent Test Domain Event handled, found {MessageSubscriber.ParentTestDomainEventHandleCount}");
        }
Example #4
0
        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}");
            }
        }