using Hotline.Api.Controllers; using Hotline.Application.Knowledge; using Hotline.Application.Tools; using Hotline.File; using Hotline.Identity.Accounts; using Hotline.Identity.Roles; using Hotline.KnowledgeBase; using Hotline.KnowledgeBase.Notifies; using Hotline.Settings; using Hotline.Share.Dtos.File; using Hotline.Share.Dtos.Knowledge; using Hotline.Share.Enums.Article; using Hotline.Share.Tools; using Hotline.ThirdAccountDomainServices; using Hotline.ThirdAccountDomainServices.Interfaces; using Hotline.Users; using Mapster; using MediatR; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Senparc.Weixin.WxOpen.AdvancedAPIs.Tcb; using Shouldly; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using XF.Domain.Cache; using XF.Domain.Repository; namespace Hotline.Tests.Application; public class KnowApplicationTest : TestBase { private readonly IKnowApplication _knowApplication; private readonly IMediator _mediator; private readonly IRepository _knowledgeRepository; private readonly IKnowledgeDomainService _knowledgeDomainService; private readonly IRepository _knowledgeWordRepository; private readonly IRepository _knowledgeHotWordRepository; private readonly IFileDomainService _fileDomainService; public KnowApplicationTest(IAccountRepository accountRepository, IRepository roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository userRepository, IHttpContextAccessor httpContextAccessor, IKnowApplication knowApplication, IMediator mediator, IRepository knowledgeRepository, IKnowledgeDomainService knowledgeDomainService, IRepository knowledgeWordRepository, IRepository knowledgeHotWordRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ITypedCache cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory, IFileDomainService fileDomainService, IServiceProvider serviceProvider) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount, cacheSettingData, thirdAccountDomainFactory, serviceProvider) { _knowApplication = knowApplication; _mediator = mediator; _knowledgeRepository = knowledgeRepository; _knowledgeDomainService = knowledgeDomainService; _knowledgeWordRepository = knowledgeWordRepository; _knowledgeHotWordRepository = knowledgeHotWordRepository; _fileDomainService = fileDomainService; } [Fact] public async Task TitleParticiple_Test() { var result = await _knowApplication.TitleParticiple("短信回访的相关解释口径、规范用语"); result.ShouldNotBeNull(); } [Fact] public void SplitKeywords_Test() { var keywords = "短信 筷子, 天才, 脑洞, 大开"; var items = keywords.SplitKeywords(); items.Count.ShouldBe(5); items[0] = "短信"; items[1] = "筷子"; items[2] = "天才"; items[3] = "脑洞"; items[4] = "大开"; } //[Fact] public async Task GetPageViewList_Test() { //var r = await _knowledgeRelationTypeRepository.Queryable() // .OrderByDescending(m => m.CreationTime) // .FirstAsync(); //var knowledge = await _knowledgeRepository.GetAsync(r.KnowledgeId); //await _knowledgeDomainService.KnowledgePvIncreaseAsync(knowledge, new CancellationToken()); //var inDto = new PageViewInDto //{ // KnowledgeTypeId = r.KnowledgeTypeId //}; //var (total, items) = await _knowApplication.GetPageViewListAsync(inDto); //total.ShouldNotBe(0); } [Fact] public async Task UpdateKnowledgeWord_Test() { var entity = await _knowledgeHotWordRepository.Queryable() .OrderByDescending(m => m.CreationTime) .FirstAsync(); entity.KeyWord = "单元测试修改"; var inDto = entity.Adapt(); await _knowApplication.UpdateKnowledgeHotWordAsync(inDto); var updateEntity = await _knowledgeHotWordRepository.GetAsync(entity.Id); updateEntity.KeyWord.ShouldBe(entity.KeyWord); } [Fact] public async Task AddKnowledgeHotWord_Test() { var addDto = new AddKnowledgeHotWordInDto { KeyWord = "单元测试" + new Random().Next(1, 100), }; await _knowApplication.AddKnowledgeHotWordAsync(addDto); try { await _knowApplication.AddKnowledgeHotWordAsync(addDto); } catch (Exception e) { e.Message.ShouldBe("热词已存在"); } } /// /// 测试扩展方法是否能正确判断集合空和非空的情况 /// [Fact] public void ListEx_Test() { List a = null; a.IsNullOrEmpty().ShouldBeTrue(); a.NotNullOrEmpty().ShouldBeFalse(); a = new List(); a.IsNullOrEmpty().ShouldBeTrue(); a.NotNullOrEmpty().ShouldBeFalse(); } [Fact] public async Task Word_Upload_Test() { var fileJson = await _fileDomainService.UploadFileFromMemoryAsync("
123
".HtmlToWord(), "测试文件" + EFileType.word.GetFileExtension(), EFileType.word); fileJson.Id.ShouldNotBeNull(); } }