Skip to content

Commit 92c927b

Browse files
committed
Added extra test case
1 parent 8262eaf commit 92c927b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Tests/Runtime/DummyBehaviour.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using UnityEngine;
1+
using System;
2+
using TNRD.Events;
3+
using UnityEngine;
24

35
public class DummyBehaviour : MonoBehaviour
46
{
@@ -9,6 +11,14 @@ public class DummyBehaviour : MonoBehaviour
911
public int Arg1 { get; private set; }
1012
public int Arg2 { get; private set; }
1113

14+
private SafeEvent onExposedEvent;
15+
16+
public event Action OnExposedEvent
17+
{
18+
add => onExposedEvent.Subscribe(value);
19+
remove => onExposedEvent.Unsubscribe(value);
20+
}
21+
1222
public void Dummy()
1323
{
1424
Invoked = true;
@@ -24,4 +34,9 @@ public void Dummy(int arg1, int arg2)
2434
Arg1 = arg1;
2535
Arg2 = arg2;
2636
}
37+
38+
public void DispatchOnExposedEvent()
39+
{
40+
onExposedEvent.Invoke();
41+
}
2742
}

Tests/Runtime/SafeEventTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,25 @@ public IEnumerator Invoke_On_Destroyed_GameObject()
7171
Assert.IsNotNull(exception);
7272
Object.Destroy(holder);
7373
}
74+
75+
[UnityTest]
76+
public IEnumerator Dispatch_Exposed_Action()
77+
{
78+
var holder = new GameObject();
79+
var dummyBehaviour = holder.AddComponent<DummyBehaviour>();
80+
yield return null;
81+
82+
bool invoked = false;
83+
84+
dummyBehaviour.OnExposedEvent += () =>
85+
{
86+
invoked = true;
87+
};
88+
89+
Assert.IsFalse(invoked);
90+
dummyBehaviour.DispatchOnExposedEvent();
91+
Assert.IsTrue(invoked);
92+
93+
Object.Destroy(holder);
94+
}
7495
}

0 commit comments

Comments
 (0)