12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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>();
- CharacterController character = obj.GetComponent<CharacterController>();
- 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<CharacterController> 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<CharacterController> action1 = null;
- GenericEventsCharacterExtensions.list.TryGetValue("TestCharacter", out action1);
- Assert.IsNotNull(action1);
- EventManager.broadcast.StopListening("TestCharacter", TestCharacterEvent);
- System.Action<CharacterController> 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;
- }
- }
- }
|