Exemple #1
0
        public void ThrowsWhenTargetAlreadyHasComponent()
        {
            _originalEntity.AddComponentA();
            _originalEntity.AddComponent(MyTestComponentsLookup.ComponentB, _nameAge);
            var component = new NameAgeComponent();

            _targetEntity.AddComponent(MyTestComponentsLookup.ComponentB, component);

            Assert.Throws <EntityAlreadyHasComponentException>(() => _originalEntity.CopyTo(_targetEntity));
        }
Exemple #2
0
        public void ValidateToStringA()
        {
            _defaultEntity.AddComponentA();
            _defaultEntity.AddComponentB();
            _defaultEntity.AddComponent(0, new StandardComponent());
            _defaultEntity.Retain(this);

            Assert.AreEqual(
                "Entity_0(EntitasRedux.Tests.StandardComponent, EntitasRedux.Tests.ComponentA, EntitasRedux.Tests.ComponentB)",
                _defaultEntity.ToString());
        }
        public void ThrowsWhenTargetAlreadyHasComponent()
        {
            _entity.AddComponentA();
            _entity.AddComponent(CID.ComponentB, _nameAge);
            var component = new NameAgeComponent();

            _target.AddComponent(CID.ComponentB, component);

#pragma warning disable CS0618  // Type or member is obsolete
#pragma warning disable HAA0101 // Array allocation for params parameter
            Assert.Throws <EntityAlreadyHasComponentException>(() => _entity.CopyTo(_target));
#pragma warning restore HAA0101 // Array allocation for params parameter
#pragma warning restore CS0618  // Type or member is obsolete
        }
Exemple #4
0
        public void CopiesOfAllComponentsAddedToTargetEntity()
        {
            _originalEntity.AddComponentA();
            _originalEntity.AddComponent(MyTestComponentsLookup.NameAge, _nameAge);
            _originalEntity.CopyTo(_targetEntity);

            Assert.AreEqual(2, _targetEntity.GetComponents().Length);
            Assert.IsTrue(_targetEntity.HasComponentA());
            Assert.IsTrue(_targetEntity.HasNameAge);
            Assert.AreNotEqual(Component.A, _targetEntity.GetComponentA());
            Assert.AreNotEqual(_nameAge, _targetEntity.NameAge);

            var clonedComponent = (NameAgeComponent)_targetEntity.GetComponent(MyTestComponentsLookup.NameAge);

            Assert.AreEqual(_nameAge.name, clonedComponent.name);
            Assert.AreEqual(_nameAge.age, clonedComponent.age);
        }
        public void PrimaryEntityIndexThrowsWhenAddingEntityForTheSameKey()
        {
            SetupActivatedPrimaryEntityIndex();

            var nameAgeComponent = new NameAgeComponent();

            nameAgeComponent.name = NAME;
            _entity = _context.CreateEntity();

            Assert.Throws <EntityIndexException>(() => _entity.AddComponent(CID.ComponentA, nameAgeComponent));
        }
        public void ReactivatedPrimaryEntityIndexAddsNewEntities()
        {
            SetupReactivatedPrimaryEntityIndex();

            var nameAgeComponent = new NameAgeComponent();

            nameAgeComponent.name = "Jack";
            _entity = _context.CreateEntity();
            _entity.AddComponent(CID.ComponentA, nameAgeComponent);

            Assert.AreEqual(_entity, _primaryIndex.GetEntity("Jack"));
        }
        public void CopiesOfAllComponentsAddedToTargetEntity()
        {
            _entity.AddComponentA();
            _entity.AddComponent(CID.ComponentB, _nameAge);

#pragma warning disable CS0618  // Type or member is obsolete
#pragma warning disable HAA0101 // Array allocation for params parameter
            _entity.CopyTo(_target);
#pragma warning restore HAA0101 // Array allocation for params parameter
#pragma warning restore CS0618  // Type or member is obsolete

            Assert.AreEqual(2, _target.GetComponents().Length);
            Assert.IsTrue(_target.HasComponentA());
            Assert.IsTrue(_target.HasComponentB());
            Assert.AreNotEqual(Component.A, _target.GetComponentA());
            Assert.AreNotEqual(_nameAge, _target.GetComponent(CID.ComponentB));

            var clonedComponent = (NameAgeComponent)_target.GetComponent(CID.ComponentB);

            Assert.AreEqual(_nameAge.name, clonedComponent.name);
            Assert.AreEqual(_nameAge.age, clonedComponent.age);
        }
        public void SetupMultipleKeyPrimaryEntityIndex()
        {
            _context      = new MyTestContext();
            _group        = _context.GetGroup(Matcher <MyTestEntity> .AllOf(CID.ComponentA));
            _primaryIndex = new PrimaryEntityIndex <MyTestEntity, string>("TestIndex", _group, (e, c) =>
            {
                return(c is NameAgeComponent nameAge
                                        ? new[] { nameAge.name + "1", nameAge.name + "2" }
                                        : new[] { ((NameAgeComponent)e.GetComponent(CID.ComponentA)).name + "1", ((NameAgeComponent)e.GetComponent(CID.ComponentA)).name + "2" });
            });

            var nameAgeComponent = new NameAgeComponent();

            nameAgeComponent.name = NAME;
            _entity = _context.CreateEntity();
            _entity.AddComponent(CID.ComponentA, nameAgeComponent);
        }
        public void SetupActivatedSingleKeyEntityIndex()
        {
            _context = new MyTestContext();
            _group   = _context.GetGroup(Matcher <MyTestEntity> .AllOf(CID.ComponentA));
            _index   = new EntityIndex <MyTestEntity, string>("TestIndex", _group, (e, c) =>
            {
                return(c is NameAgeComponent nameAge
                                        ? nameAge.name
                                        : ((NameAgeComponent)e.GetComponent(CID.ComponentA)).name);
            });

            _nameAgeComponent      = new NameAgeComponent();
            _nameAgeComponent.name = NAME;
            _entity1 = _context.CreateEntity();
            _entity1.AddComponent(CID.ComponentA, _nameAgeComponent);
            _entity2 = _context.CreateEntity();
            _entity2.AddComponent(CID.ComponentA, _nameAgeComponent);
        }
        public void SetupActivatedPrimaryEntityIndex()
        {
            _context      = new MyTestContext();
            _group        = _context.GetGroup(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentA));
            _primaryIndex = new PrimaryEntityIndex <MyTestEntity, string>(
                "TestIndex",
                _group,
                (e, c) =>
            {
                return(c is NameAgeComponent nameAge
                                                ? nameAge.name
                                                : ((NameAgeComponent)e.GetComponent(MyTestComponentsLookup.ComponentA)).name);
            });

            var nameAgeComponent = new NameAgeComponent();

            nameAgeComponent.name = NAME;

            _entity = _context.CreateEntity();
            _entity.AddComponent(MyTestComponentsLookup.ComponentA, nameAgeComponent);
        }