Exemplo n.º 1
0
        public void FindComponent_using_InstanceID_Recurse()
        {
            // Create a new Entity
            IEntity e = new GameObject();
            bool    addEntityResult = m_root.AddEntity(e);

            Assert.IsTrue(addEntityResult);

            // Create a new Component
            IComponent c = new FakeComponent();
            bool       addComponentResult = e.AddComponent(c);

            Assert.IsTrue(addComponentResult);

            // Find the Component from Root using the Component InstanceID
            IComponent f = m_component.FindComponentFromChildren(c.InstanceID);

            // Assert
            Assert.IsNotNull(f);
            Assert.AreSame(f, c);
            Assert.AreSame(f.Parent, c.Parent);
            Assert.AreSame(e, c.Parent);
            Assert.AreSame(e.Parent, m_component.Parent);
            Assert.AreEqual(f.InstanceID, c.InstanceID);
        }
Exemplo n.º 2
0
        public void Setup()
        {
            List <Component> fakeEmptyList = new List <Component>();

            FakeComponent.Setup(method => method.GetContents())
            .Returns(fakeEmptyList);
        }
Exemplo n.º 3
0
        public void RootTest_3()
        {
            IEntity e1 = new GameObject();

            m_component.AddEntity(e1);

            IComponent c1 = new FakeComponent();

            e1.AddComponent(c1);

            IEntity e2 = new GameObject();

            c1.AddEntity(e2);

            IComponent c2 = new FakeComponent();

            e2.AddComponent(c2);

            IEntity e3 = new GameObject();

            c2.AddEntity(e3);

            Assert.AreSame(m_root, e1.Root);
            Assert.AreSame(m_root, c1.Parent.Root);
            Assert.AreSame(m_root, e2.Root);
            Assert.AreSame(m_root, c2.Parent.Root);
            Assert.AreSame(m_root, e3.Root);
        }
Exemplo n.º 4
0
        public void AddSameComponentTwice()
        {
            IComponent c = new FakeComponent();

            bool result1 = m_root.AddComponent(c);
            bool result2 = m_root.AddComponent(c);

            Assert.IsTrue(result1);
            Assert.IsFalse(result2);
        }
Exemplo n.º 5
0
        public void AddComponentTest()
        {
            IComponent c      = new FakeComponent();
            bool       result = m_root.AddComponent(c);

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.Parent);
            Assert.AreSame(c.Parent, m_root);
            Assert.IsTrue(result);
        }
Exemplo n.º 6
0
        public void GameObject_AddComponent_HasComponent()
        {
            var component = new FakeComponent();

            _obj.Add(component);

            var result = _obj.Get <FakeComponent>();

            Assert.AreEqual(component, result.Value);
        }
Exemplo n.º 7
0
        public void RemoveComponent_using_InstanceID()
        {
            IComponent c = new FakeComponent();

            m_root.AddComponent(c);

            IComponent r = m_root.RemoveComponent(c.InstanceID);
            IComponent f = m_root.FindComponent(r.InstanceID);

            Assert.IsNotNull(c);
            Assert.IsNotNull(r);
            Assert.AreSame(r, c);
            Assert.IsNull(f);
        }
Exemplo n.º 8
0
        public void FindComponent_using_InstanceID_NoRecurse()
        {
            // Create a new Component
            IComponent c = new FakeComponent();

            m_root.AddComponent(c);

            // Find the Component using the Component itself
            IComponent f = m_root.FindComponent(c.InstanceID);

            // Assert
            Assert.IsNotNull(f);
            Assert.AreSame(f, c);
            Assert.AreEqual(f.InstanceID, c.InstanceID);
        }
Exemplo n.º 9
0
        public void RemoveComponent_using_InstanceID()
        {
            IComponent c = new FakeComponent();
            bool       addComponentResult = m_component.AddComponent(c);

            Assert.IsTrue(addComponentResult);

            IComponent r = m_component.RemoveComponent(c.InstanceID);
            IComponent f = m_component.FindComponent(r.InstanceID);

            Assert.IsNotNull(c);
            Assert.IsNotNull(r);
            Assert.AreSame(r, c);
            Assert.IsNull(f);
        }
Exemplo n.º 10
0
        public void RootTest_5()
        {
            IEntity e1 = new GameObject();

            m_component.AddEntity(e1);

            IComponent c1 = new FakeComponent();

            e1.AddComponent(c1);

            IEntity e2 = new GameObject();

            c1.AddEntity(e2);

            IComponent c2 = new FakeComponent();

            e2.AddComponent(c2);

            IEntity e3 = new GameObject();

            c2.AddEntity(e3);

            IComponent c3 = new FakeComponent();

            e3.AddComponent(c3);

            IEntity e4 = new GameObject();

            c3.AddEntity(e4);

            IComponent c4 = new FakeComponent();

            e4.AddComponent(c4);

            IEntity e5 = new GameObject();

            c4.AddEntity(e5);

            Assert.AreSame(m_root, e1.Root);
            Assert.AreSame(m_root, c1.Parent.Root);
            Assert.AreSame(m_root, e2.Root);
            Assert.AreSame(m_root, c2.Parent.Root);
            Assert.AreSame(m_root, e3.Root);
            Assert.AreSame(m_root, c3.Parent.Root);
            Assert.AreSame(m_root, e4.Root);
            Assert.AreSame(m_root, c4.Parent.Root);
            Assert.AreSame(m_root, e5.Root);
        }
Exemplo n.º 11
0
        public void FindComponent_using_InstanceID_NoRecurse()
        {
            // Create a new Component
            IComponent c = new FakeComponent();
            bool       addComponentResult = m_component.AddComponent(c);

            Assert.IsTrue(addComponentResult);

            // Find the Component using the Component InstanceID
            IComponent f = m_component.FindComponent(c.InstanceID);

            // Assert
            Assert.IsNotNull(f);
            Assert.AreSame(f, c);
            Assert.AreSame(f.Parent, c.Parent);
            Assert.AreSame(f.Parent, m_component.Parent);
            Assert.AreEqual(f.InstanceID, c.InstanceID);
        }
Exemplo n.º 12
0
        public void Destroying_component_destroys_after_flush()
        {
            var actor            = new Actor("Sally Sceneless", null);
            var deleteCount      = 0;
            var createdComponent = new FakeComponent(actor, () => { deleteCount++; });
            var actual           = actor.GetComponent <FakeComponent>();

            actor.RemoveComponent <FakeComponent>();
            var actual_AfterRemove_BeforeUpdate = actor.GetComponent <FakeComponent>();

            actor.FlushBuffers();
            var actual_AfterRemove_AfterUpdate = actor.GetComponent <FakeComponent>();

            Assert.NotNull(actual);
            Assert.Equal(createdComponent, actual);
            Assert.NotNull(actual_AfterRemove_BeforeUpdate);
            Assert.Null(actual_AfterRemove_AfterUpdate);
        }
Exemplo n.º 13
0
        public void GoDownToTheLowerLevel_ComponentExistButIsNotAComposite_GiveAnErrorMessage()
        {
            //Arrange
            List <Component> fakeListWithNonCompositeComponent = new List <Component>();

            fakeListWithNonCompositeComponent.Add(SimpleComponentFactory.CreateComponent("File", "nameOfNonCompositeComponent"));

            FakeComponent.Setup(method => method.GetContents())
            .Returns(fakeListWithNonCompositeComponent);

            //Act
            _consoleFileManager.GoDownToTheLowerLevel("nameOfNonCompositeComponent");

            //Assert
            string expectedMessage = "The component nameOfNonCompositeComponent can not be descended because it is not a composite";
            string actualMessage   = _lastMessageFromViewer;

            Assert.AreEqual(expectedMessage, actualMessage);
        }
Exemplo n.º 14
0
 public UnsatisfiedComponent( FakeComponent component )
 {
 }
Exemplo n.º 15
0
 public void CanResolveNamnedDependency()
 {
     m_builder.Register<DependantOnNamedFakeComponent, DependantOnNamedFakeComponent>();
     m_builder.Register<IFakeComponent, FakeComponent>();
     var fakeComponent = new FakeComponent();
     m_builder.Register<IFakeComponent>( fakeComponent, "aber" );
     IContainer container = m_builder.Build();
     var component = container.Resolve<DependantOnNamedFakeComponent>();
     Assert.IsNotNull( component );
     Assert.AreSame( fakeComponent, component.Dependency );
 }
Exemplo n.º 16
0
 public void CanRegisterValueComponent()
 {
     var component = new FakeComponent();
     m_builder.Register( component );
     IContainer container = m_builder.Build();
     var resolvedComponent = container.Resolve<FakeComponent>();
     Assert.AreSame( component, resolvedComponent );
 }