GenericEventsInventoryExtensionTests.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. namespace KairoEngine.Inventory.EditorTests
  8. {
  9. public class GenericEventsInventoryExtensionsTests
  10. {
  11. private void TestEvent(ItemContainer itemContainer, ItemRef itemRef)
  12. {
  13. Assert.NotNull(itemContainer);
  14. Assert.NotNull(itemRef);
  15. }
  16. [Test]
  17. public void GenericEvents_StartListening_ItemContainer_ItemRef()
  18. {
  19. EventManager.broadcast.StartListening("TestEvent", TestEvent);
  20. System.Action<ItemContainer, ItemRef> action = null;
  21. bool value = GenericEventsInventoryExtensions.list.TryGetValue("TestEvent", out action);
  22. Assert.AreEqual(true, value);
  23. }
  24. [Test]
  25. public void GenericEvents_StopListening_CharacterController()
  26. {
  27. EventManager.broadcast.StartListening("TestEvent", TestEvent);
  28. System.Action<ItemContainer, ItemRef> action1 = null;
  29. GenericEventsInventoryExtensions.list.TryGetValue("TestEvent", out action1);
  30. Assert.IsNotNull(action1);
  31. EventManager.broadcast.StopListening("TestEvent", TestEvent);
  32. System.Action<ItemContainer, ItemRef> action2 = null;
  33. GenericEventsInventoryExtensions.list.TryGetValue("TestEvent", out action2);
  34. Assert.IsNull(action2);
  35. }
  36. [Test]
  37. public void GenericEvents_Trigger_CharacterController()
  38. {
  39. EventManager.broadcast.StartListening("TestEvent", TestEvent);
  40. GameObject obj = new GameObject();
  41. obj.AddComponent<ItemContainer>();
  42. ItemContainer itemContainer = obj.GetComponent<ItemContainer>();
  43. ItemRef itemRef = new ItemRef(null, 1, 1000);
  44. EventManager.broadcast.Trigger("TestEvent", itemContainer, itemRef);
  45. }
  46. [TearDown]
  47. public void TearDown()
  48. {
  49. EventManager.broadcast.StopListening("TestEvent", TestEvent);
  50. }
  51. }
  52. }