GenericEventsCharacterExtensionsTests.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEngine.TestTools;
  6. using KairoEngine.Core;
  7. using KairoEngine.CharacterSystem;
  8. namespace KairoEngine.CharacterSystem.EditorTests
  9. {
  10. public class GenericEventsCharacterExtensionsTests
  11. {
  12. private CharacterController CreateTestCharacter()
  13. {
  14. GameObject obj = new GameObject();
  15. obj.AddComponent<CharacterController>();
  16. CharacterController character = obj.GetComponent<CharacterController>();
  17. return character;
  18. }
  19. private CharacterController CreateEmptyTestCharacter() => null;
  20. private void TestCharacterEvent(CharacterController character)
  21. {
  22. Assert.AreEqual(tempCharacter, character);
  23. }
  24. private CharacterController tempCharacter;
  25. [Test]
  26. public void GenericEvents_StartListening_CharacterController()
  27. {
  28. EventManager.broadcast.StartListening("TestCharacter", TestCharacterEvent);
  29. System.Action<CharacterController> action = null;
  30. bool value = GenericEventsCharacterExtensions.list.TryGetValue("TestCharacter", out action);
  31. Assert.AreEqual(true, value);
  32. }
  33. [Test]
  34. public void GenericEvents_StopListening_CharacterController()
  35. {
  36. EventManager.broadcast.StartListening("TestCharacter", TestCharacterEvent);
  37. System.Action<CharacterController> action1 = null;
  38. GenericEventsCharacterExtensions.list.TryGetValue("TestCharacter", out action1);
  39. Assert.IsNotNull(action1);
  40. EventManager.broadcast.StopListening("TestCharacter", TestCharacterEvent);
  41. System.Action<CharacterController> action2 = null;
  42. GenericEventsCharacterExtensions.list.TryGetValue("TestCharacter", out action2);
  43. Assert.IsNull(action2);
  44. }
  45. [Test]
  46. public void GenericEvents_Trigger_CharacterController()
  47. {
  48. tempCharacter = CreateTestCharacter();
  49. EventManager.broadcast.StartListening("TestCharacter", TestCharacterEvent);
  50. EventManager.broadcast.Trigger("TestCharacter", tempCharacter);
  51. }
  52. [TearDown]
  53. public void TearDown()
  54. {
  55. EventManager.broadcast.StopListening("TestCharacter", TestCharacterEvent);
  56. tempCharacter = null;
  57. }
  58. }
  59. }