Skip to content

Commit 9268dc5

Browse files
committed
Updated utilities
1 parent 333cb5b commit 9268dc5

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Assets/Plugins/AdncUtility/Scripts/Testing.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Reflection;
2+
3+
namespace Adnc.Utility.Testing {
4+
public class TestBase {
5+
protected void CallSetup<T> (T target) {
6+
CallPrivateMethod(target, "Awake");
7+
CallPrivateMethod(target, "Start");
8+
CallPrivateMethod(target, "OnEnabled");
9+
}
10+
11+
protected void CallDestroy<T> (T target) {
12+
CallPrivateMethod(target, "OnDisable");
13+
CallPrivateMethod(target, "OnDestroy");
14+
}
15+
16+
protected void CallPrivateMethod<T> (T target, string method) {
17+
var type = typeof(T);
18+
var methodInfo = type.GetMethod(method, BindingFlags.NonPublic | BindingFlags.Instance);
19+
20+
if (methodInfo != null) {
21+
methodInfo.Invoke(target, null);
22+
}
23+
}
24+
25+
protected F GetPrivateField<T, F> (T target, string field) {
26+
var type = typeof(T);
27+
var f = type.GetField(field, BindingFlags.NonPublic | BindingFlags.Instance);
28+
29+
if (f != null) {
30+
return (F)f.GetValue(target);
31+
}
32+
33+
return default(F);
34+
}
35+
36+
protected void SetPrivateField<T, V> (T target, string field, V value) {
37+
var type = typeof(T);
38+
var f = type.GetField(field, BindingFlags.NonPublic | BindingFlags.Instance);
39+
40+
if (f != null) {
41+
f.SetValue(target, value);
42+
}
43+
}
44+
}
45+
}

Assets/Plugins/AdncUtility/Scripts/Testing/TestBase.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)