KnowledgeControllerTest.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Hotline.Api.Controllers;
  2. using Hotline.Api.Controllers.Bi;
  3. using Hotline.Application.Tests.Mock;
  4. using Hotline.Identity.Accounts;
  5. using Hotline.Identity.Roles;
  6. using Hotline.KnowledgeBase;
  7. using Hotline.Settings;
  8. using Hotline.Share.Dtos.FlowEngine;
  9. using Hotline.Share.Dtos.Knowledge;
  10. using Hotline.Share.Enums.FlowEngine;
  11. using Hotline.Share.Enums.KnowledgeBase;
  12. using Hotline.Snapshot.Interfaces;
  13. using Hotline.Users;
  14. using Microsoft.AspNetCore.Http;
  15. using Microsoft.AspNetCore.Mvc;
  16. using Microsoft.Extensions.DependencyInjection;
  17. using Shouldly;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using XF.Domain.Cache;
  24. using XF.Domain.Repository;
  25. namespace Hotline.Application.Tests.Controller;
  26. public class KnowledgeControllerTest : TestBase
  27. {
  28. private readonly KnowledgeServiceMock _knowledgeServiceMock;
  29. private readonly KnowledgeController _knowledgeController;
  30. private readonly IRepository<KnowledgeBase.Knowledge> _knowledgeRepository;
  31. 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) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount, cacheSettingData)
  32. {
  33. _knowledgeServiceMock = knowledgeServiceMock;
  34. _knowledgeController = knowledgeController;
  35. _knowledgeController.ControllerContext = new ControllerContext
  36. {
  37. HttpContext = new DefaultHttpContext()
  38. };
  39. _knowledgeRepository = knowledgeRepository;
  40. }
  41. /// <summary>
  42. /// 批量审核知识
  43. /// </summary>
  44. /// <returns></returns>
  45. //[Fact]
  46. public async Task KnowledgeBatchAudit_TestAsync()
  47. {
  48. SetPaiDanYuan();
  49. var inDto = new KnowledgeBatchAuditInDto
  50. {
  51. IsPass = true,
  52. KnowledgeIds = new string[3],
  53. IsSms = false,
  54. Opinion = "批量审核通过"
  55. };
  56. for (int i = 0;i < 3;i++)
  57. {
  58. inDto.KnowledgeIds[i] = _knowledgeServiceMock.创建并审核知识()
  59. .GetKnowledgeId();
  60. }
  61. Set班长();
  62. var result = await _knowledgeController.KnowledgeBatchAuditAsync(inDto);
  63. foreach (var id in inDto.KnowledgeIds)
  64. {
  65. var k = await _knowledgeRepository.GetAsync(id);
  66. k.Status.ShouldBe(EKnowledgeStatus.OnShelf, $"{id} 状态错误: {result}");
  67. }
  68. }
  69. }