public void AddingAndRemovingHandlerInTheSameFrameExecutesNoCode() { var entity = new MockEntity().Start<IncrementCounter>(); entity.Stop<IncrementCounter>(); entities.RunEntities(); Assert.IsFalse(entity.Contains<string>()); }
public void ActiveEntityRunsBehavior() { var entity = new MockEntity(); entity.Start<IncrementCounter>().Add(0); entities.RunEntities(); Assert.AreEqual(1, entity.Get<int>()); }
public void InactivateEntity() { var entity = new MockEntity(); entity.IsActive = false; Assert.IsFalse(entity.IsActive); Assert.AreEqual(0, EntitiesRunner.Current.NumberOfEntities); }
public void AddingAndRemovingTheSameHandlerDoesNothing() { var entity = new MockEntity().Add(0); entity.Start<IncrementCounter>(); entity.Stop<IncrementCounter>(); entities.RunEntities(); Assert.AreEqual(0, entity.Get<int>()); }
public void InitializeEntitiesRunner() { entities = new MockEntitiesRunner(typeof(MockUpdateBehavior), typeof(ComponentTests.Rotate), typeof(CreateEntityStartAndStopBehavior)); entityWithTags = new MockEntity(); entityWithTags.AddTag(Tag1); entityWithTags.AddTag(Tag2); }
public void CreateEntityWithRotationComponent() { var entities = new MockEntitiesRunner(typeof(Rotate)); var entity = new MockEntity().Add(0.5f).Start<Rotate>(); Assert.AreEqual(0.5f, entity.Get<float>()); entities.RunEntities(); Assert.AreEqual(0.55f, entity.Get<float>()); }
public void SelectingEntityHandlerProcessesEntitiesThatPassTheSelectionCriteria() { var entities = new MockEntitiesRunner(typeof(IncludeOnlyEntitiesWithPositiveFloats)); var first = new MockEntity().Start<IncludeOnlyEntitiesWithPositiveFloats>().Add(3.0f); var excluded = new MockEntity().Start<IncludeOnlyEntitiesWithPositiveFloats>().Add(-1.0f); var second = new MockEntity().Start<IncludeOnlyEntitiesWithPositiveFloats>().Add(2.0f); entities.RunEntities(); var start = first.Get<int>(); Assert.IsFalse(excluded.Contains<int>()); Assert.AreEqual(start + 1, second.Get<int>()); }
public void AddingBehaviorTwiceIsIgnored() { var entity = new MockEntity().Start<IncrementCounter>().Add(0); var behavior = EntitiesRunner.Current.GetUpdateBehavior<IncrementCounter>(); entities.RunEntities(); Assert.AreEqual(1, entity.Get<int>()); entity.Start<IncrementCounter>(); Assert.AreEqual(behavior, EntitiesRunner.Current.GetUpdateBehavior<IncrementCounter>()); entities.RunEntities(); Assert.AreEqual(2, entity.Get<int>()); Assert.AreEqual(1, EntitiesRunner.Current.NumberOfEntities); }
public void AddEntityAndAttachHandlerLater() { var entity = new MockEntity().Add(0); entities.RunEntities(); Assert.AreEqual(0, entity.Get<int>()); entity.Start<IncrementCounter>(); entities.RunEntities(); Assert.AreEqual(1, entity.Get<int>()); entity.Stop<IncrementCounter>(); entities.RunEntities(); Assert.AreEqual(1, entity.Get<int>()); }
public void AddAndRemoveComponent() { Assert.AreEqual(1, entities.NumberOfEntities); var entity = new MockEntity().Add(new object()); Assert.AreEqual(2, entities.NumberOfEntities); Assert.AreEqual(1, entity.NumberOfComponents); Assert.IsNotNull(entity.Get<object>()); entity.Remove<object>(); Assert.AreEqual(0, entity.NumberOfComponents); Assert.IsFalse(entity.Contains<object>()); Assert.Throws<ArgumentNullException>(() => new MockEntity().Add<object>(null)); }
public void PauseTimeShouldNotUpdateAnyEntityAnymore() { var entities = new MockEntitiesRunner(typeof(EntitiesRunnerTests.IncrementCounter)); var entity = new MockEntity().Add(0).Start<EntitiesRunnerTests.IncrementCounter>(); Assert.AreEqual(0, entity.Get<int>()); entities.RunEntities(); Assert.AreEqual(1, entity.Get<int>()); Time.SpeedFactor = 0; entities.RunEntities(); Assert.AreEqual(1, entity.Get<int>()); Time.SpeedFactor = 1; }
public void ToStringWithComponentAndList() { entityWithTags.IsActive = false; Assert.AreEqual("<Inactive> MockEntity Tags=Tag1, Tag2", entityWithTags.ToString()); var entityWithComponent = new MockEntity().Add(new object()).Add(new Vector2D(1, 2)); Assert.AreEqual("MockEntity: Object, Vector2D=1, 2", entityWithComponent.ToString()); var entityWithList = new MockEntity().Add(new List<Color>()); Assert.AreEqual("MockEntity: List<Color>", entityWithList.ToString()); }
public override void Update(IEnumerable<Entity> entities) { foreach (Entity entity in entities) { var child = new MockEntity(); child.Start<MockUpdateBehavior>(); child.Stop<MockUpdateBehavior>(); entity.Add(child); } }
public void EntityIsCreatedActiveAndAutomaticallyAddedToEntitySystem() { var entity = new MockEntity(); Assert.IsTrue(entity.IsActive); Assert.AreEqual(1, EntitiesRunner.Current.NumberOfEntities); }
public void ToStringWithArrayAndBehavior() { entityWithTags.Add(new Vector2D[2]); Assert.AreEqual("MockEntity Tags=Tag1, Tag2: Vector2D[]", entityWithTags.ToString()); var entityWithRunner = new MockEntity().Start<MockUpdateBehavior>().Start<ComponentTests.Rotate>(); Assert.AreEqual("MockEntity [MockUpdateBehavior, Rotate]", entityWithRunner.ToString()); }
public void AddingTheSameEntityTwiceIsNotOk() { var entity1 = new MockEntity(); var entity2 = new MockEntity().Start<MockUpdateBehavior>(); Assert.Throws<EntitiesRunner.EntityAlreadyAdded>(() => EntitiesRunner.Current.Add(entity1)); Assert.Throws<EntitiesRunner.EntityAlreadyAdded>(() => EntitiesRunner.Current.Add(entity2)); var entity3 = new MockEntity(); Assert.Throws<EntitiesRunner.EntityAlreadyAdded>(() => EntitiesRunner.Current.Add(entity3)); }
public void InactiveEntityDoesntRunBehavior() { var entity = new MockEntity(); entity.Start<IncrementCounter>().Add(0); entity.IsActive = false; entities.RunEntities(); Assert.AreEqual(0, entity.Get<int>()); }
public void ActivateEntity() { var entity = new MockEntity { IsActive = false }; entity.IsActive = true; Assert.AreEqual(1, EntitiesRunner.Current.NumberOfEntities); }
public void TestIfComponentIsRemovedWhenEntityIsRemoved() { var entity = new MockEntity().Start<IncrementCounter>(); entity.IsActive = false; entities.RunEntities(); Assert.AreEqual(0, entities.NumberOfEntities); }
public void RemovingHandlerWhenNeverAddedExecutesNoCode() { var entity = new MockEntity(); entities.RunEntities(); entity.Stop<IncrementCounter>(); entities.RunEntities(); Assert.IsFalse(entity.Contains<string>()); }
public void NonPauseableUpdateBehaviorAlwaysRuns() { VerifyEntityWasUpdated( (VerifiableUpdate)new MockEntity().Start<MockNonPauseableUpdateBehavior>(), () => entities.RunEntities()); var entity = new MockEntity().Start<MockNonPauseableUpdateBehavior>(); VerifyEntityWasUpdated( (VerifiableUpdate)entity, () => entities.RunEntitiesPaused()); }
public void ReactivatedEntityRunsBehavior() { var entity = new MockEntity(); entity.Start<IncrementCounter>().Add(0); entity.IsActive = false; entity.IsActive = true; entities.RunEntities(); Assert.AreEqual(1, entity.Get<int>()); }