Ejemplo n.º 1
0
        public void TestChangingSceneGraphForEntity()
        {
            var entity = new MockEntity(0);

            entity.Initialize();

            var root1 = new SceneGraphRoot();
            var root2 = new SceneGraphRoot();

            root1.AddAsync(entity);
            entity.Parent.Should().Be(root1);

            new Action(() => root1.AddAsync(entity)).Should().Throw <NotSupportedException>();

            root1.RemoveAsync(entity);
            entity.Parent.Should().Be(root1, "because RemoveScheduled will only be called in the next update");
            root1.Update(new GameTime());
            entity.Parent.Should().BeNull("because update now removed the entity from the scene");

            root2.AddAsync(entity);
            entity.Parent.Should().Be(root2);

            root1.IsRegistered(entity).Should().BeFalse("because it will only be registered in the update call");
            new Action(() => entity.ChangeParent(root1)).Should().Throw <NotSupportedException>();
            // call update so entity is actually registered with the root2
            root2.Update(new GameTime());

            // only now is the alternative method possible
            entity.ChangeParent(root1);
            entity.Parent.Should().Be(root1);
        }