Ejemplo n.º 1
0
        public void SelectedSceneModelChangedEvent_ShouldAddItems()
        {
            // Arrange
            var sceneOutlineViewModel = CreateSceneOutlineViewModel();

            var scene = TestSceneFactory.Create();

            scene.AddEntity(new Entity {
                Name = "Entity"
            });
            var sceneModel = TestSceneModelFactory.Create(scene);

            // Act
            _eventBus.SendEvent(new SelectedSceneModelChangedEvent(sceneModel));

            // Assert
            Assert.That(sceneOutlineViewModel.Items, Has.Count.EqualTo(1));
            var sceneRootViewModel = sceneOutlineViewModel.Items.Single();

            Assert.That(sceneRootViewModel.Name, Is.EqualTo("Scene"));
            Assert.That(sceneRootViewModel.Items, Has.Count.EqualTo(1));
            var entityViewModel = sceneRootViewModel.Items.Single();

            Assert.That(entityViewModel.Name, Is.EqualTo("Entity"));
            Assert.That(entityViewModel.Items, Has.Count.Zero);
        }
        public void ContextMenu_AddEntity_ShouldAddEntityInSceneModelAndUpdateViewModelItems()
        {
            // Arrange
            var sceneModel               = TestSceneModelFactory.Create();
            var sceneRootViewModel       = CreateSceneRootViewModel(sceneModel);
            var addEntityContextMenuItem = sceneRootViewModel.ContextMenuItems.Single(i => i.Name == "Add entity");

            // Act
            addEntityContextMenuItem.Command.Execute(null);

            // Assert
            Assert.That(sceneModel.RootEntities, Has.Count.EqualTo(1));
            Assert.That(sceneRootViewModel.Items, Has.Count.EqualTo(1));
        }
        public void AvailableSceneBehaviors_ShouldReturnBehaviorsDefinedBySceneModel()
        {
            // Arrange
            var sceneModel = TestSceneModelFactory.Create("Behavior 1", "Behavior 2", "Behavior 3");

            // Act
            var scenePropertiesEditorViewModel = new ScenePropertiesEditorViewModel(sceneModel);

            // Assert
            Assert.That(scenePropertiesEditorViewModel.AvailableSceneBehaviors, Is.EquivalentTo(new[]
            {
                new SceneBehaviorName("Behavior 1"),
                new SceneBehaviorName("Behavior 2"),
                new SceneBehaviorName("Behavior 3")
            }));
        }
        public void SceneBehavior_ShouldSetSceneModelSceneBehavior_WhenSet()
        {
            // Arrange
            const string oldBehaviorName = "Old scene behavior";
            const string newBehaviorName = "New scene behavior";
            var          sceneModel      = TestSceneModelFactory.Create(oldBehaviorName, newBehaviorName);

            sceneModel.SceneBehavior = sceneModel.AvailableSceneBehaviors.Single(b => b.Value == oldBehaviorName);
            var scenePropertiesEditorViewModel = new ScenePropertiesEditorViewModel(sceneModel);

            // Act
            scenePropertiesEditorViewModel.SceneBehavior = scenePropertiesEditorViewModel.AvailableSceneBehaviors.Single(b => b.Value == newBehaviorName);

            // Assert
            Assert.That(scenePropertiesEditorViewModel.SceneBehavior.Value, Is.EqualTo("New scene behavior"));
            Assert.That(sceneModel.SceneBehavior.Value, Is.EqualTo("New scene behavior"));
        }
        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);
        }
Ejemplo n.º 6
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));
        }
        public void OnSelected_ShouldSendPropertiesSubjectChangedEventWithScenePropertiesEditor()
        {
            // Arrange
            var sceneModel = TestSceneModelFactory.Create("Scene behavior name");

            sceneModel.SceneBehavior = sceneModel.AvailableSceneBehaviors.Single();
            var sceneRootViewModel = CreateSceneRootViewModel(sceneModel);

            PropertiesSubjectChangedEvent? @event = null;

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

            // Act
            sceneRootViewModel.OnSelected();

            // Assert
            Assert.That(@event, Is.Not.Null);
            Assert.That(@event !.ViewModel, Is.Not.Null);
            Assert.That(@event.ViewModel, Is.TypeOf <ScenePropertiesEditorViewModel>());
            var viewModel = (ScenePropertiesEditorViewModel)@event.ViewModel;

            Assert.That(viewModel.SceneBehavior, Is.EqualTo(sceneModel.SceneBehavior));
        }