private static ReactiveSystemSpy CreateReactiveSystem(MyTestContext context) { var system = new ReactiveSystemSpy(context.CreateCollector(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentA))); context.CreateEntity().AddComponentA(); return(system); }
public void AddsReactiveSystem() { var system = new ReactiveSystemSpy(_ctx.CreateCollector(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentA))); _systems.Add(system); _ctx.CreateEntity().AddComponentA(); _systems.Execute(); Assert.AreEqual(1, system.DidExecute); }
public void ClearsReactiveSystemAfterExecute() { _system = new ReactiveSystemSpy(_context.CreateCollector(_matcherAb)); _system.executeAction = entities => { entities[0].ReplaceComponentA(Component.A); }; var e = CreateEntityAb(); _system.Execute(); _system.Clear(); _system.Execute(); AssertEntities(_system, e); }
private void SetupMultipleContexts() { _context1 = new MyTestContext(); _context2 = new MyTestContext(); var groupA = _context1.GetGroup(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentA)); var groupB = _context2.GetGroup(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentB)); var groups = new[] { groupA, groupB }; var groupEvents = new[] { GroupEvent.Added, GroupEvent.Removed }; var collector = new Collector <MyTestEntity>(groups, groupEvents); _system = new ReactiveSystemSpy(collector); }
public void FiltersEntities() { _system = new ReactiveSystemSpy(_context.CreateCollector(_matcherAb), e => ((NameAgeComponent)e.GetComponent(MyTestComponentsLookup.ComponentA)).age > 42); _context.CreateEntity() .AddComponentA() .AddComponentC(); var eAb1 = _context.CreateEntity(); eAb1.AddComponentB(); eAb1.AddComponent(MyTestComponentsLookup.ComponentA, new NameAgeComponent { age = 10 }); var eAb2 = _context.CreateEntity(); eAb2.AddComponentB(); eAb2.AddComponent(MyTestComponentsLookup.ComponentA, new NameAgeComponent { age = 50 }); var didExecute = 0; _system.executeAction = entities => { didExecute += 1; Assert.AreEqual(3, eAb2.RetainCount); // retained by context, group and collector }; _system.Execute(); Assert.AreEqual(1, didExecute); _system.Execute(); Assert.AreEqual(1, _system.Entities.Length); Assert.AreEqual(eAb2, _system.Entities[0]); Assert.AreEqual(2, eAb1.RetainCount); // retained by context and group Assert.AreEqual(2, eAb2.RetainCount); }
public void InitializesExecutesCleansUpAndTearsDownSystem() { var system = new ReactiveSystemSpy(_ctx.CreateCollector(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentA))); _ctx.CreateEntity().AddComponentA(); Assert.AreEqual(0, system.DidInitialize); system.Initialize(); Assert.AreEqual(1, system.DidInitialize); Assert.AreEqual(0, system.DidExecute); system.Execute(); Assert.AreEqual(1, system.DidExecute); Assert.AreEqual(0, system.DidCleanup); system.Cleanup(); Assert.AreEqual(1, system.DidCleanup); Assert.AreEqual(0, system.DidTearDown); system.TearDown(); Assert.AreEqual(1, system.DidTearDown); }
public void InitializesExecutesCleansUpAndTearsDownInterfacesOfReactiveSystemSpy() { var system = new ReactiveSystemSpy(_ctx.CreateCollector(Matcher <MyTestEntity> .AllOf(CID.ComponentA))); _ctx.CreateEntity().AddComponentA(); _systems.Add(system); Assert.AreEqual(0, system.DidInitialize); _systems.Initialize(); Assert.AreEqual(1, system.DidInitialize); Assert.AreEqual(0, system.DidExecute); _systems.Execute(); Assert.AreEqual(1, system.DidExecute); Assert.AreEqual(0, system.DidCleanup); _systems.Cleanup(); Assert.AreEqual(1, system.DidCleanup); Assert.AreEqual(0, system.DidTearDown); _systems.TearDown(); Assert.AreEqual(1, system.DidTearDown); }
private void SetupReactiveSystemAddedOrRemoved() { _system = new ReactiveSystemSpy(_context.CreateCollector(_matcherAb.AddedOrRemoved())); }