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));
        }
Пример #2
0
        public void TestMessageToEntityComponentFirstOfType()
        {
            var mockMessage = new Mock <IMessageToEntityComponentFirstOfType>();
            var mockComponentActorFactory = new Mock <IComponentActorFactory>();

            mockComponentActorFactory.Setup(f => f.GetOrCreateActorForComponent(It.IsAny <EntityComponent>())).Returns(
                (EntityComponent component) =>
            {
                return(Sys.ActorOf(Props.Create(() => new EntityTestActor(component.Id)), $"{component.Id}"));
            }
                );

            var testComponent = new Utils.TestComponent();
            var entity        = new Entity
            {
                testComponent,
                new Utils.TestComponent()
            };

            mockMessage.Setup(m => m.EntityId).Returns(entity.Id);
            mockMessage.Setup(m => m.ComponentType).Returns(typeof(Utils.TestComponent));
            mockMessage.Setup(m => m.Message).Returns("Test");

            IActorRef entityActor = Sys.ActorOf(EntityActor.Props(entity, mockComponentActorFactory.Object));

            entityActor.Tell(mockMessage.Object);
            ExpectMsg(testComponent.Id);

            entity.RemoveAll <EntityComponent>();
            entity.Dispose();

            entity = new Entity
            {
                new Utils.TestComponent(),
                testComponent
            };

            entityActor = Sys.ActorOf(EntityActor.Props(entity, mockComponentActorFactory.Object));
            entityActor.Tell(mockMessage.Object);
            ExpectMsg <Guid>(guid => guid != testComponent.Id);
        }