public void AddEntityDoesntAddToListBeforeCommit() { var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>()); var entity = e.CreateEntity(new IComponent[0]); e.Entities.Should().NotContain(entity); e.AddedEntities.Should().Contain(entity); }
public void RemoveEntityClearsListAfterCommit() { var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>()); var entity = e.CreateEntity(new IComponent[0]); e.CommitAdded(); e.RemoveEntity(entity); e.CommitRemoved(); e.RemovedEntities.Should().BeEmpty(); }
public void AddEntityAddsEntityToListAfterCommit() { var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>()); var entity = e.CreateEntity(new IComponent[0]); e.CommitAdded(); e.Entities.Should().Contain(entity); e.AddedEntities.Should().NotContain(entity); e.GetEntity(entity.Id).Should().Be(entity); }
public void RemoveEntityRemovesFromListAfterCommit() { var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>()); var entity = e.CreateEntity(new IComponent[0]); e.CommitAdded(); e.RemoveEntity(entity); e.CommitRemoved(); e.Entities.Should().NotContain(entity); e.GetEntity(entity.Id).Should().BeNull(); }
public RuntimeEngine(RuntimeEntityService entityService, ISystemManager systemManager, EventQueue eventQueue, ILogger logger) { AddEntityAccessGate = new AccessGate(); EventQueue = eventQueue; _logger = logger; EntityService = entityService; EntityService.AddEntityAccessGate = AddEntityAccessGate; SystemManager = systemManager; SystemUpdateScheduler = new SystemUpdateScheduler(SystemManager.Systems); foreach (var updateBurst in SystemUpdateScheduler.UpdateBursts) { _logger.Info($"Update Burst: {string.Join(", ", updateBurst.Systems.Select(p => p.System.Name))}"); } // Add any entities that are already loaded into the engine. SystemManager.AddEntities(entityService.Entities); }
public void RemoveEntityPostsEvent() { var mock = new Mock<IEventDispatcher>(); var e = new RuntimeEntityService(mock.Object, Mock.Of<ILogger>()); var entity = e.CreateEntity(new IComponent[0]); mock.Verify(p => p.Post(It.IsAny<EntityAdded>())); }
public void CheckIdProviderDoesntOverrideExistingId() { var entityService = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>(), new RuntimeEntityTemplateProvider(new[] {new EntityTemplate("Test", new IComponent[0])}), new[] { new EngineEntity(0, new IComponent[0], Mock.Of<IEventDispatcher>()), new EngineEntity(1, new IComponent[0], Mock.Of<IEventDispatcher>()), new EngineEntity(5, new IComponent[0], Mock.Of<IEventDispatcher>()), }); // Create new entity entityService.CreateEntity("Test"); // Commit the added entities entityService.CommitAdded(); entityService.Entities.Select(p => p.Id).Should().OnlyHaveUniqueItems("Entity IDs need to be unique."); }
public void CreatesEntityFromTemplateSetsCorrectPrototype() { var mock = new Mock<IEntityTemplateProvider>(); mock.Setup((c) => c.Get("Test")).Returns(new EntityTemplate("Test", new IComponent[] {})); var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>(), mock.Object); var entity = e.CreateEntity("Test"); (entity as EngineEntity).Prototype.Should().Be("Test"); }
public void CreatesEntityFromTemplateWithCorrectComponents() { var mock = new Mock<IEntityTemplateProvider>(); mock.Setup((c) => c.Get("Test")).Returns(new EntityTemplate("Test", new IComponent[] { new SimpleComponent(), new OtherSimpleComponent() })); var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>(), mock.Object); var entity = e.CreateEntity("Test"); entity.HasComponent<ISimpleComponent>().Should().BeTrue(); entity.HasComponent<IOtherSimpleComponent>().Should().BeTrue(); }
public void ThrowsIfCreateEntityFromTemplateCalledWithNoTemplateProvider() { var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>()); Action act = () => e.CreateEntity("Test"); act.ShouldThrow<InvalidOperationException>(); }
public void EnsureAddEntityThrowsWhenGateLocked() { var mock = new Mock<IAccessGate>(); mock.Setup(gate => gate.TryEnter()).Returns(false); var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>()); e.AddEntityAccessGate = mock.Object; Action act = () => e.CreateEntity(new IComponent[0]); act.ShouldThrow<InvalidOperationException>(); }