public void ComponentHasGameObjectWhenAdded()
        {
            var gameObject = new GameObject();
            var mock       = new MockGameObjectComponent();

            gameObject.AddComponent(mock);
            Assert.AreSame(gameObject, mock.GameObject);
        }
Beispiel #2
0
        public void CanAccessTransformDirectly()
        {
            var gameObject = new GameObject();
            var transform  = gameObject.GetComponent <Transform>();
            var mockGameObjectComponent = new MockGameObjectComponent();

            gameObject.AddComponent(mockGameObjectComponent);
            Assert.IsTrue(mockGameObjectComponent.HasAccessToTransform(transform));
        }
        public void ComponentNoLongerHasGameObjectWhenRemoved()
        {
            var gameObject = new GameObject();
            var mock       = new MockGameObjectComponent();

            gameObject.AddComponent(mock);
            gameObject.RemoveComponent(mock);
            Assert.IsNull(mock.GameObject);
        }
        public void AddComponentMayBeChained()
        {
            var gameObject = new GameObject();
            var mock       = new MockGameObjectComponent();
            var mock2      = new MockGameObjectComponent();

            Assert.AreSame(gameObject.AddComponent(mock)
                           .AddComponent(mock2), gameObject);
        }
        public void CanRemoveComponents()
        {
            var gameObject = new GameObject();
            var mock       = new MockGameObjectComponent();

            gameObject.AddComponent(mock);
            gameObject.RemoveComponent(mock);
            Assert.IsNull(gameObject.GetComponent <MockGameObjectComponent>());
        }
        public void GameComponentMayBeRemovedDuringUpdate()
        {
            var gameObject    = new GameObject();
            var mockComponent = new MockGameObjectComponent();

            gameObject.AddComponent(mockComponent);
            var mockComponent2 = new MockGameObjectComponent();

            mockComponent2.RemoveFromGameObjectDuringUpdate = true;
            gameObject.AddComponent(mockComponent2);
            gameObject.Update(new DummyGameTime());
            // must not throw exception
        }
        public void InvokesUpdateOnGameObjectComponentsWhenUpdateIsInvoked()
        {
            var gameObject    = new GameObject();
            var mockComponent = new MockGameObjectComponent();

            gameObject.AddComponent(mockComponent);
            var mockComponent2 = new MockGameObjectComponent();

            gameObject.AddComponent(mockComponent2);
            gameObject.Update(new DummyGameTime());
            Assert.IsTrue(mockComponent.UpdateWasInvoked);
            Assert.IsTrue(mockComponent2.UpdateWasInvoked);
        }
        public void CanAddGameComponents()
        {
            var gameObject    = new GameObject();
            var mockComponent = new MockGameObjectComponent();

            gameObject.AddComponent(mockComponent);
            Assert.AreSame(gameObject.GetComponent <MockGameObjectComponent>(), mockComponent);
            var mockComponent2 = new MockGameObjectComponent();

            gameObject.AddComponent(mockComponent2);
            var components = gameObject.GetComponents <MockGameObjectComponent>();

            Assert.IsTrue(components.Contains(mockComponent));
            Assert.IsTrue(components.Contains(mockComponent2));
        }