- 将 ShrinkEventBus、ShrinkDataSaver 及其 EventBus 集成从 gitlink 转为仓库直接维护的完整 UPM 包,补齐运行时、编辑器工具、测试与文档 - 新增 Command 和 Network 的 App 集成组件,支持 ContextLoader 服务发布、可逆注销及 Network Loopback 生命周期管理 - 更新 Starter 与演示组合逻辑,缺失模块时可注册、已有兼容安装器时可覆盖,并补充宿主启动断言 - 升级内部包依赖与 Shared CodeGen 包定义,放宽 Integration.App 包的 Git 忽略规则 - 将独立服务器生成器改为基于已编译程序集的语义扫描,支持 partial、复杂泛型、命名冲突检测及模板 SHA-256 覆写保护 - 新增 Network 语义扫描、模板保护和 App 组件生命周期测试 - 新增真实 UPM 消费工程验证脚本,校验内部版本一致性、程序集加载及 EditMode 测试 - 重构当前架构文档并归档已完成的 Cordis 迁移与旧代码地图
95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace ShrinkEventBus.Tests
|
|
{
|
|
[TestFixture]
|
|
public sealed class EventBusSubscriptionTests
|
|
{
|
|
private sealed class SampleEvent : EventBase
|
|
{
|
|
public int Value { get; set; }
|
|
}
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
EventBus.UnregisterAllEvents();
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
EventBus.UnregisterAllEvents();
|
|
}
|
|
|
|
[Test]
|
|
public void SubscribeEvent_Dispose_RemovesOnlyOwnedSubscription()
|
|
{
|
|
var firstHits = 0;
|
|
var secondHits = 0;
|
|
|
|
using var first = EventBus.SubscribeEvent<SampleEvent>(_ => firstHits++);
|
|
using var second = EventBus.SubscribeEvent<SampleEvent>(_ => secondHits++);
|
|
|
|
EventBus.TriggerEvent(new SampleEvent());
|
|
Assert.AreEqual(1, firstHits);
|
|
Assert.AreEqual(1, secondHits);
|
|
|
|
first.Dispose();
|
|
|
|
EventBus.TriggerEvent(new SampleEvent());
|
|
Assert.AreEqual(1, firstHits);
|
|
Assert.AreEqual(2, secondHits);
|
|
}
|
|
|
|
[Test]
|
|
public void ActiveSubscriptionSnapshot_ContainsExpectedMetadata()
|
|
{
|
|
using var subscription = EventBus.SubscribeEvent<SampleEvent>(_ => { }, EventPriority.HIGH, true);
|
|
|
|
var snapshots = EventBus.GetActiveSubscriptionsSnapshot();
|
|
|
|
Assert.AreEqual(1, snapshots.Count);
|
|
Assert.AreEqual(subscription.SubscriptionId, snapshots[0].SubscriptionId);
|
|
Assert.AreEqual(typeof(SampleEvent), snapshots[0].EventType);
|
|
Assert.AreEqual(EventPriority.HIGH, snapshots[0].Priority);
|
|
Assert.IsTrue(snapshots[0].ReceiveCanceled);
|
|
Assert.IsFalse(string.IsNullOrWhiteSpace(snapshots[0].MethodName));
|
|
}
|
|
|
|
[Test]
|
|
public void RegisterEvent_StillWorksWithoutDisposableSubscription()
|
|
{
|
|
var hits = 0;
|
|
|
|
void Handler(SampleEvent evt)
|
|
{
|
|
hits += evt.Value;
|
|
}
|
|
|
|
EventBus.RegisterEvent<SampleEvent>(Handler);
|
|
EventBus.TriggerEvent(new SampleEvent { Value = 3 });
|
|
|
|
Assert.AreEqual(3, hits);
|
|
|
|
EventBus.UnregisterEvent<SampleEvent>(Handler);
|
|
EventBus.TriggerEvent(new SampleEvent { Value = 5 });
|
|
|
|
Assert.AreEqual(3, hits);
|
|
}
|
|
|
|
[Test]
|
|
public void ActiveSubscriptionSnapshot_EmptyAfterDispose()
|
|
{
|
|
var subscription = EventBus.SubscribeEvent<SampleEvent>(_ => Debug.Log("noop"));
|
|
subscription.Dispose();
|
|
|
|
var snapshots = EventBus.GetActiveSubscriptionsSnapshot();
|
|
|
|
Assert.AreEqual(0, snapshots.Count);
|
|
Assert.IsTrue(subscription.IsDisposed);
|
|
}
|
|
}
|
|
}
|