RequestEventsTests.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Security.Policy;
  5. using NUnit.Framework;
  6. using UnityEngine;
  7. using UnityEngine.TestTools;
  8. using KairoEngine.Core;
  9. namespace KairoEngine.Core.EditorTests
  10. {
  11. public class RequestEventsTests
  12. {
  13. [Test]
  14. public void RequestEvents_Exists()
  15. {
  16. Assert.AreEqual(true, typeof(RequestEvents) != null);
  17. }
  18. public class Request_bool_with_no_args
  19. {
  20. private bool TestBool() => true;
  21. [Test]
  22. public void RequestEvents_Get_bool()
  23. {
  24. EventManager.request.Bind("TestBool", TestBool);
  25. EventResponse<bool> response = EventManager.request.GetBool("TestBool");
  26. Assert.AreEqual(true, response.value);
  27. Assert.AreEqual(EventResponseStatus.OK, response.status);
  28. }
  29. [Test]
  30. public void RequestEvents_Get_bool_NotFound()
  31. {
  32. EventResponse<bool> response = EventManager.request.GetBool("TestEmptyBool");
  33. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  34. }
  35. [Test]
  36. public void RequestEvents_Unbind_bool()
  37. {
  38. EventManager.request.Bind("UnbindTest", TestBool);
  39. EventResponse<bool> response = EventManager.request.GetBool("UnbindTest");
  40. Assert.AreEqual(true, response.value);
  41. EventManager.request.Unbind("UnbindTest", TestBool);
  42. response = EventManager.request.GetBool("UnbindTest");
  43. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  44. }
  45. }
  46. public class Request_GameObject_with_no_args
  47. {
  48. private GameObject TestGameObject() => GameObject.Instantiate(new GameObject());
  49. private GameObject TestEmptyGameObject() => null;
  50. [Test]
  51. public void RequestEvents_Get_GameObject()
  52. {
  53. EventManager.request.Bind("TestGameObject", TestGameObject);
  54. EventResponse<GameObject> response = EventManager.request.GetGameObject("TestGameObject");
  55. Assert.AreEqual(true, response.value.GetType() == typeof(GameObject));
  56. Assert.AreEqual(EventResponseStatus.OK, response.status);
  57. }
  58. [Test]
  59. public void RequestEvents_Get_GameObject_EmptyResponse()
  60. {
  61. EventManager.request.Bind("TestEmptyGameObject", TestEmptyGameObject);
  62. EventResponse<GameObject> response = EventManager.request.GetGameObject("TestEmptyGameObject");
  63. Assert.IsNull(response.value);
  64. Assert.AreEqual(EventResponseStatus.EmptyResponse, response.status);
  65. }
  66. [Test]
  67. public void RequestEvents_Get_GameObject_NotFound()
  68. {
  69. EventResponse<GameObject> response = EventManager.request.GetGameObject("WrongTestGameObject");
  70. Assert.IsNull(response.value);
  71. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  72. }
  73. [Test]
  74. public void RequestEvents_Unbind_GameObject()
  75. {
  76. EventManager.request.Bind("UnbindGameObjectTest", TestGameObject);
  77. EventResponse<GameObject> response = EventManager.request.GetGameObject("UnbindGameObjectTest");
  78. Assert.AreEqual(true, response.value.GetType() == typeof(GameObject));
  79. EventManager.request.Unbind("UnbindGameObjectTest", TestGameObject);
  80. response = EventManager.request.GetGameObject("UnbindGameObjectTest");
  81. Assert.IsNull(response.value);
  82. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  83. }
  84. }
  85. }
  86. }