Example #1
0
        public void CanAddComponentsToEntityAndRetrieveThem()
        {
            var component1 = new MockComponent1("comp1", 1);
            var component2 = new MockComponent2("comp2", true);
            var entity     = new Entity().AddComponent(component1).AddComponent(component2);

            Assert.True(entity.HasComponent <MockComponent1>());
            Assert.True(entity.HasComponent <MockComponent2>());
            Assert.Equal(component1, entity.GetComponent <MockComponent1>());
            Assert.Equal(component2, entity.GetComponent <MockComponent2>());
            Assert.True(entity.TryGetComponent <MockComponent1>(out var retrievedComponent1));
            Assert.True(entity.TryGetComponent <MockComponent2>(out var retrievedComponent2));
            Assert.Equal(component1, retrievedComponent1);
            Assert.Equal(component2, retrievedComponent2);
        }
Example #2
0
        public void CanRemoveComponentsFromEntity()
        {
            var component1 = new MockComponent1("comp1", 1);
            var component2 = new MockComponent2("comp2", true);
            var entity     = new Entity().AddComponent(component1).AddComponent(component2).RemoveComponent <MockComponent1>();

            Assert.False(entity.HasComponent <MockComponent1>());
            Assert.ThrowsAny <Exception>(() => entity.GetComponent <MockComponent1>());
            Assert.False(entity.TryGetComponent <MockComponent1>(out var retrievedComponent1));
            Assert.Null(retrievedComponent1);

            Assert.True(entity.HasComponent <MockComponent2>());
            Assert.Equal(component2, entity.GetComponent <MockComponent2>());
            Assert.True(entity.TryGetComponent <MockComponent2>(out var retrievedComponent2));
            Assert.Equal(component2, retrievedComponent2);
        }