Esempio n. 1
0
        public void CannotAddDuplicateHandlerToEcosystem()
        {
            var ecosystem = TestEco();
            var handler1  = new MockHandler1();

            ecosystem.AddHandler(handler1);

            Assert.Throws <ArgumentException>(() => ecosystem.AddHandler(handler1));
        }
Esempio n. 2
0
        public void CanAddHandlerToEcosystem()
        {
            var ecosystem = TestEco();
            var handler   = new MockHandler1();

            ecosystem
            .AddHandler(handler)
            .Update();

            Assert.Equal(1, handler.Called);
        }
Esempio n. 3
0
        public void CanAddHandlerToEcosystemWithEntities()
        {
            var ecosystem = CreateEcosystemWithEntities();
            var handler   = new MockHandler1();

            ecosystem
            .AddHandler(handler)
            .Update();

            Assert.Equal(1, handler.Called);
        }
Esempio n. 4
0
        public void CanRemoveHandlerFromEcosystem()
        {
            var ecosystem = TestEco();
            var handler   = new MockHandler1();

            ecosystem
            .AddHandler(handler)
            .RemoveHandler(handler)
            .Update();

            Assert.Equal(0, handler.Called);
        }
Esempio n. 5
0
        public void CanAddMultipleHandlersToEcosystem()
        {
            var ecosystem = TestEco();
            var handler1  = new MockHandler1();
            var handler2  = new MockHandler2();

            ecosystem
            .AddHandlers(handler1, handler2)
            .Update();

            Assert.Equal(1, handler1.Called);
            Assert.Equal(1, handler2.Called);
        }
Esempio n. 6
0
        public void CanAddEntityWithComponentsToEcosystemWithHandlers()
        {
            var ecosystem = TestEco();
            var handler   = new MockHandler1();
            var entity    = new Entity().AddComponent <MockComponent1>();

            ecosystem
            .AddHandler(handler)
            .AddEntity(NAME, entity)
            .Update();

            Assert.Equal(1, handler.Called);
            Assert.Equal(entity, handler.EntitiesHandled.Single());
        }
Esempio n. 7
0
        public void CanAddEntityToEcosystemWithHandlers()
        {
            var ecosystem = TestEco();
            var handler   = new MockHandler1();
            var entity    = new Entity();

            ecosystem
            .AddHandler(handler)
            .AddEntity(NAME, entity)
            .Update();

            Assert.Equal(1, handler.Called);
            Assert.Empty(handler.EntitiesHandled);
        }
Esempio n. 8
0
        public void CanClearHandlersFromEcosystemWithEntities()
        {
            var ecosystem = CreateEcosystemWithEntities();
            var handler1  = new MockHandler1();
            var handler2  = new MockHandler2();

            ecosystem
            .AddHandlers(handler1, handler2)
            .ClearHandlers()
            .Update();

            Assert.Equal(0, handler1.Called);
            Assert.Equal(0, handler2.Called);
        }
Esempio n. 9
0
        public void CanRemoveEntityWithComponentsFromEcosystemWithHandlers()
        {
            var ecosystem = TestEco();
            var handler   = new MockHandler1();
            var entity    = new Entity().AddComponent <MockComponent1>();

            ecosystem
            .AddHandler(handler)
            .AddEntity(NAME, entity)
            .RemoveEntity(NAME)
            .Update();

            Assert.Equal(1, handler.Called);
            Assert.Empty(handler.EntitiesHandled);
        }
Esempio n. 10
0
        public void CanRemoveComponentFromEntityInEcosystemWithHandlers()
        {
            var ecosystem = TestEco();
            var handler   = new MockHandler1();
            var entity    = new Entity();

            ecosystem
            .AddHandler(handler)
            .AddEntity(NAME, entity);
            entity.AddComponent <MockComponent1>();
            ecosystem.Update();

            entity.RemoveComponent <MockComponent1>();
            ecosystem.Update();

            Assert.Equal(2, handler.Called);
            Assert.Empty(handler.EntitiesHandled); // No entities handled on most recent update
        }