From 03c73a8ee50e22825b5b9bbe63e128f2a2570a6b Mon Sep 17 00:00:00 2001 From: gewuyou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 25 Apr 2026 10:18:40 +0800 Subject: [PATCH] =?UTF-8?q?test(core-tests):=20=E6=94=B6=E6=95=9B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=A1=A9=E4=B8=8E=E8=BE=85=E5=8A=A9=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 ArchitectureContext、ArchitectureServices、GameContext 与环境测试桩的异常类型以满足 analyzer 约束 - 补齐 AsyncTestModel 与 AsyncTestSystem 的异步等待配置并保持测试语义不变 - 调整 ResultTests 的异类异常断言样例以避免新增编译与 analyzer 噪音 --- .../Architectures/ArchitectureContextTests.cs | 2 +- .../ArchitectureServicesTests.cs | 20 +++++++++---------- .../Architectures/GameContextTests.cs | 20 +++++++++---------- .../Functional/ResultTests.cs | 2 +- GFramework.Core.Tests/Model/AsyncTestModel.cs | 4 ++-- .../ContextAwareEnvironmentExtensionsTests.cs | 6 +++--- .../Systems/AsyncTestSystem.cs | 4 ++-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs b/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs index 584090ab..685655a5 100644 --- a/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs +++ b/GFramework.Core.Tests/Architectures/ArchitectureContextTests.cs @@ -339,7 +339,7 @@ public class ArchitectureContextTests { workersReady.Signal(); startGate.Wait(); - return await context.SendRequestAsync(new TestCqrsRequest()); + return await context.SendRequestAsync(new TestCqrsRequest()).ConfigureAwait(false); })) .ToArray(); diff --git a/GFramework.Core.Tests/Architectures/ArchitectureServicesTests.cs b/GFramework.Core.Tests/Architectures/ArchitectureServicesTests.cs index 52c2ecbd..4a520097 100644 --- a/GFramework.Core.Tests/Architectures/ArchitectureServicesTests.cs +++ b/GFramework.Core.Tests/Architectures/ArchitectureServicesTests.cs @@ -351,12 +351,12 @@ public class TestArchitectureContextV3 : IArchitectureContext public ValueTask SendRequestAsync(IRequest request, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public TResponse SendRequest(IRequest request) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -371,7 +371,7 @@ public class TestArchitectureContextV3 : IArchitectureContext GFramework.Cqrs.Abstractions.Cqrs.Command.ICommand command, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -383,7 +383,7 @@ public class TestArchitectureContextV3 : IArchitectureContext /// 该测试桩未实现此成员。 public TResponse SendCommand(GFramework.Cqrs.Abstractions.Cqrs.Command.ICommand command) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -398,7 +398,7 @@ public class TestArchitectureContextV3 : IArchitectureContext GFramework.Cqrs.Abstractions.Cqrs.Query.IQuery query, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -410,32 +410,32 @@ public class TestArchitectureContextV3 : IArchitectureContext /// 该测试桩未实现此成员。 public TResponse SendQuery(GFramework.Cqrs.Abstractions.Cqrs.Query.IQuery query) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public ValueTask PublishAsync(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification { - throw new NotImplementedException(); + throw new NotSupportedException(); } public IAsyncEnumerable CreateStream( IStreamRequest request, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public ValueTask SendAsync(TCommand command, CancellationToken cancellationToken = default) where TCommand : IRequest { - throw new NotImplementedException(); + throw new NotSupportedException(); } public ValueTask SendAsync(IRequest command, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } public void SendCommand(ICommand command) diff --git a/GFramework.Core.Tests/Architectures/GameContextTests.cs b/GFramework.Core.Tests/Architectures/GameContextTests.cs index 9b990e78..4f9b99e3 100644 --- a/GFramework.Core.Tests/Architectures/GameContextTests.cs +++ b/GFramework.Core.Tests/Architectures/GameContextTests.cs @@ -405,7 +405,7 @@ public class TestArchitectureContext : IArchitectureContext public ValueTask SendRequestAsync(IRequest request, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -417,7 +417,7 @@ public class TestArchitectureContext : IArchitectureContext /// 该测试桩未实现此成员。 public TResponse SendRequest(IRequest request) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -432,7 +432,7 @@ public class TestArchitectureContext : IArchitectureContext GFramework.Cqrs.Abstractions.Cqrs.Command.ICommand command, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -444,7 +444,7 @@ public class TestArchitectureContext : IArchitectureContext /// 该测试桩未实现此成员。 public TResponse SendCommand(GFramework.Cqrs.Abstractions.Cqrs.Command.ICommand command) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -459,7 +459,7 @@ public class TestArchitectureContext : IArchitectureContext GFramework.Cqrs.Abstractions.Cqrs.Query.IQuery query, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -471,7 +471,7 @@ public class TestArchitectureContext : IArchitectureContext /// 该测试桩未实现此成员。 public TResponse SendQuery(GFramework.Cqrs.Abstractions.Cqrs.Query.IQuery query) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -485,7 +485,7 @@ public class TestArchitectureContext : IArchitectureContext public ValueTask PublishAsync(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -500,7 +500,7 @@ public class TestArchitectureContext : IArchitectureContext IStreamRequest request, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -514,7 +514,7 @@ public class TestArchitectureContext : IArchitectureContext public ValueTask SendAsync(TCommand command, CancellationToken cancellationToken = default) where TCommand : IRequest { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// @@ -528,7 +528,7 @@ public class TestArchitectureContext : IArchitectureContext public ValueTask SendAsync(IRequest command, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + throw new NotSupportedException(); } /// diff --git a/GFramework.Core.Tests/Functional/ResultTests.cs b/GFramework.Core.Tests/Functional/ResultTests.cs index e3a3ad28..cb5ed8bd 100644 --- a/GFramework.Core.Tests/Functional/ResultTests.cs +++ b/GFramework.Core.Tests/Functional/ResultTests.cs @@ -329,7 +329,7 @@ public class ResultTests { // Arrange var result1 = Result.Failure(new InvalidOperationException("Error")); - var result2 = Result.Failure(new ArgumentException("Error")); + var result2 = Result.Failure(new InvalidCastException("Error")); // Act & Assert Assert.That(result1.Equals(result2), Is.False); diff --git a/GFramework.Core.Tests/Model/AsyncTestModel.cs b/GFramework.Core.Tests/Model/AsyncTestModel.cs index bf2ee9f2..f2b2d56c 100644 --- a/GFramework.Core.Tests/Model/AsyncTestModel.cs +++ b/GFramework.Core.Tests/Model/AsyncTestModel.cs @@ -20,7 +20,7 @@ public sealed class AsyncTestModel : AbstractModel, IAsyncInitializable /// 表示异步操作的Task public async Task InitializeAsync() { - await Task.Delay(10); + await Task.Delay(10).ConfigureAwait(false); Initialized = true; } @@ -45,4 +45,4 @@ public sealed class AsyncTestModel : AbstractModel, IAsyncInitializable protected override void OnInit() { } -} \ No newline at end of file +} diff --git a/GFramework.Core.Tests/Rule/ContextAwareEnvironmentExtensionsTests.cs b/GFramework.Core.Tests/Rule/ContextAwareEnvironmentExtensionsTests.cs index 31b8b718..4fb94ed1 100644 --- a/GFramework.Core.Tests/Rule/ContextAwareEnvironmentExtensionsTests.cs +++ b/GFramework.Core.Tests/Rule/ContextAwareEnvironmentExtensionsTests.cs @@ -93,7 +93,7 @@ public class ContextAwareEnvironmentExtensionsTests return false; } - public T GetRequired(string key) where T : class => throw new NotImplementedException(); + public T GetRequired(string key) where T : class => throw new NotSupportedException(); public void Register(string key, object value) { @@ -115,7 +115,7 @@ public class ContextAwareEnvironmentExtensionsTests return false; } - public T GetRequired(string key) where T : class => throw new NotImplementedException(); + public T GetRequired(string key) where T : class => throw new NotSupportedException(); public void Register(string key, object value) { @@ -129,4 +129,4 @@ public class ContextAwareEnvironmentExtensionsTests private class TestContextAware : ContextAwareBase { } -} \ No newline at end of file +} diff --git a/GFramework.Core.Tests/Systems/AsyncTestSystem.cs b/GFramework.Core.Tests/Systems/AsyncTestSystem.cs index 2b715bc3..3e2880ad 100644 --- a/GFramework.Core.Tests/Systems/AsyncTestSystem.cs +++ b/GFramework.Core.Tests/Systems/AsyncTestSystem.cs @@ -16,7 +16,7 @@ public sealed class AsyncTestSystem : ISystem, IAsyncInitializable public async Task InitializeAsync() { - await Task.Delay(10); + await Task.Delay(10).ConfigureAwait(false); Initialized = true; } @@ -44,4 +44,4 @@ public sealed class AsyncTestSystem : ISystem, IAsyncInitializable public void OnArchitecturePhase(ArchitecturePhase phase) { } -} \ No newline at end of file +}