public void Constructor_ShouldCreateSceneRootViewModelWithNameAndItems()
        {
            // Arrange
            var entity1 = new Entity {
                Name = "Entity 1"
            };
            var entity2 = new Entity {
                Name = "Entity 2"
            };
            var entity3 = new Entity {
                Name = "Entity 3"
            };

            var scene = TestSceneFactory.Create();

            scene.AddEntity(entity1);
            scene.AddEntity(entity2);
            scene.AddEntity(entity3);

            var sceneModel = TestSceneModelFactory.Create(scene);

            // Act
            var sceneRootViewModel = CreateSceneRootViewModel(sceneModel);

            // Assert
            Assert.That(sceneRootViewModel.Name, Is.EqualTo("Scene"));
            Assert.That(sceneRootViewModel.Items, Has.Count.EqualTo(3));

            var sceneOutlineItemViewModel1 = sceneRootViewModel.Items.ElementAt(0);
            var sceneOutlineItemViewModel2 = sceneRootViewModel.Items.ElementAt(1);
            var sceneOutlineItemViewModel3 = sceneRootViewModel.Items.ElementAt(2);

            Assert.That(sceneOutlineItemViewModel1.Name, Is.EqualTo("Entity 1"));
            Assert.That(sceneOutlineItemViewModel2.Name, Is.EqualTo("Entity 2"));
            Assert.That(sceneOutlineItemViewModel3.Name, Is.EqualTo("Entity 3"));
            Assert.That(sceneOutlineItemViewModel1.Items, Has.Count.Zero);
            Assert.That(sceneOutlineItemViewModel2.Items, Has.Count.Zero);
            Assert.That(sceneOutlineItemViewModel3.Items, Has.Count.Zero);
        }
Пример #2
0
        public void OnDocumentSelected_ShouldSendEventWithSceneModel()
        {
            // Arrange
            var scene      = TestSceneFactory.Create();
            var sceneModel = TestSceneModelFactory.Create(scene);

            _sceneLoader.Load(SceneFilePath).Returns(scene);
            _sceneModelFactory.Create(scene).Returns(sceneModel);

            var sceneEditorViewModel = new SceneEditorViewModel(SceneFilePath, _eventBus, _sceneLoader, _sceneModelFactory);

            SelectedSceneModelChangedEvent? @event = null;

            _eventBus.RegisterEventHandler <SelectedSceneModelChangedEvent>(e => @event = e);

            // Act
            sceneEditorViewModel.OnDocumentSelected();

            // Assert
            Assert.That(@event, Is.Not.Null);
            Assert.That(@event !.SceneModel, Is.EqualTo(sceneModel));
        }
Пример #3
0
        public void Update_ShouldExecuteEngineSystemsInCorrectOrder()
        {
            // Arrange
            GameTime.FixedDeltaTime = TimeSpan.FromSeconds(0.1);
            var gameTime = new GameTime(TimeSpan.FromSeconds(0.15));

            _gameTimeProvider.GetGameTime().Returns(gameTime);

            var scene = TestSceneFactory.Create();

            _sceneManager.CurrentScene.Returns(scene);

            var gameLoop = GetGameLoop();

            // Act
            gameLoop.Update();

            // Assert
            Received.InOrder(() =>
            {
                _inputSystem.Received(1).ProcessInput(scene);
                _behaviorSystem.Received(1).ProcessBehaviorFixedUpdate(scene);
                _customSystem1.Received(1).ProcessFixedUpdate(scene);
                _customSystem2.Received(1).ProcessFixedUpdate(scene);
                _customSystem3.Received(1).ProcessFixedUpdate(scene);
                _physicsSystem.Received(1).ProcessPhysics(scene);
                _entityDestructionSystem.Received(1).DestroyEntitiesAfterFixedTimeStep(scene);
                _behaviorSystem.Received(1).ProcessBehaviorUpdate(scene, gameTime);
                _customSystem1.Received(1).ProcessUpdate(scene, gameTime);
                _customSystem2.Received(1).ProcessUpdate(scene, gameTime);
                _customSystem3.Received(1).ProcessUpdate(scene, gameTime);
                _physicsSystem.Received(1).PreparePhysicsDebugInformation();
                _audioSystem.Received(1).ProcessAudio(scene);
                _animationSystem.Received(1).ProcessAnimations(scene, gameTime);
                _renderingSystem.Received(1).RenderScene(scene);
                _entityDestructionSystem.Received(1).DestroyEntitiesAfterFullFrame(scene);
            });
        }
Пример #4
0
        public void Update_ShouldExecuteSceneManagerOnNextFrameBeforeAccessingCurrentScene()
        {
            // Arrange
            GameTime.FixedDeltaTime = TimeSpan.FromSeconds(0.1);
            var gameTime = new GameTime(TimeSpan.FromSeconds(0.15));

            _gameTimeProvider.GetGameTime().Returns(gameTime);

            var sceneBeforeOnNextFrame = TestSceneFactory.Create();
            var sceneAfterOnNextFrame  = TestSceneFactory.Create();

            _sceneManager.CurrentScene.Returns(sceneBeforeOnNextFrame);

            _sceneManager.When(sm => sm.OnNextFrame()).Do(_ => { _sceneManager.CurrentScene.Returns(sceneAfterOnNextFrame); });

            var gameLoop = GetGameLoop();

            // Act
            gameLoop.Update();

            // Assert
            _coreDiagnosticInfoProvider.Received().UpdateDiagnostics(sceneAfterOnNextFrame);
        }
        public void Serialize_and_Deserialize_SceneWithSceneBehavior()
        {
            // Arrange
            var sceneBehaviorName = Guid.NewGuid().ToString();

            var emptyScene = TestSceneFactory.Create();

            _sceneFactory.Create().Returns(emptyScene);

            var sceneBehavior = Substitute.ForPartsOf <SceneBehavior>(emptyScene);

            sceneBehavior.Name.Returns(sceneBehaviorName);

            var sceneBehaviorFactory = Substitute.For <ISceneBehaviorFactory>();

            sceneBehaviorFactory.BehaviorName.Returns(sceneBehaviorName);
            sceneBehaviorFactory.Create(emptyScene).Returns(sceneBehavior);

            _sceneBehaviorFactoryProvider.Get(sceneBehaviorName).Returns(sceneBehaviorFactory);

            // Prepare scene to serialize
            var sceneToSerialize = TestSceneFactory.Create();

            var sceneBehaviorToSerialize = Substitute.ForPartsOf <SceneBehavior>(sceneToSerialize);

            sceneBehaviorToSerialize.Name.Returns(sceneBehaviorName);

            sceneToSerialize.SceneBehavior = sceneBehaviorToSerialize;

            // Act
            var actual = SerializeAndDeserialize(sceneToSerialize);

            // Assert
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.RootEntities, Has.Count.Zero);
            Assert.That(actual.SceneBehavior.Name, Is.EqualTo(sceneBehaviorName));
        }
        public void Serialize_and_Deserialize_SceneWithEntityGraph()
        {
            // Arrange
            var root   = new Entity();
            var child1 = new Entity {
                Parent = root
            };
            var child2 = new Entity {
                Parent = root
            };

            _ = new Entity {
                Parent = root
            };

            child1.AddChild(new Entity());
            child1.AddChild(new Entity());
            child2.AddChild(new Entity());

            var scene = TestSceneFactory.Create();

            scene.AddEntity(root);

            // Act
            var actual = SerializeAndDeserialize(scene);

            // Assert
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.RootEntities, Has.Count.EqualTo(1));

            var actualRoot = actual.RootEntities.Single();

            Assert.That(actualRoot.Children, Has.Count.EqualTo(3));
            Assert.That(actualRoot.Children.ElementAt(0).Children, Has.Count.EqualTo(2));
            Assert.That(actualRoot.Children.ElementAt(1).Children, Has.Count.EqualTo(1));
            Assert.That(actualRoot.Children.ElementAt(2).Children, Has.Count.Zero);
        }
Пример #7
0
        public void OnNextFrame_HandlesLoadSceneOnlyOnce()
        {
            // Arrange
            const string sceneFilePath = "start up scene";

            var scene1 = TestSceneFactory.Create();

            _sceneLoader.Load(sceneFilePath).Returns(scene1);

            _sceneManager.LoadScene(sceneFilePath);
            _sceneManager.OnNextFrame();

            Assume.That(_sceneManager.CurrentScene, Is.EqualTo(scene1));

            var scene2 = TestSceneFactory.Create();

            _sceneLoader.Load(sceneFilePath).Returns(scene2);

            // Act
            _sceneManager.OnNextFrame();

            // Assert
            Assert.That(_sceneManager.CurrentScene, Is.EqualTo(scene1));
        }
Пример #8
0
        public void OnNextFrame_HandlesLatestLoadEmptySceneOnly()
        {
            // Arrange
            const string sceneBehaviorName1 = "Scene Behavior 1";
            const string sceneBehaviorName2 = "Scene Behavior 2";

            var scene = TestSceneFactory.Create();

            SetUpSceneBehavior(sceneBehaviorName1, scene);
            var sceneBehavior2 = SetUpSceneBehavior(sceneBehaviorName2, scene);

            _sceneFactory.Create().Returns(scene);

            _sceneManager.LoadEmptyScene(sceneBehaviorName1);
            _sceneManager.LoadEmptyScene(sceneBehaviorName2);

            // Act
            _sceneManager.OnNextFrame();

            // Assert
            Assert.That(_sceneManager.CurrentScene, Is.EqualTo(scene));
            Assert.That(_sceneManager.CurrentScene?.SceneBehavior, Is.EqualTo(sceneBehavior2));
            _sceneFactory.Received(1).Create();
        }
 public static SceneModel Create(params string[] availableSceneBehaviors) => Create(TestSceneFactory.Create(), availableSceneBehaviors);
 public static SceneModel Create() => Create(TestSceneFactory.Create());