补齐 package Tests 第一刀

This commit is contained in:
JSD\13999
2026-06-06 16:14:17 +08:00
parent 0930e7c173
commit 7b2243a40b
13 changed files with 334 additions and 169 deletions

View File

@@ -0,0 +1,70 @@
using System.Threading;
using System.Threading.Tasks;
using FlowScope.Addressables;
using FlowScope.Container;
using FlowScope.Resources;
using NUnit.Framework;
namespace FlowScope.PackageTests.EditMode
{
public sealed class PackageSmokeTests
{
[Test]
public void PackageAssemblies_CanBeReferencedFromPackageTests()
{
var container = new Container();
var backend = new AddressablesResourceBackend();
IResourceService resources = new ResourceService(new ImmediateBackend());
container.RegisterInstance(resources);
Assert.AreEqual("Addressables", backend.Name);
Assert.AreSame(resources, container.Resolve<IResourceService>());
container.Dispose();
}
[Test]
public void ResourceService_LoadAsync_CanRunInsidePackageTestAssembly()
{
var backend = new ImmediateBackend();
var service = new ResourceService(backend);
using var handle = service
.LoadAsync<TestAsset>("package-smoke", CancellationToken.None)
.GetAwaiter()
.GetResult();
Assert.That(handle.Asset, Is.Not.Null);
Assert.AreEqual(1, backend.LoadCalls);
handle.Dispose();
Assert.AreEqual(1, backend.ReleaseCalls);
}
private sealed class ImmediateBackend : IResourceBackend
{
public string Name => "Immediate";
public int LoadCalls { get; private set; }
public int ReleaseCalls { get; private set; }
public Task<T> LoadAsync<T>(string key, CancellationToken cancellationToken)
where T : class
{
LoadCalls++;
return Task.FromResult(new TestAsset() as T);
}
public void Release<T>(string key, T asset)
where T : class
{
ReleaseCalls++;
}
}
private sealed class TestAsset
{
}
}
}