Beispiel #1
0
        public void When_handling_CreateActor_message_Then_a_new_instance_of_the_actor_is_created()
        {
            var mailbox           = A.Fake <Mailbox>();
            var actor             = ActorHelper.CreateActorDirectly <TestActor>();
            var actorInstantiator = A.Fake <ActorInstantiator>();

            //Note: NEVER do this in actual code (returning a premade instance). Always create new instances.
            A.CallTo(() => actorInstantiator.CreateNewActor()).Returns(actor);
            var actorRef = new LocalActorRef(new TestActorSystem(), actorInstantiator, new RootActorPath("test"), mailbox, A.Dummy <InternalActorRef>());

            actorRef.HandleSystemMessage(new SystemMessageEnvelope(actorRef, new CreateActor(), A.Fake <ActorRef>()));

            A.CallTo(() => actorInstantiator.CreateNewActor()).MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #2
0
        public void When_handling_message_Then_it_is_forwarded_to_the_actor_and_sender_is_set()
        {
            var mailbox           = A.Fake <Mailbox>();
            var actor             = ActorHelper.CreateActorDirectly <TestActor>();
            var actorInstantiator = A.Fake <ActorInstantiator>();

            //Note: NEVER do this in actual code (returning a premade instance). Always create new instances.
            A.CallTo(() => actorInstantiator.CreateNewActor()).Returns(actor);
            var actorRef = new LocalActorRef(new TestActorSystem(), actorInstantiator, new RootActorPath("test"), mailbox, A.Dummy <InternalActorRef>());
            var message  = new object();
            var sender   = A.Fake <ActorRef>();

            A.CallTo(() => sender.Name).Returns("SenderActor");

            //Send Create message so that the instance is created
            actorRef.HandleSystemMessage(new SystemMessageEnvelope(actorRef, new CreateActor(), A.Fake <ActorRef>()));


            actorRef.HandleMessage(new Envelope(actorRef, message, sender));

            actor.ReceivedMessages.Should().HaveCount(1);
            actor.ReceivedMessages[0].Item2.Should().BeSameAs(message);
            actor.ReceivedMessages[0].Item1.Name.Should().Be("SenderActor");
        }