From fcb1b4b6848b90f81118d25c9f6c86f9733799ff Mon Sep 17 00:00:00 2001 From: Bryan Wong Date: Tue, 11 Aug 2020 10:05:23 +0100 Subject: [PATCH] UTY-2533: add commands tests for subscription (#1448) This commit adds a couple of tests for the subscription system when sending commands. --- .../Correctness/Subscriptions/CommandTests.cs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/workers/unity/Assets/Tests/EditmodeTests/Correctness/Subscriptions/CommandTests.cs b/workers/unity/Assets/Tests/EditmodeTests/Correctness/Subscriptions/CommandTests.cs index 4035c93feb..675b2abbe6 100644 --- a/workers/unity/Assets/Tests/EditmodeTests/Correctness/Subscriptions/CommandTests.cs +++ b/workers/unity/Assets/Tests/EditmodeTests/Correctness/Subscriptions/CommandTests.cs @@ -40,6 +40,35 @@ public void SubscriptionSystem_invokes_callback_on_receiving_response() }); } + [Test] + public void SubscriptionSystem_does_not_invoke_callback_when_gameobject_is_unlinked() + { + World.Step(world => + { + world.Connection.CreateEntity(EntityId, GetTemplate()); + }) + .Step(world => + { + return world.CreateGameObject(EntityId).Item2; + }) + .Step((world, mono) => + { + mono.Sender.SendTestCommand(GetRequest(), response => throw new AssertionException("Don't call")); + }) + .Step((world, mono) => + { + world.Linker.UnlinkGameObjectFromEntity(new EntityId(EntityId), mono.gameObject); + }) + .Step(world => + { + world.Connection.GenerateResponses(ResponseGenerator); + }) + .Step((world, mono) => + { + Assert.IsFalse(mono.enabled); + }); + } + private static TestCommands.Test.ReceivedResponse ResponseGenerator(CommandRequestId id, TestCommands.Test.Request request) { return new TestCommands.Test.ReceivedResponse( @@ -57,8 +86,8 @@ private static TestCommands.Test.ReceivedResponse ResponseGenerator(CommandReque private static EntityTemplate GetTemplate() { var template = new EntityTemplate(); - template.AddComponent(new Position.Snapshot(), "worker"); - template.AddComponent(new TestCommands.Snapshot(), "worker"); + template.AddComponent(new Position.Snapshot()); + template.AddComponent(new TestCommands.Snapshot()); return template; }