using System.Collections; using System.Collections.Generic; using NUnit.Framework; using UnityEngine; using UnityEngine.TestTools; using KairoEngine.Core; using KairoEngine.CharacterSystem; namespace KairoEngine.CharacterSystem.EditorTests { public class GenericEventsCharacterExtensionsTests { private CharacterController CreateTestCharacter() { GameObject obj = new GameObject(); obj.AddComponent(); CharacterController character = obj.GetComponent(); return character; } private CharacterController CreateEmptyTestCharacter() => null; private void TestCharacterEvent(CharacterController character) { Assert.AreEqual(tempCharacter, character); } private CharacterController tempCharacter; [Test] public void GenericEvents_StartListening_CharacterController() { EventManager.broadcast.StartListening("TestCharacter", TestCharacterEvent); System.Action action = null; bool value = GenericEventsCharacterExtensions.list.TryGetValue("TestCharacter", out action); Assert.AreEqual(true, value); } [Test] public void GenericEvents_StopListening_CharacterController() { EventManager.broadcast.StartListening("TestCharacter", TestCharacterEvent); System.Action action1 = null; GenericEventsCharacterExtensions.list.TryGetValue("TestCharacter", out action1); Assert.IsNotNull(action1); EventManager.broadcast.StopListening("TestCharacter", TestCharacterEvent); System.Action action2 = null; GenericEventsCharacterExtensions.list.TryGetValue("TestCharacter", out action2); Assert.IsNull(action2); } [Test] public void GenericEvents_Trigger_CharacterController() { tempCharacter = CreateTestCharacter(); EventManager.broadcast.StartListening("TestCharacter", TestCharacterEvent); EventManager.broadcast.Trigger("TestCharacter", tempCharacter); } [TearDown] public void TearDown() { EventManager.broadcast.StopListening("TestCharacter", TestCharacterEvent); tempCharacter = null; } } }