RequestEventsInventoryExtensionTests.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.Inventory;
  8. namespace KairoEngine.Inventory.EditorTests
  9. {
  10. public class RequestEventsInventoryExtensionTests
  11. {
  12. private ItemContainer TestItemContainer()
  13. {
  14. GameObject obj = new GameObject();
  15. obj.AddComponent<ItemContainer>();
  16. ItemContainer itemContainer = obj.GetComponent<ItemContainer>();
  17. return itemContainer;
  18. }
  19. private ItemContainer EmptyTestItemContainer() => null;
  20. [Test]
  21. public void RequestEvents_Get_ItemContainer()
  22. {
  23. EventManager.request.Bind("TestItemContainer", TestItemContainer);
  24. EventResponse<ItemContainer> response = EventManager.request.GetItemContainer("TestItemContainer");
  25. Assert.AreEqual(typeof(ItemContainer), response.value.GetType());
  26. Assert.AreEqual(EventResponseStatus.OK, response.status);
  27. }
  28. [Test]
  29. public void RequestEvents_Get_ItemContainer_EmptyResponse()
  30. {
  31. EventManager.request.Bind("EmptyTestItemContainer", EmptyTestItemContainer);
  32. EventResponse<ItemContainer> response = EventManager.request.GetItemContainer("EmptyTestItemContainer");
  33. Assert.IsNull(response.value);
  34. Assert.AreEqual(EventResponseStatus.EmptyResponse, response.status);
  35. }
  36. [Test]
  37. public void RequestEvents_Get_ItemContainer_NotFound()
  38. {
  39. EventResponse<ItemContainer> response = EventManager.request.GetItemContainer("WrongTestItemContainer");
  40. Assert.IsNull(response.value);
  41. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  42. }
  43. [Test]
  44. public void RequestEvents_Unbind_ItemContainer()
  45. {
  46. EventManager.request.Bind("UnbindTestItemContainer", TestItemContainer);
  47. EventResponse<ItemContainer> response = EventManager.request.GetItemContainer("UnbindTestItemContainer");
  48. Assert.AreEqual(true, response.value.GetType() == typeof(ItemContainer));
  49. EventManager.request.Unbind("UnbindTestItemContainer", TestItemContainer);
  50. response = EventManager.request.GetItemContainer("UnbindTestItemContainer");
  51. Assert.IsNull(response.value);
  52. Assert.AreEqual(EventResponseStatus.NotFound, response.status);
  53. }
  54. }
  55. }