コード例 #1
0
 public void AddingAndRemovingHandlerInTheSameFrameExecutesNoCode()
 {
     var entity = new MockEntity().Start<IncrementCounter>();
     entity.Stop<IncrementCounter>();
     entities.RunEntities();
     Assert.IsFalse(entity.Contains<string>());
 }
コード例 #2
0
 public void ActiveEntityRunsBehavior()
 {
     var entity = new MockEntity();
     entity.Start<IncrementCounter>().Add(0);
     entities.RunEntities();
     Assert.AreEqual(1, entity.Get<int>());
 }
コード例 #3
0
		public void InactivateEntity()
		{
			var entity = new MockEntity();
			entity.IsActive = false;
			Assert.IsFalse(entity.IsActive);
			Assert.AreEqual(0, EntitiesRunner.Current.NumberOfEntities);
		}
コード例 #4
0
 public void AddingAndRemovingTheSameHandlerDoesNothing()
 {
     var entity = new MockEntity().Add(0);
     entity.Start<IncrementCounter>();
     entity.Stop<IncrementCounter>();
     entities.RunEntities();
     Assert.AreEqual(0, entity.Get<int>());
 }
コード例 #5
0
ファイル: EntityTests.cs プロジェクト: whztt07/DeltaEngine
		public void InitializeEntitiesRunner()
		{
			entities = new MockEntitiesRunner(typeof(MockUpdateBehavior), typeof(ComponentTests.Rotate),
				typeof(CreateEntityStartAndStopBehavior));
			entityWithTags = new MockEntity();
			entityWithTags.AddTag(Tag1);
			entityWithTags.AddTag(Tag2);
		}
コード例 #6
0
ファイル: ComponentTests.cs プロジェクト: whztt07/DeltaEngine
		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>());
		}
コード例 #7
0
		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>());
		}
コード例 #8
0
 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);
 }
コード例 #9
0
 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>());
 }
コード例 #10
0
ファイル: EntityTests.cs プロジェクト: whztt07/DeltaEngine
		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));
		}
コード例 #11
0
ファイル: TimeTests.cs プロジェクト: whztt07/DeltaEngine
		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;
		}
コード例 #12
0
ファイル: EntityTests.cs プロジェクト: whztt07/DeltaEngine
		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());
		}
コード例 #13
0
ファイル: EntityTests.cs プロジェクト: whztt07/DeltaEngine
			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);
				}
			}
コード例 #14
0
 public void EntityIsCreatedActiveAndAutomaticallyAddedToEntitySystem()
 {
     var entity = new MockEntity();
     Assert.IsTrue(entity.IsActive);
     Assert.AreEqual(1, EntitiesRunner.Current.NumberOfEntities);
 }
コード例 #15
0
ファイル: EntityTests.cs プロジェクト: whztt07/DeltaEngine
		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());
		}
コード例 #16
0
 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));
 }
コード例 #17
0
 public void InactiveEntityDoesntRunBehavior()
 {
     var entity = new MockEntity();
     entity.Start<IncrementCounter>().Add(0);
     entity.IsActive = false;
     entities.RunEntities();
     Assert.AreEqual(0, entity.Get<int>());
 }
コード例 #18
0
 public void ActivateEntity()
 {
     var entity = new MockEntity { IsActive = false };
     entity.IsActive = true;
     Assert.AreEqual(1, EntitiesRunner.Current.NumberOfEntities);
 }
コード例 #19
0
 public void TestIfComponentIsRemovedWhenEntityIsRemoved()
 {
     var entity = new MockEntity().Start<IncrementCounter>();
     entity.IsActive = false;
     entities.RunEntities();
     Assert.AreEqual(0, entities.NumberOfEntities);
 }
コード例 #20
0
 public void RemovingHandlerWhenNeverAddedExecutesNoCode()
 {
     var entity = new MockEntity();
     entities.RunEntities();
     entity.Stop<IncrementCounter>();
     entities.RunEntities();
     Assert.IsFalse(entity.Contains<string>());
 }
コード例 #21
0
 public void NonPauseableUpdateBehaviorAlwaysRuns()
 {
     VerifyEntityWasUpdated(
         (VerifiableUpdate)new MockEntity().Start<MockNonPauseableUpdateBehavior>(),
         () => entities.RunEntities());
     var entity = new MockEntity().Start<MockNonPauseableUpdateBehavior>();
     VerifyEntityWasUpdated(
         (VerifiableUpdate)entity,
         () => entities.RunEntitiesPaused());
 }
コード例 #22
0
 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>());
 }