using NUnit.Framework; using System; using System.Collections.Generic; using Encompass; namespace Tests { public static class GeneralRendererTest { struct AComponent : IComponent { } public class SingletonRead { static ValueTuple result; class TestRenderer : GeneralRenderer { public override void Render() { result = ReadComponent(); } } [Test] public void SingletonComponent() { var worldBuilder = new WorldBuilder(); worldBuilder.AddGeneralRenderer(new TestRenderer(), 1); AComponent aComponent; var entity = worldBuilder.CreateEntity(); var componentID = worldBuilder.AddComponent(entity, aComponent); var world = worldBuilder.Build(); world.Update(0.01f); world.Draw(); Assert.That(result, Is.EqualTo(new ValueTuple(componentID, aComponent))); } [Test] public void MultipleComponents() { var worldBuilder = new WorldBuilder(); worldBuilder.AddGeneralRenderer(new TestRenderer(), 1); AComponent aComponent; AComponent aComponentTwo; var entity = worldBuilder.CreateEntity(); var componentID = worldBuilder.AddComponent(entity, aComponent); var entityB = worldBuilder.CreateEntity(); var componentTwoID = worldBuilder.AddComponent(entityB, aComponentTwo); var world = worldBuilder.Build(); world.Update(0.01f); world.Draw(); Assert.That(result, Is.EqualTo((componentID, aComponent)).Or.EqualTo((componentTwoID, aComponentTwo))); } } } }