test(web): add unit tests to verify Hangfire scheduler jobs mapping and cron pattern validation
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
<PackageReference Include="Moq" Version="4.20.70" />
|
||||
<PackageReference Include="Hangfire.Core" Version="1.8.23" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -22,6 +24,7 @@
|
||||
<ProjectReference Include="..\QuantEngine.Core\QuantEngine.Core.csproj" />
|
||||
<ProjectReference Include="..\QuantEngine.Application\QuantEngine.Application.csproj" />
|
||||
<ProjectReference Include="..\QuantEngine.Infrastructure\QuantEngine.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\QuantEngine.Web\QuantEngine.Web.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Fixtures\operational_report.json" CopyToOutputDirectory="PreserveNewest" />
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Hangfire;
|
||||
using Hangfire.Common;
|
||||
using QuantEngine.Web.Services;
|
||||
|
||||
namespace QuantEngine.Core.Tests;
|
||||
|
||||
public class SchedulerServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void InitializeSchedules_RegistersAllFourRequiredJobs()
|
||||
{
|
||||
// Arrange
|
||||
var loggerMock = new Mock<ILogger<SchedulerService>>();
|
||||
var jobClientMock = new Mock<IBackgroundJobClient>();
|
||||
var recurringJobManagerMock = new Mock<IRecurringJobManager>();
|
||||
var scopeFactoryMock = new Mock<IServiceScopeFactory>();
|
||||
|
||||
var configMock = new Mock<IConfiguration>();
|
||||
configMock.Setup(c => c["Kis:AccountMode"]).Returns("mock");
|
||||
|
||||
var service = new SchedulerService(
|
||||
loggerMock.Object,
|
||||
jobClientMock.Object,
|
||||
recurringJobManagerMock.Object,
|
||||
scopeFactoryMock.Object,
|
||||
configMock.Object
|
||||
);
|
||||
|
||||
// Act
|
||||
service.InitializeSchedules();
|
||||
|
||||
// Assert
|
||||
// Verify daily-collection was added or updated
|
||||
recurringJobManagerMock.Verify(m => m.AddOrUpdate(
|
||||
"daily-collection",
|
||||
It.IsAny<Job>(),
|
||||
"0 9 * * *",
|
||||
It.IsAny<RecurringJobOptions>()
|
||||
), Times.Once);
|
||||
|
||||
// Verify hourly-price-update was added or updated
|
||||
recurringJobManagerMock.Verify(m => m.AddOrUpdate(
|
||||
"hourly-price-update",
|
||||
It.IsAny<Job>(),
|
||||
"0 9,11,13,15 * * 1-5",
|
||||
It.IsAny<RecurringJobOptions>()
|
||||
), Times.Once);
|
||||
|
||||
// Verify weekly-report was added or updated
|
||||
recurringJobManagerMock.Verify(m => m.AddOrUpdate(
|
||||
"weekly-report",
|
||||
It.IsAny<Job>(),
|
||||
"0 17 * * 5",
|
||||
It.IsAny<RecurringJobOptions>()
|
||||
), Times.Once);
|
||||
|
||||
// Verify monthly-optimization was added or updated
|
||||
recurringJobManagerMock.Verify(m => m.AddOrUpdate(
|
||||
"monthly-optimization",
|
||||
It.IsAny<Job>(),
|
||||
"0 2 1 * *",
|
||||
It.IsAny<RecurringJobOptions>()
|
||||
), Times.Once);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user