KnowledgeControllerTest.cs 2.9 KB

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