Ejemplo n.º 1
0
        public void ProcessBehaviorFixedUpdate_ShouldCallOnStartOnce_WhenUpdateExecutedTwice()
        {
            // Arrange
            var behaviorSceneBuilder = new BehaviorSceneBuilder();

            behaviorSceneBuilder.AddBehavior(out var behaviorComponent);
            var scene = behaviorSceneBuilder.Build();

            // Act
            _behaviorSystem.ProcessBehaviorFixedUpdate(scene);
            _behaviorSystem.ProcessBehaviorFixedUpdate(scene);

            // Assert
            behaviorComponent.Received(1).OnStart();
        }
Ejemplo n.º 2
0
        public void ProcessBehaviorFixedUpdate_ShouldSetEntityOnAllBehaviorComponents()
        {
            // Arrange
            var behaviorSceneBuilder = new BehaviorSceneBuilder();
            var entity1 = behaviorSceneBuilder.AddBehavior(out var behavior1OfEntity1);
            var entity2 = behaviorSceneBuilder.AddBehavior(out var behavior1OfEntity2, out var behavior2OfEntity2);
            var scene   = behaviorSceneBuilder.Build();

            // Act
            _behaviorSystem.ProcessBehaviorFixedUpdate(scene);

            // Assert
            Assert.That(behavior1OfEntity1.Entity, Is.EqualTo(entity1));
            Assert.That(behavior1OfEntity2.Entity, Is.EqualTo(entity2));
            Assert.That(behavior2OfEntity2.Entity, Is.EqualTo(entity2));
        }
Ejemplo n.º 3
0
        public void ProcessBehaviorFixedUpdate_ShouldCallOnFixedUpdateOnAllBehaviorComponents()
        {
            // Arrange
            var behaviorSceneBuilder = new BehaviorSceneBuilder();

            behaviorSceneBuilder.AddBehavior(out var behavior1OfEntity1);
            behaviorSceneBuilder.AddBehavior(out var behavior1OfEntity2, out var behavior2OfEntity2);
            var scene = behaviorSceneBuilder.Build();

            // Act
            _behaviorSystem.ProcessBehaviorFixedUpdate(scene);

            // Assert
            behavior1OfEntity1.Received(1).OnFixedUpdate();
            behavior1OfEntity2.Received(1).OnFixedUpdate();
            behavior2OfEntity2.Received(1).OnFixedUpdate();
        }
Ejemplo n.º 4
0
        public void ProcessBehaviorFixedUpdate_ShouldRemoveEntityWithRemoveFromSceneBehavior()
        {
            // Arrange
            var behaviorSceneBuilder = new BehaviorSceneBuilder();
            var scene  = behaviorSceneBuilder.Build();
            var entity = new Entity();

            entity.AddComponent(new RemoveFromSceneBehaviorComponent());

            scene.AddEntity(entity);

            // Act
            _behaviorSystem.ProcessBehaviorFixedUpdate(scene);

            // Assert
            Assert.That(scene.AllEntities, Does.Not.Contain(entity));
        }
Ejemplo n.º 5
0
        public void ProcessBehaviorFixedUpdate_ShouldCallOnStartBeforeOnFixedUpdate()
        {
            // Arrange
            var behaviorSceneBuilder = new BehaviorSceneBuilder();

            behaviorSceneBuilder.AddBehavior(out var behaviorComponent);
            var scene = behaviorSceneBuilder.Build();

            // Act
            _behaviorSystem.ProcessBehaviorFixedUpdate(scene);

            // Assert
            Received.InOrder(() =>
            {
                behaviorComponent.Received(1).OnStart();
                behaviorComponent.Received(1).OnFixedUpdate();
            });
        }
Ejemplo n.º 6
0
        public void ProcessBehaviorUpdate_ShouldAddComponentToEntityInAddComponentBehavior(bool addComponentOnStart, bool addComponentOnUpdate)
        {
            // Arrange
            var behaviorSceneBuilder = new BehaviorSceneBuilder();
            var scene  = behaviorSceneBuilder.Build();
            var entity = new Entity();

            entity.AddComponent(new AddComponentBehaviorComponent
            {
                AddComponentOnStart  = addComponentOnStart,
                AddComponentOnUpdate = addComponentOnUpdate
            });

            scene.AddEntity(entity);

            // Act
            _behaviorSystem.ProcessBehaviorUpdate(scene, _gameTime);

            // Assert
            Assert.That(entity.Components.Count, Is.EqualTo(2));
        }