Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GFramework.Core.Tests.Architectures;

/// <summary>
/// 表示用于验证上下文类型不匹配分支的测试架构上下文。
/// </summary>
public class AnotherTestArchitectureContext : TestArchitectureContext
{
}
212 changes: 0 additions & 212 deletions GFramework.Core.Tests/Architectures/ArchitectureServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,215 +262,3 @@ public void ModuleManager_Should_Not_Be_Null()
Assert.That(_services!.ModuleManager, Is.Not.Null);
}
}

#region Test Classes

public class TestArchitectureContextV3 : IArchitectureContext
{
private readonly MicrosoftDiContainer _container = new();
private readonly DefaultEnvironment _environment = new();
public int Id { get; init; }

public TService? GetService<TService>() where TService : class
{
return _container.Get<TService>();
}

public IReadOnlyList<TService> GetServices<TService>() where TService : class
{
return _container.GetAll<TService>();
}

public TModel? GetModel<TModel>() where TModel : class, IModel
{
return _container.Get<TModel>();
}

public IReadOnlyList<TModel> GetModels<TModel>() where TModel : class, IModel
{
return _container.GetAll<TModel>();
}

public TSystem? GetSystem<TSystem>() where TSystem : class, ISystem
{
return _container.Get<TSystem>();
}

public IReadOnlyList<TSystem> GetSystems<TSystem>() where TSystem : class, ISystem
{
return _container.GetAll<TSystem>();
}

public TUtility? GetUtility<TUtility>() where TUtility : class, IUtility
{
return _container.Get<TUtility>();
}

public IReadOnlyList<TUtility> GetUtilities<TUtility>() where TUtility : class, IUtility
{
return _container.GetAll<TUtility>();
}

public IReadOnlyList<TService> GetServicesByPriority<TService>() where TService : class
{
return _container.GetAllByPriority<TService>();
}

public IReadOnlyList<TSystem> GetSystemsByPriority<TSystem>() where TSystem : class, ISystem
{
return _container.GetAllByPriority<TSystem>();
}

public IReadOnlyList<TModel> GetModelsByPriority<TModel>() where TModel : class, IModel
{
return _container.GetAllByPriority<TModel>();
}

public IReadOnlyList<TUtility> GetUtilitiesByPriority<TUtility>() where TUtility : class, IUtility
{
return _container.GetAllByPriority<TUtility>();
}

public void SendEvent<TEvent>() where TEvent : new()
{
}

public void SendEvent<TEvent>(TEvent e) where TEvent : class
{
}

public IUnRegister RegisterEvent<TEvent>(Action<TEvent> handler)
{
return new DefaultUnRegister(() => { });
}

public void UnRegisterEvent<TEvent>(Action<TEvent> onEvent)
{
}

public ValueTask<TResponse> SendRequestAsync<TResponse>(IRequest<TResponse> request,
CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}

public TResponse SendRequest<TResponse>(IRequest<TResponse> request)
{
throw new NotSupportedException();
}

/// <summary>
/// 测试桩:异步发送 CQRS 命令并返回响应。
/// </summary>
/// <typeparam name="TResponse">命令响应类型。</typeparam>
/// <param name="command">要发送的命令。</param>
/// <param name="cancellationToken">取消令牌。</param>
/// <returns>命令响应任务。</returns>
/// <exception cref="NotSupportedException">该测试桩不支持此成员。</exception>
public ValueTask<TResponse> SendCommandAsync<TResponse>(
GFramework.Cqrs.Abstractions.Cqrs.Command.ICommand<TResponse> command,
CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}

/// <summary>
/// 测试桩:同步发送 CQRS 命令并返回响应。
/// </summary>
/// <typeparam name="TResponse">命令响应类型。</typeparam>
/// <param name="command">要发送的命令。</param>
/// <returns>命令响应。</returns>
/// <exception cref="NotSupportedException">该测试桩不支持此成员。</exception>
public TResponse SendCommand<TResponse>(GFramework.Cqrs.Abstractions.Cqrs.Command.ICommand<TResponse> command)
{
throw new NotSupportedException();
}

/// <summary>
/// 测试桩:异步发送 CQRS 查询并返回结果。
/// </summary>
/// <typeparam name="TResponse">查询结果类型。</typeparam>
/// <param name="query">要发送的查询。</param>
/// <param name="cancellationToken">取消令牌。</param>
/// <returns>查询结果任务。</returns>
/// <exception cref="NotSupportedException">该测试桩不支持此成员。</exception>
public ValueTask<TResponse> SendQueryAsync<TResponse>(
GFramework.Cqrs.Abstractions.Cqrs.Query.IQuery<TResponse> query,
CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}

/// <summary>
/// 测试桩:同步发送 CQRS 查询并返回结果。
/// </summary>
/// <typeparam name="TResponse">查询结果类型。</typeparam>
/// <param name="query">要发送的查询。</param>
/// <returns>查询结果。</returns>
/// <exception cref="NotSupportedException">该测试桩不支持此成员。</exception>
public TResponse SendQuery<TResponse>(GFramework.Cqrs.Abstractions.Cqrs.Query.IQuery<TResponse> query)
{
throw new NotSupportedException();
}

public ValueTask PublishAsync<TNotification>(TNotification notification,
CancellationToken cancellationToken = default) where TNotification : INotification
{
throw new NotSupportedException();
}

public IAsyncEnumerable<TResponse> CreateStream<TResponse>(
IStreamRequest<TResponse> request,
CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}

public ValueTask SendAsync<TCommand>(TCommand command, CancellationToken cancellationToken = default)
where TCommand : IRequest<Unit>
{
throw new NotSupportedException();
}

public ValueTask<TResponse> SendAsync<TResponse>(IRequest<TResponse> command,
CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}

public void SendCommand(ICommand command)
{
}

public TResult SendCommand<TResult>(Abstractions.Command.ICommand<TResult> command)
{
return default!;
}

public Task SendCommandAsync(IAsyncCommand command)
{
return Task.CompletedTask;
}

public Task<TResult> SendCommandAsync<TResult>(IAsyncCommand<TResult> command)
{
return (Task<TResult>)Task.CompletedTask;
}

public TResult SendQuery<TResult>(Abstractions.Query.IQuery<TResult> query)
{
return default!;
}

public Task<TResult> SendQueryAsync<TResult>(IAsyncQuery<TResult> query)
{
return (Task<TResult>)Task.CompletedTask;
}

public IEnvironment GetEnvironment()
{
return _environment;
}
}

#endregion
7 changes: 0 additions & 7 deletions GFramework.Core.Tests/Architectures/ContextProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,3 @@ public void ScopedContextProvider_TryGetContext_Should_Support_Interface_Type()
Assert.That(foundContext, Is.SameAs(context));
}
}

/// <summary>
/// 另一个测试用的架构上下文类,用于测试类型不匹配的情况
/// </summary>
public class AnotherTestArchitectureContext : TestArchitectureContext
{
}
Loading
Loading