72 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
| using NUnit.Framework;
 | |
| using Encompass;
 | |
| 
 | |
| namespace Tests
 | |
| {
 | |
|     public static class GeneralRendererTest
 | |
|     {
 | |
|         struct AComponent { }
 | |
| 
 | |
|         public class SingletonRead
 | |
|         {
 | |
|             static (AComponent, Entity) result;
 | |
| 
 | |
|             class TestRenderer : Renderer
 | |
|             {
 | |
|                 public override void Render(double dt, double alpha)
 | |
|                 {
 | |
|                     ref readonly var entity = ref ReadEntity<AComponent>();
 | |
|                     result = (GetComponent<AComponent>(entity), entity);
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             [Test]
 | |
|             public void SingletonComponent()
 | |
|             {
 | |
|                 var worldBuilder = new WorldBuilder();
 | |
|                 worldBuilder.AddRenderer(new TestRenderer());
 | |
| 
 | |
|                 AComponent aComponent;
 | |
| 
 | |
|                 var entity = worldBuilder.CreateEntity();
 | |
|                 worldBuilder.SetComponent(entity, aComponent);
 | |
| 
 | |
|                 var world = worldBuilder.Build();
 | |
| 
 | |
|                 world.Update(0.01f);
 | |
|                 world.Draw(0.01f, 0);
 | |
| 
 | |
|                 world.Update(0.01);
 | |
|                 world.Draw(0.01f, 0);
 | |
| 
 | |
|                 Assert.That(result, Is.EqualTo((aComponent, entity)));
 | |
|             }
 | |
| 
 | |
|             [Test]
 | |
|             public void MultipleComponents()
 | |
|             {
 | |
|                 var worldBuilder = new WorldBuilder();
 | |
|                 worldBuilder.AddRenderer(new TestRenderer());
 | |
| 
 | |
|                 AComponent aComponent;
 | |
|                 AComponent aComponentTwo;
 | |
| 
 | |
|                 var entity = worldBuilder.CreateEntity();
 | |
|                 worldBuilder.SetComponent(entity, aComponent);
 | |
| 
 | |
|                 var entityB = worldBuilder.CreateEntity();
 | |
|                 worldBuilder.SetComponent(entityB, aComponentTwo);
 | |
|                 var world = worldBuilder.Build();
 | |
| 
 | |
|                 world.Update(0.01f);
 | |
|                 world.Draw(0.01f, 0);
 | |
| 
 | |
|                 world.Update(0.01f);
 | |
|                 world.Draw(0.01f, 0);
 | |
| 
 | |
|                 Assert.That(result, Is.EqualTo((aComponent, entity)).Or.EqualTo((aComponentTwo, entityB)));
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |