引入批量 Job 表、RabbitMQ 队列与消费者,支持导入/小包创建及我的订单批量操作异步化,并提供任务列表、重试失败、取消 pending 与 DLX 监控接口及测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
66 lines
2.7 KiB
C#
66 lines
2.7 KiB
C#
using FluentAssertions;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Moq;
|
|
using Oms.Application.Dtos.Orders;
|
|
using Oms.Application.Messaging;
|
|
using SimpleAdmin.Api.IntegrationTests.Support;
|
|
|
|
namespace SimpleAdmin.Api.IntegrationTests;
|
|
|
|
public class OrderBatchJobApiIntegrationTests
|
|
{
|
|
[Fact]
|
|
public async Task BatchGovernanceRoutes_ShouldBeRegistered()
|
|
{
|
|
await using var host = await SimpleAdminApiTestHost.CreateAsync(configureServices: ConfigureDisabledQueueInspector);
|
|
|
|
host.RoutePatterns.Should().Contain("order/batch/dlx/stats");
|
|
host.RoutePatterns.Should().Contain("order/batch/jobs/{id:int}/retry-failed");
|
|
host.RoutePatterns.Should().Contain("order/batch/jobs/{id:int}/cancel");
|
|
host.RoutePatterns.Should().Contain("order/batch/jobs");
|
|
host.GetHttpMethods("order/batch/dlx/stats").Should().Contain("GET");
|
|
host.GetHttpMethods("order/batch/jobs/{id:int}/retry-failed").Should().Contain("POST");
|
|
host.GetHttpMethods("order/batch/jobs/{id:int}/cancel").Should().Contain("POST");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetBatchDlxStats_ShouldReturnDisabledPayloadWhenQueueDisabled()
|
|
{
|
|
var inspector = new Mock<IOrderBatchQueueInspector>(MockBehavior.Strict);
|
|
inspector.SetupGet(x => x.IsEnabled).Returns(false);
|
|
inspector
|
|
.Setup(x => x.GetStatsAsync(It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(new OrderBatchDlxStatsOutput
|
|
{
|
|
Enabled = false,
|
|
DlxAlertThreshold = 100,
|
|
});
|
|
|
|
await using var host = await SimpleAdminApiTestHost.CreateAsync(configureServices: services =>
|
|
{
|
|
services.RemoveAll<IOrderBatchQueueInspector>();
|
|
services.AddSingleton(inspector.Object);
|
|
});
|
|
|
|
var response = await host.Client.GetAsync("/order/batch/dlx/stats");
|
|
|
|
response.IsSuccessStatusCode.Should().BeTrue();
|
|
var payload = await IntegrationTestJson.ReadAsync<OrderBatchDlxStatsOutput>(response);
|
|
payload.Should().NotBeNull();
|
|
payload!.Enabled.Should().BeFalse();
|
|
payload.DlxAlertThreshold.Should().Be(100);
|
|
}
|
|
|
|
private static void ConfigureDisabledQueueInspector(IServiceCollection services)
|
|
{
|
|
var inspector = new Mock<IOrderBatchQueueInspector>(MockBehavior.Strict);
|
|
inspector.SetupGet(x => x.IsEnabled).Returns(false);
|
|
inspector
|
|
.Setup(x => x.GetStatsAsync(It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(new OrderBatchDlxStatsOutput { Enabled = false });
|
|
services.RemoveAll<IOrderBatchQueueInspector>();
|
|
services.AddSingleton(inspector.Object);
|
|
}
|
|
}
|