feat: make Unity integration optional
This commit is contained in:
27 files changed
+916
-69
No files matched your search
@@ -0,0 +1,43 @@
|
||||
#if SHRINK_EVENTBUS_HAS_SHARED_RUNTIME
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using ShrinkSDK.Runtime;
|
||||
|
||||
namespace ShrinkEventBus.Integration.Tests
|
||||
{
|
||||
public sealed class SharedDispatcherTests
|
||||
{
|
||||
private sealed class Dispatcher : IShrinkMainThreadDispatcher
|
||||
{
|
||||
public bool IsMainThread => false;
|
||||
public Action Pending;
|
||||
public bool TryPost(Action action) { Pending = action; return true; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AdapterPreservesAffinityAndPostsThroughSharedDispatcher()
|
||||
{
|
||||
var original = ShrinkEventBusRuntime.MainThreadDispatcher;
|
||||
try
|
||||
{
|
||||
var dispatcher = new Dispatcher();
|
||||
var adapter = new ShrinkSharedMainThreadDispatcher(dispatcher);
|
||||
ShrinkEventBusRuntime.ConfigureMainThreadDispatcher(adapter);
|
||||
Assert.IsFalse(ShrinkEventBusRuntime.MainThreadDispatcher.IsMainThread);
|
||||
var hits = 0;
|
||||
Assert.IsTrue(ShrinkEventBusRuntime.MainThreadDispatcher.TryPost(() => hits++));
|
||||
Assert.AreEqual(0, hits);
|
||||
dispatcher.Pending();
|
||||
Assert.AreEqual(1, hits);
|
||||
}
|
||||
finally { ShrinkEventBusRuntime.ConfigureMainThreadDispatcher(original); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AdapterRejectsNullDispatcher()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ShrinkSharedMainThreadDispatcher(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user