Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

TaskSchedulerTests.cs

using FluentAssertions;
using Nop.Core.Domain.ScheduleTasks;
using Nop.Data;
using Nop.Services.ScheduleTasks;
using NUnit.Framework;

namespace Nop.Tests.Nop.Services.Tests.ScheduleTasks;

[TestFixture]
public class TaskSchedulerTests : ServiceTest
{
    private TestTaskScheduler _taskScheduler;
    private IRepository _scheduleTaskRepository;

    [OneTimeSetUp]
    public async Task SetUp()
    {
        _taskScheduler = GetService() as TestTaskScheduler;
        _scheduleTaskRepository = GetService>();

        var item = await _scheduleTaskRepository.GetByIdAsync(1);
        item.LastStartUtc = DateTime.UtcNow.AddSeconds(-(item.Seconds + 1));
        await _scheduleTaskRepository.UpdateAsync(item);

        item = await _scheduleTaskRepository.GetByIdAsync(2);
        item.LastStartUtc = DateTime.UtcNow.AddSeconds(item.Seconds - 1);
        await _scheduleTaskRepository.UpdateAsync(item);
    }

    [OneTimeTearDown]
    public void TearDown()
    {
        _taskScheduler.StopScheduler();
    }

    [Test]
    public async Task CanInitialize()
    {
        _taskScheduler.IsInit.Should().BeFalse();
        await _taskScheduler.InitializeAsync();
        _taskScheduler.IsInit.Should().BeTrue();
    }

    [Test]
    public void CanStartStopScheduler()
    {
        _taskScheduler.IsRun.Should().BeFalse();
        _taskScheduler.StartScheduler();
        _taskScheduler.IsRun.Should().BeTrue();
        _taskScheduler.StopScheduler();
        _taskScheduler.IsRun.Should().BeFalse();
    }
}