using NUnit.Framework; using System.Linq; using Encompass; using System.Collections.Generic; using System; namespace Tests { public class EngineTest { static IEnumerable components; static MockComponent component; public class ReadComponentsTestEngine : Engine { public override void Update(float dt) { components = this.ReadComponents(); } } public class ReadComponentTestEngine : Engine { public override void Update(float dt) { component = this.ReadComponent(); } } [Test] public void ReadComponents() { var worldBuilder = new WorldBuilder(); worldBuilder.AddEngine(); var entity = worldBuilder.CreateEntity(); MockComponent mockComponent; mockComponent.myInt = 0; mockComponent.myString = "hello"; MockComponent mockComponentB; mockComponentB.myInt = 1; mockComponentB.myString = "howdy"; entity.AddComponent(mockComponent); entity.AddComponent(mockComponentB); var world = worldBuilder.Build(); world.Update(0.01f); Assert.Contains(mockComponent, components.ToList()); Assert.Contains(mockComponentB, components.ToList()); } [Test] public void ReadComponent() { var worldBuilder = new WorldBuilder(); worldBuilder.AddEngine(); var entity = worldBuilder.CreateEntity(); MockComponent mockComponent; mockComponent.myInt = 0; mockComponent.myString = "hello"; entity.AddComponent(mockComponent); var world = worldBuilder.Build(); world.Update(0.01f); Assert.AreEqual(mockComponent, component); } [Test] public void ReadComponentWhenMultipleComponents() { var worldBuilder = new WorldBuilder(); worldBuilder.AddEngine(); var entity = worldBuilder.CreateEntity(); MockComponent mockComponent; mockComponent.myInt = 0; mockComponent.myString = "hello"; MockComponent mockComponentB; mockComponentB.myInt = 1; mockComponentB.myString = "howdy"; entity.AddComponent(mockComponent); entity.AddComponent(mockComponentB); var world = worldBuilder.Build(); Assert.Throws(() => world.Update(0.01f)); } } }