public void AddingDifferentEntitiesWithMatchingComponent_AllAreAddedToNodeList() { var family = new ComponentMatchingFamily <Node <MockComponentA> >(); var entity1 = new MockEntity <MockComponentA>(); var entity2 = new MockEntity <MockComponentA>(); family.EntityAdded(entity1); Assert.AreEqual(family.Nodes.Count(), 1); Assert.AreEqual(family.Nodes.ToList()[0].Component1, entity1.Components[0]); family.EntityAdded(entity2); Assert.AreEqual(family.Nodes.Count(), 2); Assert.AreEqual(family.Nodes.ToList()[1].Component1, entity2.Components[0]); }
public void WhenEntityRemoved_NodeReturnedToPool() { var pool = Substitute.For <INodePool <Node <MockComponentA> > >(); var family = new ComponentMatchingFamily <Node <MockComponentA> >(pool); var node = new Node <MockComponentA>(); pool.UnPool().Returns(node); var entity1 = new MockEntity <MockComponentA>(); family.EntityAdded(entity1); family.EntityRemoved(entity1); pool.Received().UnPool(); pool.Received().Pool(node); }
public void IfComponentRemovedFromAnEntityNotInTheList_NothingHappens() { var family = new ComponentMatchingFamily <Node <MockComponentA> >(); var entity1 = new MockEntity <MockComponentA>(); var entity2 = new MockEntity <MockComponentB>(); family.EntityAdded(entity1); family.EntityAdded(entity2); Assert.AreEqual(family.Nodes.Count(), 1); Assert.AreEqual(family.Nodes.ToList()[0].Component1, entity1.Components[0]); family.ComponentRemoved(entity2, typeof(MockComponentA)); Assert.AreEqual(family.Nodes.Count(), 1); Assert.AreEqual(family.Nodes.ToList()[0].Component1, entity1.Components[0]); }
public void IfEntityOfSameTypeButDifferentInstanceIsRemoved_CorrectInstanceIsRemoved() { var family = new ComponentMatchingFamily <Node <MockComponentA> >(); var entity1 = new MockEntity <MockComponentA>(); family.EntityAdded(entity1); var entity2 = new MockEntity <MockComponentA>(); family.EntityAdded(entity2); Assert.IsTrue(family.Nodes.Count() == 2); family.EntityRemoved(entity1); Assert.IsTrue(family.Nodes.Count() == 1); Assert.IsTrue(family.Nodes.First().Component1 == entity2.Components[0]); }
public void IfNodesAreReleasedThenRetrievedAgain_EntitiesReadded() { var factory = Substitute.For <IFamilyFactory>(); var engine = new Engine(factory); var entity = new MockEntity <MockComponentA>(); var family1 = Substitute.For <IFamily <Node <MockComponentA> > >(); var family2 = Substitute.For <IFamily <Node <MockComponentA> > >(); factory.Produce <Node <MockComponentA> >().Returns(family1, family2); var nodes1 = engine.GetNodes <Node <MockComponentA> >(); engine.AddEntity(entity); engine.ReleaseNodes(nodes1); engine.GetNodes <Node <MockComponentA> >(); family1.Received().EntityAdded(entity); family2.Received().EntityAdded(entity); }
public void IfComponentRemovedAfterEntityAddedToEngine_FamiliesInformed() { var factory = Substitute.For <IFamilyFactory>(); var engine = new Engine(factory); var entity = new MockEntity <MockComponentA>(); var family1 = Substitute.For <IFamily <Node <MockComponentA> > >(); var family2 = Substitute.For <IFamily <Node <MockComponentB> > >(); factory.Produce <Node <MockComponentA> >().Returns(family1); factory.Produce <Node <MockComponentB> >().Returns(family2); engine.GetNodes <Node <MockComponentA> >(); engine.GetNodes <Node <MockComponentB> >(); engine.AddEntity(entity); entity.ComponentRemoved.Invoke(entity, typeof(MockComponentC)); family1.Received().ComponentRemoved(entity, typeof(MockComponentC)); family2.Received().ComponentRemoved(entity, typeof(MockComponentC)); }
public void AddingAnEntity_InformsEachFamily() { var factory = Substitute.For <IFamilyFactory>(); var engine = new Engine(factory); var familyA = Substitute.For <IFamily <Node <MockComponentA> > >(); var familyB = Substitute.For <IFamily <Node <MockComponentB> > >(); factory.Produce <Node <MockComponentA> >().Returns(familyA); factory.Produce <Node <MockComponentB> >().Returns(familyB); engine.GetNodes <Node <MockComponentA> >(); engine.GetNodes <Node <MockComponentB> >(); var entityA = new MockEntity(); engine.AddEntity(entityA); familyA.Received().EntityAdded(entityA); familyB.Received().EntityAdded(entityA); }