|
5 | 5 | using Improbable.Gdk.Core; |
6 | 6 | using Improbable.Gdk.GameObjectCreation; |
7 | 7 | using Improbable.Gdk.Subscriptions; |
| 8 | +using Improbable.Gdk.TestUtils; |
8 | 9 | using NUnit.Framework; |
9 | 10 | using UnityEngine; |
10 | | -using Object = UnityEngine.Object; |
11 | 11 |
|
12 | | -namespace Improbable.Gdk.PlaymodeTests.Subscriptions |
| 12 | +namespace Improbable.Gdk.EditmodeTests.Subscriptions |
13 | 13 | { |
14 | | - public class SubscriptionAggregateCouplingTests |
| 14 | + public class SubscriptionAggregateCouplingTests : MockBase |
15 | 15 | { |
16 | | - private MockConnectionHandler connectionHandler; |
17 | | - private WorkerInWorld workerInWorld; |
18 | | - private EntityGameObjectLinker linker; |
19 | | - |
20 | | - private SpatialOSReceiveSystem receiveSystem; |
21 | | - private RequireLifecycleSystem requireLifecycleSystem; |
22 | | - |
23 | | - private const string WorkerType = "TestWorkerType"; |
24 | | - |
25 | | - [SetUp] |
26 | | - public void Setup() |
| 16 | + protected override MockWorld.Options GetOptions() |
27 | 17 | { |
28 | | - var logDispatcher = new LoggingDispatcher(); |
29 | | - |
30 | | - var connectionBuilder = new MockConnectionHandlerBuilder(); |
31 | | - connectionHandler = connectionBuilder.ConnectionHandler; |
32 | | - workerInWorld = WorkerInWorld |
33 | | - .CreateWorkerInWorldAsync(connectionBuilder, WorkerType, logDispatcher, Vector3.zero) |
34 | | - .Result; |
35 | | - receiveSystem = workerInWorld.World.GetExistingSystem<SpatialOSReceiveSystem>(); |
36 | | - requireLifecycleSystem = workerInWorld.World.GetExistingSystem<RequireLifecycleSystem>(); |
37 | | - |
38 | | - var goInitSystem = workerInWorld.World |
39 | | - .CreateSystem<GameObjectInitializationSystem>( |
40 | | - new GameObjectCreatorFromMetadata(WorkerType, Vector3.zero, logDispatcher), null); |
41 | | - linker = goInitSystem.Linker; |
42 | | - } |
| 18 | + var opts = base.GetOptions(); |
43 | 19 |
|
44 | | - [TearDown] |
45 | | - public void TearDown() |
46 | | - { |
47 | | - workerInWorld.Dispose(); |
| 20 | + // Required for the LinkedGameObjectMap subscription to be fulfilled. |
| 21 | + opts.AdditionalSystems = (world) => |
| 22 | + { |
| 23 | + world.AddSystem( |
| 24 | + new GameObjectInitializationSystem( |
| 25 | + new GameObjectCreatorFromMetadata(opts.WorkerType, Vector3.zero, null), null)); |
| 26 | + }; |
| 27 | + |
| 28 | + return opts; |
48 | 29 | } |
49 | 30 |
|
50 | 31 | [Test] |
51 | 32 | public void All_non_generated_subscription_managers_have_a_test() |
52 | 33 | { |
53 | 34 | // Find all non-generated subscription manager implementations. |
54 | | - var subscriptionManagersTypes = ReflectionUtility.GetNonAbstractTypesWithBlacklist(typeof(SubscriptionManagerBase), new[] { "Improbable.Gdk.Generated" }); |
| 35 | + var subscriptionManagersTypes = |
| 36 | + ReflectionUtility.GetNonAbstractTypesWithBlacklist(typeof(SubscriptionManagerBase), |
| 37 | + new[] { "Improbable.Gdk.Generated" }); |
55 | 38 |
|
56 | 39 | // Get the subscription payload type. |
57 | 40 | var subscriptionManagerContainedTypes = subscriptionManagersTypes |
@@ -157,45 +140,49 @@ public void DifferentAggregateSubscriptions_should_not_couple_together(Type requ |
157 | 140 | // were cached incorrectly would cause the subscriptions to become coupled. |
158 | 141 | private void DifferentAggregateSubscriptions_should_not_couple_together_impl<T>() where T : MonoBehaviour |
159 | 142 | { |
160 | | - var gameObject1 = CreateAndLinkGameObject<T>(1); |
161 | | - var gameObject2 = CreateAndLinkGameObject<T>(2); |
162 | | - |
163 | | - RemoveAndUnlinkGameObject(1, gameObject1); |
164 | | - RemoveAndUnlinkGameObject(2, gameObject2); |
165 | | - |
166 | | - var gameObject3 = CreateAndLinkGameObject<T>(3); |
167 | | - var gameObject4 = CreateAndLinkGameObject<T>(4); |
168 | | - |
169 | | - RemoveAndUnlinkGameObject(3, gameObject3); |
170 | | - |
171 | | - Assert.IsTrue(gameObject4.GetComponent<T>().enabled, "gameObject4.GetComponent<T>().enabled"); |
| 143 | + World |
| 144 | + .Step(world => |
| 145 | + { |
| 146 | + world.Connection.CreateEntity(1, GetEntityTemplate()); |
| 147 | + world.Connection.CreateEntity(2, GetEntityTemplate()); |
| 148 | + }) |
| 149 | + .Step(world => |
| 150 | + { |
| 151 | + world.CreateGameObject<T>(1); |
| 152 | + world.CreateGameObject<T>(2); |
| 153 | + }) |
| 154 | + .Step(world => |
| 155 | + { |
| 156 | + world.Connection.RemoveComponent(1, Position.ComponentId); |
| 157 | + world.Connection.RemoveEntity(1); |
| 158 | + world.Connection.RemoveComponent(2, Position.ComponentId); |
| 159 | + world.Connection.RemoveEntity(2); |
| 160 | + }) |
| 161 | + .Step(world => |
| 162 | + { |
| 163 | + world.Connection.CreateEntity(3, GetEntityTemplate()); |
| 164 | + world.Connection.CreateEntity(4, GetEntityTemplate()); |
| 165 | + }) |
| 166 | + .Step(world => |
| 167 | + { |
| 168 | + world.CreateGameObject<T>(3); |
| 169 | + var (_, behaviour) = world.CreateGameObject<T>(4); |
| 170 | + return behaviour; |
| 171 | + }).Step(world => |
| 172 | + { |
| 173 | + world.Connection.RemoveComponent(3, Position.ComponentId); |
| 174 | + world.Connection.RemoveEntity(3); |
| 175 | + }).Step((world, behaviour) => |
| 176 | + { |
| 177 | + Assert.IsTrue(behaviour.enabled); |
| 178 | + }); |
172 | 179 | } |
173 | 180 |
|
174 | | - private GameObject CreateAndLinkGameObject<T>(long entityId) where T : MonoBehaviour |
| 181 | + private EntityTemplate GetEntityTemplate() |
175 | 182 | { |
176 | 183 | var template = new EntityTemplate(); |
177 | 184 | template.AddComponent(new Position.Snapshot(), "worker"); |
178 | | - connectionHandler.CreateEntity(entityId, template); |
179 | | - receiveSystem.Update(); |
180 | | - |
181 | | - var gameObject = new GameObject("TestGameObject"); |
182 | | - gameObject.AddComponent<T>(); |
183 | | - gameObject.GetComponent<T>().enabled = false; |
184 | | - |
185 | | - linker.LinkGameObjectToSpatialOSEntity(new EntityId(entityId), gameObject); |
186 | | - requireLifecycleSystem.Update(); |
187 | | - |
188 | | - return gameObject; |
189 | | - } |
190 | | - |
191 | | - private void RemoveAndUnlinkGameObject(long entityId, GameObject gameObject) |
192 | | - { |
193 | | - connectionHandler.RemoveComponent(entityId, Position.ComponentId); |
194 | | - connectionHandler.RemoveEntity(entityId); |
195 | | - receiveSystem.Update(); |
196 | | - requireLifecycleSystem.Update(); |
197 | | - |
198 | | - Object.DestroyImmediate(gameObject); |
| 185 | + return template; |
199 | 186 | } |
200 | 187 | } |
201 | 188 | } |
0 commit comments