Example #1
0
 public EntityActor(Entity entity, IComponentActorFactory componentActorFactory)
 {
     this.entity = entity;
     this.componentActorFactory = componentActorFactory;
     Receive <Update>(msg => HandleUpdate(msg));
     Receive <IMessageToEntityComponentFirstOfType>(msg => HandleMessageToEntityComponent(msg));
     Receive <EnqueueOrder>(msg => orderQueue.Enqueue(msg.Order));
     Receive <Stop>(msg =>
     {
         orderQueue.Clear();
         currentOrder = null;
     }
                    );
     ReceiveAny(msg => Context.Parent.Forward(msg));
 }
        public void TestGetOrCreateType()
        {
            var mockComponentActorFactory = new Mock <ComponentActorFactory <Utils.TestComponent> >(Sys);

            mockComponentActorFactory.Setup(f => f.GetProps(It.IsAny <Utils.TestComponent>())).Returns(Props.Create(() => new FactoryTestActor()));
            var mockComponent = new Mock <EntityComponent>();

            IComponentActorFactory componentActorFactory = mockComponentActorFactory.Object;

            var testComponentCorrect = new Utils.TestComponent();

            IActorRef actorRef = componentActorFactory.GetOrCreateActorForComponent(testComponentCorrect);

            Assert.NotNull(actorRef);
            Assert.Equal(actorRef, componentActorFactory.GetOrCreateActorForComponent(testComponentCorrect));
            Assert.Throws <ArgumentException>(() => componentActorFactory.GetOrCreateActorForComponent(mockComponent.Object));
        }
Example #3
0
 public static Props Props(Entity entity, IComponentActorFactory componentActorFactory)
 {
     return(Akka.Actor.Props.Create(() => new EntityActor(entity, componentActorFactory)));
 }