RequestEventsCharacterExtensionsTests.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 RequestEventsCharacterExtensionsTests
  11. {
  12. private CharacterController TestCharacter()
  13. {
  14. GameObject obj = new GameObject();
  15. obj.AddComponent<CharacterController>();
  16. CharacterController character = obj.GetComponent<CharacterController>();
  17. return character;
  18. }
  19. private CharacterController EmptyTestCharacter() => null;
  20. [Test]
  21. public void RequestEvents_Get_Character()
  22. {
  23. EventManager.request.Bind("TestCharacter", TestCharacter);
  24. EventResponse<CharacterController> response = EventManager.request.GetCharacterController("TestCharacter");
  25. Assert.AreEqual(typeof(CharacterController), response.value.GetType());
  26. Assert.AreEqual(EventResponseStatus.OK, response.status);
  27. }
  28. [Test]
  29. public void RequestEvents_Get_Character_EmptyResponse()
  30. {
  31. EventManager.request.Bind("EmptyTestCharacter", EmptyTestCharacter);
  32. EventResponse<CharacterController> response = EventManager.request.GetCharacterController("EmptyTestCharacter");
  33. Assert.IsNull(response.value);
  34. Assert.AreEqual(EventResponseStatus.EmptyResponse, response.status);
  35. }
  36. [Test]
  37. public void RequestEvents_Get_Character_NotFound()
  38. {
  39. EventResponse<CharacterController> response = EventManager.request.GetCharacterController("WrongTestCharacter");
  40. Assert.IsNull(response.value);
  41. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  42. }
  43. [Test]
  44. public void RequestEvents_Unbind_Character()
  45. {
  46. EventManager.request.Bind("UnbindTestCharacter", TestCharacter);
  47. EventResponse<CharacterController> response = EventManager.request.GetCharacterController("UnbindTestCharacter");
  48. Assert.AreEqual(true, response.value.GetType() == typeof(CharacterController));
  49. EventManager.request.Unbind("UnbindTestCharacter", TestCharacter);
  50. response = EventManager.request.GetCharacterController("UnbindTestCharacter");
  51. Assert.IsNull(response.value);
  52. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  53. }
  54. }
  55. }