using Hotline.Api.Controllers;
using Hotline.Identity.Accounts;
using Hotline.Identity.Roles;
using Hotline.KnowledgeBase;
using Hotline.Settings;
using Hotline.Share.Dtos.FlowEngine;
using Hotline.Share.Dtos.Knowledge;
using Hotline.Share.Enums.KnowledgeBase;
using Hotline.Tests.Mock;
using Hotline.ThirdAccountDomainServices;
using Hotline.ThirdAccountDomainServices.Interfaces;
using Hotline.Users;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Cache;
using XF.Domain.Repository;

namespace Hotline.Tests.Controller;
public class KnowledgeControllerTest : TestBase
{
    private readonly KnowledgeServiceMock _knowledgeServiceMock;
    private readonly KnowledgeController _knowledgeController;
    private readonly IRepository<KnowledgeBase.Knowledge> _knowledgeRepository;

    public KnowledgeControllerTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, KnowledgeServiceMock knowledgeServiceMock, KnowledgeController knowledgeController, IRepository<KnowledgeBase.Knowledge> knowledgeRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ITypedCache<SystemSetting> cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory, IServiceProvider serviceProvider) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
    {
        _knowledgeServiceMock = knowledgeServiceMock;
        _knowledgeController = knowledgeController;
        _knowledgeController.ControllerContext = new ControllerContext
        {
            HttpContext = new DefaultHttpContext()
        };
        _knowledgeRepository = knowledgeRepository;
    }

    /// <summary>
    /// 批量审核知识
    /// </summary>
    /// <returns></returns>
    //[Fact]
    public async Task KnowledgeBatchAudit_TestAsync()
    {
        SetPaiDanYuan();
        var inDto = new KnowledgeBatchAuditInDto
        {
            IsPass = true,
            KnowledgeIds = new string[3],
            IsSms = false,
            Opinion = "批量审核通过"
        };
        for (int i = 0;i < 3;i++)
        {
            inDto.KnowledgeIds[i] = _knowledgeServiceMock.创建并审核知识()
                .GetKnowledgeId();

        }
        Set班长();
        var result = await _knowledgeController.KnowledgeBatchAuditAsync(inDto);
        foreach (var id in inDto.KnowledgeIds)
        {
            var k = await _knowledgeRepository.GetAsync(id);
            k.Status.ShouldBe(EKnowledgeStatus.OnShelf, $"{id} 状态错误: {result}");
        }
    }
}
