コード例 #1
0
        public void should_remove_setup_system_subscriptions_and_dispose_when_removing_corresponding_entity()
        {
            var dummyGroup             = new Group(typeof(TestComponentOne));
            var mockPoolManager        = Substitute.For <IPoolManager>();
            var mockEventSystem        = Substitute.For <IEventSystem>();
            var mockSetupSystemHandler = Substitute.For <ISetupSystemHandler>();
            var fakeSystem             = Substitute.For <ISetupSystem>();

            fakeSystem.TargetGroup.Returns(dummyGroup);

            var entity = new Entity(Guid.NewGuid(), mockEventSystem);

            entity.AddComponent(new TestComponentOne());

            var fakeDisposable = Substitute.For <IDisposable>();

            mockSetupSystemHandler.ProcessEntity(fakeSystem, entity).Returns(new SubscriptionToken(entity, fakeDisposable));

            var systemExecutor = new SystemExecutor(mockPoolManager, mockEventSystem,
                                                    null, null, mockSetupSystemHandler, null, null);

            systemExecutor.AddSystem(fakeSystem);
            systemExecutor.OnEntityAddedToPool(new EntityAddedEvent(entity, null));

            Assert.That(systemExecutor.GetSubscriptionCountForSystem(fakeSystem), Is.EqualTo(1));
            Assert.That(systemExecutor.GetTotalSubscriptions(), Is.EqualTo(1));

            systemExecutor.OnEntityRemovedFromPool(new EntityRemovedEvent(entity, null));

            Assert.That(systemExecutor.GetSubscriptionCountForSystem(fakeSystem), Is.EqualTo(0));
            Assert.That(systemExecutor.GetTotalSubscriptions(), Is.EqualTo(0));
            fakeDisposable.Received().Dispose();
        }