Example #1
0
        public void Given_two_messages_in_mailbox_When_scheduled_Then_both_messages_are_processed()
        {
            var receiver  = A.Fake <ActorRef>();
            var sender    = A.Fake <ActorRef>();
            var scheduler = new ManuallySyncronousScheduler();

            var mailbox = new TestableMailbox(scheduler);

            mailbox.SetActor(A.Fake <InternalActorRef>());
            mailbox.Enqueue(new Envelope(receiver, "first message", sender));
            mailbox.Enqueue(new Envelope(receiver, "second message", sender));

            scheduler.ExecuteAll();
            var handledMessages = mailbox.HandledMessages.Select(e => e.Message as string).ToList();

            handledMessages.Count.Should().Be(2);
            handledMessages[0].Should().Be("first message");
            handledMessages[1].Should().Be("second message");
        }
Example #2
0
        public void Given_mailbox_with_messages_When_scheduler_processes_Then_mailbox_calls_actor_with_messages()
        {
            var receiver  = A.Fake <ActorRef>();
            var sender    = A.Fake <ActorRef>();
            var scheduler = new ManuallySyncronousScheduler();

            var mailbox       = new TestableMailbox(scheduler);
            var fakeActor     = A.Fake <InternalActorRef>();
            var actorMessages = new List <Envelope>();

            A.CallTo(() => fakeActor.HandleMessage(A <Envelope> .Ignored)).Invokes(x => actorMessages.Add(x.GetArgument <Envelope>(0)));
            mailbox.SetActor(fakeActor);
            mailbox.Enqueue(new Envelope(receiver, "first message", sender));
            mailbox.Enqueue(new Envelope(receiver, "second message", sender));

            scheduler.ExecuteAll();
            actorMessages.Count.Should().Be(2);
            actorMessages[0].Message.Should().Be("first message");
            actorMessages[1].Message.Should().Be("second message");
        }