using System;
using Xunit;
using CncCollector.Core;
using CncCollector.Config;

namespace CncCollector.Tests
{
    /// <summary>
    /// 日终汇总作业测试（使用无效数据库连接字符串以触发容错处理）
    /// </summary>
    public class DailySummaryJobTests
    {
        private string InvalidConnection => "Server=invalid;Database=invalid;User Id=invalid;Password=invalid;";

        [Fact]
        public void Execute_无DB连接_不抛异常()
        {
            var job = new DailySummaryJob(InvalidConnection);
            var date = DateTime.Now.AddDays(-1).Date;

            // 仅确保调用不抛出异常
            job.Execute(date);
        }

        [Fact]
        public void Execute_正常日期_不抛异常()
        {
            var job = new DailySummaryJob(InvalidConnection);
            var date = DateTime.Now.AddDays(-1);

            job.Execute(date.Date);
        }

        [Fact]
        public void Execute_多次调用同一日期_不抛异常()
        {
            var job = new DailySummaryJob(InvalidConnection);
            var date = DateTime.Now.AddDays(-1).Date;

            // 幂等性测试：多次执行同一日期不应抛出异常
            job.Execute(date);
            job.Execute(date);
        }
    }
}
