Example #1
0
        public void should_correctly_remove_all_components_for_entity()
        {
            var expectedSize       = 10;
            var fakeEntityId       = 1;
            var otherEntityId      = 2;
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, expectedSize);

            database.Add(0, fakeEntityId, new TestComponentOne());
            database.Add(0, fakeEntityId, new TestComponentTwo());
            database.Add(0, fakeEntityId, new TestComponentThree());
            database.Add(0, otherEntityId, new TestComponentOne());
            database.Add(1, otherEntityId, new TestComponentOne());

            database.RemoveAll(fakeEntityId);
            Assert.False(database.Has(0, fakeEntityId));
            Assert.False(database.Has(1, fakeEntityId));
            Assert.False(database.Has(2, fakeEntityId));

            var allComponents = database.GetAll(fakeEntityId);

            Assert.Empty(allComponents);
        }