feat: make Unity integration optional
This commit is contained in:
27 files changed
+916
-69
No files matched your search
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using ShrinkEventBus;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace EventBusConsumer
|
||||
{
|
||||
internal readonly struct Ping : IShrinkEvent { }
|
||||
|
||||
[ShrinkEventSubscriber]
|
||||
internal sealed class Subscriber
|
||||
{
|
||||
public int SyncHits;
|
||||
public int AsyncHits;
|
||||
[ShrinkSubscribe] private void OnPing(Ping value) => SyncHits++;
|
||||
[ShrinkSubscribe] private async UniTask OnPingAsync(Ping value, CancellationToken token)
|
||||
{
|
||||
await UniTask.Yield(cancellationToken: token);
|
||||
AsyncHits++;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConsumerTests
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator ConsumerAssemblyGeneratesBindingsAndDisposesThem()
|
||||
{
|
||||
using var host = new ShrinkEventBusHost();
|
||||
var bus = host.CreateBus(ShrinkBusKey.Game, ShrinkBusOptions.Inline());
|
||||
var target = new Subscriber();
|
||||
Assert.IsInstanceOf<IShrinkGeneratedSubscriber>(target);
|
||||
var binding = host.Attach(target, ShrinkBusKey.Game);
|
||||
yield return bus.PostAsync(new Ping()).ToCoroutine();
|
||||
Assert.AreEqual(1, target.SyncHits);
|
||||
Assert.AreEqual(1, target.AsyncHits);
|
||||
binding.Dispose();
|
||||
yield return bus.PostAsync(new Ping()).ToCoroutine();
|
||||
Assert.AreEqual(1, target.SyncHits);
|
||||
Assert.AreEqual(1, target.AsyncHits);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "EventBus.Consumer.Tests",
|
||||
"references": [
|
||||
"ShrinkEventBus.Runtime",
|
||||
"UniTask"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
],
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"autoReferenced": false
|
||||
}
|
||||
@@ -1,13 +1,4 @@
|
||||
{
|
||||
"scopedRegistries": [
|
||||
{
|
||||
"name": "ShrinkSDK",
|
||||
"url": "https://git.crash.work/api/packages/ShrinkSDK/npm/",
|
||||
"scopes": [
|
||||
"com.cneicy"
|
||||
]
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"com.unity.test-framework": "1.1.33",
|
||||
"com.cneicy.shrink-eventbus": "file:../../..",
|
||||
|
||||
Reference in new issue
Block a user