#nullable enable
using System;
using System.Collections.Generic;
using NUnit.Framework;
using ShrinkApp.Starter.Basic;
using ShrinkCommand.Integration.App;
using ShrinkContext;
using ShrinkDataSaver.Integration.App;
using ShrinkNetwork;
using ShrinkNetwork.Integration.App;
using ShrinkApp;
using UnityEngine;
using Object = UnityEngine.Object;
namespace ShrinkContext.AppAdapter.Tests
{
///
/// Basic Starter 默认装配表的端到端验证(阶段 3):
/// 三个功能模块走原生 Cordis 组件,四个跨包集成走按键注入的薄组件;
/// 提供者停用时依赖集成先退出,兼容服务门面也作为可逆效应注销。
///
public class NativeWiringTests
{
[Test]
public void BasicComposition_UsesNativeComponents_AndRetiresDependentsReversibly()
{
var settings = ScriptableObject.CreateInstance();
ShrinkAppLoaderHost? host = null;
try
{
var coreInstallers = new List();
foreach (var installerType in ShrinkAppInstallers.GetDiscoveredInstallerTypes())
{
if (Activator.CreateInstance(installerType) is not IShrinkAppModuleInstaller installer)
continue;
if (installer.ModuleId is "shrink.network" or "shrink.command" or "shrink.datasaver")
coreInstallers.Add(installer);
}
host = new ShrinkAppLoaderHost(settings, coreInstallers);
ShrinkAppBasicContextComposition.Configure(host);
host.ApplyComposition(ShrinkAppBasicContextComposition.CreateDefaultDocument());
TestAwait.Run(host.StartAsync());
Assert.AreEqual(7, host.ModuleIds.Count);
Assert.AreEqual(7, host.ActiveModuleIds.Count);
Assert.IsTrue(host.IsModuleActive("shrink.network"));
Assert.IsTrue(host.IsModuleActive("shrink.command"));
Assert.IsTrue(host.IsModuleActive("shrink.datasaver"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.command-network"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.command-eventbus"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.datasaver-eventbus"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.network-eventbus"));
var root = host.Context.RootContext;
Assert.IsTrue(host.Context.TryGetRaw(root,
ShrinkNetworkAppComponent.ServiceKey, out _), "网络服务键由原生组件提供");
Assert.IsTrue(host.Context.TryGetRaw(root,
ShrinkCommandAppComponent.ServiceKey, out _), "命令服务键由原生组件提供");
Assert.IsTrue(host.Context.TryGetRaw