using System.IO; using GFramework.Core.Abstractions.Resource; namespace GFramework.Core.Tests.Resource; /// /// 为 ResourceManager 测试提供可控数据源的资源加载器。 /// public class TestResourceLoader : IResourceLoader { private readonly Dictionary _resourceData = new(StringComparer.Ordinal); /// public TestResource Load(string path) { if (_resourceData.TryGetValue(path, out var content)) { return new TestResource { Content = content }; } throw new FileNotFoundException($"Resource not found: {path}"); } /// public async Task LoadAsync(string path) { await Task.Delay(10).ConfigureAwait(false); // 模拟异步加载 return Load(path); } /// public void Unload(TestResource resource) { resource.IsDisposed = true; } /// public bool CanLoad(string path) { return _resourceData.ContainsKey(path); } /// /// 向测试加载器注册一条可返回的资源数据。 /// /// 资源路径。 /// 资源内容。 public void AddTestData(string path, string content) { _resourceData[path] = content; } }