add tests for component-entity getters
							parent
							
								
									c994e9d7fe
								
							
						
					
					
						commit
						5da8e2b71d
					
				| 
						 | 
					@ -32,6 +32,17 @@ namespace Tests
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        static List<(Guid, MockComponent, Entity)> resultComponentsIncludingEntity;
 | 
				
			||||||
 | 
					        static (Guid, MockComponent, Entity) resultComponentIncludingEntity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Reads(typeof(MockComponent))]
 | 
				
			||||||
 | 
					        public class ReadComponentsIncludingEntityEngine : Engine
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public override void Update(double dt)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                resultComponentsIncludingEntity = ReadComponentsIncludingEntity<MockComponent>().ToList();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Reads(typeof(MockComponent))]
 | 
					        [Reads(typeof(MockComponent))]
 | 
				
			||||||
        public class ReadComponentTestEngine : Engine
 | 
					        public class ReadComponentTestEngine : Engine
 | 
				
			||||||
| 
						 | 
					@ -42,6 +53,15 @@ namespace Tests
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Reads(typeof(MockComponent))]
 | 
				
			||||||
 | 
					        public class ReadComponentIncludingEntityEngine : Engine
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public override void Update(double dt)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                resultComponentIncludingEntity = ReadComponentIncludingEntity<MockComponent>();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Test]
 | 
					        [Test]
 | 
				
			||||||
        public void ReadComponents()
 | 
					        public void ReadComponents()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					@ -71,6 +91,42 @@ namespace Tests
 | 
				
			||||||
            resultComponentValues.Should().Contain(mockComponentB);
 | 
					            resultComponentValues.Should().Contain(mockComponentB);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Test]
 | 
				
			||||||
 | 
					        public void ReadComponentsIncludingEntity()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var worldBuilder = new WorldBuilder();
 | 
				
			||||||
 | 
					            worldBuilder.AddEngine(new ReadComponentsIncludingEntityEngine());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var entity = worldBuilder.CreateEntity();
 | 
				
			||||||
 | 
					            var entityB = worldBuilder.CreateEntity();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            MockComponent mockComponent;
 | 
				
			||||||
 | 
					            mockComponent.myInt = 0;
 | 
				
			||||||
 | 
					            mockComponent.myString = "hello";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            MockComponent mockComponentB;
 | 
				
			||||||
 | 
					            mockComponentB.myInt = 1;
 | 
				
			||||||
 | 
					            mockComponentB.myString = "howdy";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var componentAID = worldBuilder.SetComponent(entity, mockComponent);
 | 
				
			||||||
 | 
					            var componentBID = worldBuilder.SetComponent(entityB, mockComponentB);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var world = worldBuilder.Build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            world.Update(0.01f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var resultComponentValues = resultComponentsIncludingEntity.Select((kv) => kv.Item2);
 | 
				
			||||||
 | 
					            resultComponentValues.Should().Contain(mockComponent);
 | 
				
			||||||
 | 
					            resultComponentValues.Should().Contain(mockComponentB);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var resultEntities = resultComponentsIncludingEntity.Select((kv) => kv.Item3);
 | 
				
			||||||
 | 
					            resultEntities.Should().Contain(entity);
 | 
				
			||||||
 | 
					            resultEntities.Should().Contain(entityB);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            resultComponentsIncludingEntity.Should().Contain((componentAID, mockComponent, entity));
 | 
				
			||||||
 | 
					            resultComponentsIncludingEntity.Should().Contain((componentBID, mockComponentB, entityB));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Test]
 | 
					        [Test]
 | 
				
			||||||
        public void ReadComponent()
 | 
					        public void ReadComponent()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					@ -119,6 +175,27 @@ namespace Tests
 | 
				
			||||||
            Assert.That(resultComponent, Is.EqualTo(mockComponent).Or.EqualTo(mockComponentB));
 | 
					            Assert.That(resultComponent, Is.EqualTo(mockComponent).Or.EqualTo(mockComponentB));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Test]
 | 
				
			||||||
 | 
					        public void ReadComponentWithEntity()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var worldBuilder = new WorldBuilder();
 | 
				
			||||||
 | 
					            worldBuilder.AddEngine(new ReadComponentIncludingEntityEngine());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var entity = worldBuilder.CreateEntity();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            MockComponent mockComponent;
 | 
				
			||||||
 | 
					            mockComponent.myInt = 0;
 | 
				
			||||||
 | 
					            mockComponent.myString = "hello";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var componentID = worldBuilder.SetComponent(entity, mockComponent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var world = worldBuilder.Build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            world.Update(0.01f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            (componentID, mockComponent, entity).Should().BeEquivalentTo(resultComponentIncludingEntity);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Reads(typeof(MockComponent))]
 | 
					        [Reads(typeof(MockComponent))]
 | 
				
			||||||
        [Writes(typeof(MockComponent))]
 | 
					        [Writes(typeof(MockComponent))]
 | 
				
			||||||
        public class UpdateComponentTestEngine : Engine
 | 
					        public class UpdateComponentTestEngine : Engine
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue