Skip to content

Commit

Permalink
added EntityManager::verifyExistenceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
lpmaurice committed Mar 23, 2011
1 parent f5ae36e commit f247002
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/com/tomseysdavies/ember/base/EntityManager.as
Expand Up @@ -52,6 +52,11 @@ package com.tomseysdavies.ember.base {
return entity;
}

public function verifyExistenceOf(id:String):Boolean
{
return _components[id] != null;
}

/**
* @inheritDoc
*/
Expand Down
11 changes: 10 additions & 1 deletion src/com/tomseysdavies/ember/core/IEntityManager.as
Expand Up @@ -10,13 +10,22 @@ package com.tomseysdavies.ember.core{
public interface IEntityManager extends IDisposable {

/**
* creates a new entity with the id provided. If no id is provided a unique id will be auto generated
* Creates a new entity with the id provided. If no id is provided a unique id will be auto generated.
*
* If an id is provided but the entityManager already has an entity
* with the same id, no entity will be created.
*
* @return the new entity
*
*/
function createEntity(Id:String = null):IEntity;

/**
*
* @return Boolean, true if an entity with the provided id exists.
*/
function verifyExistenceOf(id:String):Boolean;

/**
* unregisters an entity
*
Expand Down
9 changes: 8 additions & 1 deletion test/ember/EntityManagerTest.as
Expand Up @@ -40,7 +40,14 @@ package ember
var id:String = "SOME_ID";
_entityManager.createEntity(id);
assertNull("Entity with duplicate ID won't be created.", _entityManager.createEntity(id));

}

public function testEntityIsDeleted():void
{
var id:String = "SOME_ID";
_entityManager.createEntity(id);
_entityManager.removeEntity(id);
assertFalse("Entity was removed.", _entityManager.verifyExistenceOf(id));
}

//_________________PRIVATE
Expand Down

0 comments on commit f247002

Please sign in to comment.