private Entity BuildEntity(int id = 1) { var entity = new Entity(id); var c = new UpdateComponentStub(entity); entity.AddComponent(c); var result = entity.Initialize(); Debug.Assert(result); return(entity); }
public void Dispose_DisposesAllComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); entity.AddComponent(component1); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component2); entity.Dispose(); Assert.AreEqual(1, component1.DisposeCallCount); Assert.AreEqual(1, component2.DisposeCallCount); }
public void DoInitialize_SetsUpdateFlag() { var entity = new Entity(1); var component = new UpdateComponentStub(entity); entity.AddComponent(component); var result = entity.Initialize(); Assert.IsTrue(result); Assert.IsTrue(entity.NeedsUpdate); Assert.IsTrue(entity.IsInitialized); Assert.AreEqual(1, component.DoInitializeCallCount); }
public void AddComponent_RejectsAfterInitialization() { var entity = new Entity(1); var component1 = new ComponentStub(entity); entity.AddComponent(component1); entity.Initialize(); var component2 = new UpdateComponentStub(entity); TestDelegate func = () => entity.AddComponent(component2); Assert.Throws<InvalidOperationException>(func); Assert.AreEqual(1, entity.Components.Count()); Assert.AreSame(component1, entity.GetComponent<ComponentStub>()); }
public void GetComponent_FindsWithMultipleComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component1); entity.AddComponent(component2); var result1 = entity.GetComponent<ComponentStub>(); var result2 = entity.GetComponent<UpdateComponentStub>(); Assert.AreSame(component1, result1); Assert.AreSame(component2, result2); }
public void HasComponent_FindsWithMultipleComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component1); entity.AddComponent(component2); var result1 = entity.HasComponent<ComponentStub>(); var result2 = entity.HasComponent<UpdateComponentStub>(); Assert.IsTrue(result1); Assert.IsTrue(result2); }
public void DoInitialize_InitializesComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); entity.AddComponent(component1); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component2); var result = entity.Initialize(); Assert.IsTrue(result); Assert.IsTrue(entity.IsInitialized); Assert.AreEqual(1, component1.DoInitializeCallCount); Assert.AreEqual(1, component2.DoInitializeCallCount); }
public void GetComponentsByBase_GetsComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component1); entity.AddComponent(component2); var result1 = entity.GetComponentsByBase<ComponentBase>(); var result2 = entity.GetComponentsByBase<ComponentStub>(); var result3 = entity.GetComponentsByBase<UpdateComponentStub>(); Assert.AreEqual(2, result1.Count); Assert.AreEqual(2, result2.Count); Assert.AreEqual(1, result3.Count); }
public void Update_IgnoresNonUpdateComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); entity.AddComponent(component1); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component2); entity.Initialize(); entity.Activate(); var time = 1.0f; entity.Update(time); Assert.AreEqual(0, component1.UpdateCallCount); Assert.AreEqual(1, component2.UpdateCallCount); Assert.AreEqual(time, component2.LastUpdateDeltaTime); }
public void DoDestroy_DestroysComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); entity.AddComponent(component1); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component2); entity.Initialize(); entity.Destroy(); Assert.IsTrue(entity.IsDestroyed); Assert.IsTrue(component1.IsDestroyed); Assert.AreEqual(1, component1.DoDestroyCallCount); Assert.IsTrue(component2.IsDestroyed); Assert.AreEqual(1, component2.DoDestroyCallCount); }
public void DoActivate_ActivatesComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); entity.AddComponent(component1); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component2); entity.Initialize(); entity.Activate(); Assert.IsTrue(entity.IsActive); Assert.IsTrue(component1.IsActive); Assert.AreEqual(1, component1.DoActivateCallCount); Assert.IsTrue(component2.IsActive); Assert.AreEqual(1, component2.DoActivateCallCount); }
public void DoInitialize_FailsWhenComponentFails() { var entity = new Entity(1); var component1 = new ComponentStub(entity); entity.AddComponent(component1); var component2 = new UpdateComponentStub(entity, false); entity.AddComponent(component2); var result = entity.Initialize(); Assert.IsFalse(result); Assert.IsFalse(entity.IsInitialized); Assert.IsTrue(entity.IsDestroyed); Assert.AreEqual(1, component1.DoInitializeCallCount); Assert.AreEqual(1, component1.DoDestroyCallCount); Assert.AreEqual(1, component2.DoInitializeCallCount); Assert.AreEqual(1, component2.DoDestroyCallCount); }
public void TryGetComponent_FindsWithMultipleComponents() { var entity = new Entity(1); var component1 = new ComponentStub(entity); var component2 = new UpdateComponentStub(entity); entity.AddComponent(component1); entity.AddComponent(component2); ComponentStub outResult1; UpdateComponentStub outResult2; var result1 = entity.TryGetComponent(out outResult1); var result2 = entity.TryGetComponent(out outResult2); Assert.IsTrue(result1); Assert.AreSame(component1, outResult1); Assert.IsTrue(result2); Assert.AreSame(component2, outResult2); }