123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System.Collections;
- using System.Collections.Generic;
- using NUnit.Framework;
- using UnityEngine;
- using UnityEngine.TestTools;
- using KairoEngine.Core;
- namespace KairoEngine.Inventory.EditorTests
- {
- public class GenericEventsInventoryExtensionsTests
- {
- private void TestEvent(ItemContainer itemContainer, ItemRef itemRef)
- {
- Assert.NotNull(itemContainer);
- Assert.NotNull(itemRef);
- }
-
- [Test]
- public void GenericEvents_StartListening_ItemContainer_ItemRef()
- {
- EventManager.broadcast.StartListening("TestEvent", TestEvent);
- System.Action<ItemContainer, ItemRef> action = null;
- bool value = GenericEventsInventoryExtensions.list.TryGetValue("TestEvent", out action);
- Assert.AreEqual(true, value);
- }
- [Test]
- public void GenericEvents_StopListening_CharacterController()
- {
- EventManager.broadcast.StartListening("TestEvent", TestEvent);
- System.Action<ItemContainer, ItemRef> action1 = null;
- GenericEventsInventoryExtensions.list.TryGetValue("TestEvent", out action1);
- Assert.IsNotNull(action1);
- EventManager.broadcast.StopListening("TestEvent", TestEvent);
- System.Action<ItemContainer, ItemRef> action2 = null;
- GenericEventsInventoryExtensions.list.TryGetValue("TestEvent", out action2);
- Assert.IsNull(action2);
- }
- [Test]
- public void GenericEvents_Trigger_CharacterController()
- {
- EventManager.broadcast.StartListening("TestEvent", TestEvent);
- GameObject obj = new GameObject();
- obj.AddComponent<ItemContainer>();
- ItemContainer itemContainer = obj.GetComponent<ItemContainer>();
- ItemRef itemRef = new ItemRef(null, 1, 1000);
- EventManager.broadcast.Trigger("TestEvent", itemContainer, itemRef);
- }
- [TearDown]
- public void TearDown()
- {
- EventManager.broadcast.StopListening("TestEvent", TestEvent);
- }
- }
- }
|