public void CreateEntity() { // create entity with no data blobs: Entity testEntity = Entity.Create(_game.GlobalManager); Assert.IsTrue(testEntity.IsValid); Assert.AreSame(_game.GlobalManager, testEntity.Manager); // Check the mask. Assert.AreEqual(EntityManager.BlankDataBlobMask(), testEntity.DataBlobMask); // Create entity with existing datablobs: var dataBlobs = new List <BaseDataBlob> { new OrbitDB(), new ColonyInfoDB(_pop1, Entity.InvalidEntity) }; testEntity = Entity.Create(_game.GlobalManager, dataBlobs); Assert.IsTrue(testEntity.IsValid); // Check the mask. ComparableBitArray expectedMask = EntityManager.BlankDataBlobMask(); int orbitTypeIndex = EntityManager.GetTypeIndex <OrbitDB>(); int colonyTypeIndex = EntityManager.GetTypeIndex <ColonyInfoDB>(); expectedMask[orbitTypeIndex] = true; expectedMask[colonyTypeIndex] = true; Assert.AreEqual(expectedMask, testEntity.DataBlobMask); // Create entity with existing datablobs, but provide an empty list: dataBlobs.Clear(); testEntity = Entity.Create(_game.GlobalManager, dataBlobs); Assert.IsTrue(testEntity.IsValid); }
public void EntityLookup() { PopulateEntityManager(); // Find all entities with a specific DataBlob. List <Entity> entities = _game.GlobalManager.GetAllEntitiesWithDataBlob <ColonyInfoDB>(_smAuthToken); Assert.AreEqual(2, entities.Count); // again, but look for a datablob that no entity has: entities = _game.GlobalManager.GetAllEntitiesWithDataBlob <AtmosphereDB>(_smAuthToken); Assert.AreEqual(0, entities.Count); // check with invalid data blob type: Assert.Catch(typeof(KeyNotFoundException), () => _game.GlobalManager.GetAllEntitiesWithDataBlob <BaseDataBlob>(_smAuthToken)); // now lets lookup using a mask: ComparableBitArray dataBlobMask = EntityManager.BlankDataBlobMask(); dataBlobMask.Set(EntityManager.GetTypeIndex <ColonyInfoDB>(), true); dataBlobMask.Set(EntityManager.GetTypeIndex <OrbitDB>(), true); entities = _game.GlobalManager.GetAllEntitiesWithDataBlobs(_smAuthToken, dataBlobMask); Assert.AreEqual(2, entities.Count); // and with a mask that will not match any entities: dataBlobMask.Set(EntityManager.GetTypeIndex <AtmosphereDB>(), true); entities = _game.GlobalManager.GetAllEntitiesWithDataBlobs(_smAuthToken, dataBlobMask); Assert.AreEqual(0, entities.Count); // and an empty mask: dataBlobMask = EntityManager.BlankDataBlobMask(); entities = _game.GlobalManager.GetAllEntitiesWithDataBlobs(_smAuthToken, dataBlobMask); Assert.AreEqual(3, entities.Count); // this is counter intuitive... but it is what happens. // test bad mask: ComparableBitArray badMask = new ComparableBitArray(4242); // use a big number so we never rach that many data blobs. Assert.Catch(typeof(ArgumentException), () => _game.GlobalManager.GetAllEntitiesWithDataBlobs(_smAuthToken, badMask)); Assert.Catch(typeof(ArgumentNullException), () => _game.GlobalManager.GetAllEntitiesWithDataBlobs(_smAuthToken, null)); // now lets just get the one entity: Entity testEntity = _game.GlobalManager.GetFirstEntityWithDataBlob <ColonyInfoDB>(_smAuthToken); Assert.IsTrue(testEntity.IsValid); // lookup an entity that does not exist: testEntity = _game.GlobalManager.GetFirstEntityWithDataBlob <AtmosphereDB>(_smAuthToken); Assert.IsFalse(testEntity.IsValid); // try again with incorrect type: Assert.Catch(typeof(KeyNotFoundException), () => { _game.GlobalManager.GetFirstEntityWithDataBlob <BaseDataBlob>(_smAuthToken); }); // now lets just get the one entity, but use a different function to do it: int type = EntityManager.GetTypeIndex <ColonyInfoDB>(); testEntity = _game.GlobalManager.GetFirstEntityWithDataBlob(_smAuthToken, type); Assert.IsTrue(testEntity.IsValid); // lookup an entity that does not exist: type = EntityManager.GetTypeIndex <AtmosphereDB>(); testEntity = _game.GlobalManager.GetFirstEntityWithDataBlob(_smAuthToken, type); Assert.IsFalse(testEntity.IsValid); // try again with incorrect type index: Assert.AreEqual(Entity.InvalidEntity, _game.GlobalManager.GetFirstEntityWithDataBlob(_smAuthToken, 4242)); }