DefaultCallApplicationTest.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using AutoFixture;
  2. using Hotline.Api.Controllers;
  3. using Hotline.Application.CallCenter;
  4. using Hotline.CallCenter.Calls;
  5. using Hotline.CallCenter.Tels;
  6. using Hotline.Identity.Accounts;
  7. using Hotline.Identity.Roles;
  8. using Hotline.Orders;
  9. using Hotline.Repository.SqlSugar.Extensions;
  10. using Hotline.Settings;
  11. using Hotline.Share.Dtos.CallCenter;
  12. using Hotline.Share.Dtos.Order;
  13. using Hotline.Share.Enums.CallCenter;
  14. using Hotline.ThirdAccountDomainServices;
  15. using Hotline.ThirdAccountDomainServices.Interfaces;
  16. using Hotline.Users;
  17. using Microsoft.AspNetCore.Http;
  18. using Microsoft.Extensions.DependencyInjection;
  19. using Shouldly;
  20. using SqlSugar.Extensions;
  21. using XF.Domain.Cache;
  22. using XF.Domain.Repository;
  23. namespace Hotline.Tests.Application;
  24. public class DefaultCallApplicationTest : TestBase
  25. {
  26. private readonly XingTangCallApplication _defaultCallApplication;
  27. private readonly IOrderVisitRepository _orderVisitRepository;
  28. private readonly IRepository<CallNative> _callNativeRepository;
  29. public readonly IFixture _fixture;
  30. private readonly IOrderRepository _orderRepository;
  31. private readonly ICallTelClient _callTelClient;
  32. public DefaultCallApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, XingTangCallApplication defaultCallApplication, IOrderVisitRepository orderVisitRepository, IRepository<CallNative> callNativeRepository, IOrderRepository orderRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ITypedCache<SystemSetting> cacheSettingData, ICallTelClient callTelClient, ThirdAccounSupplierFactory thirdAccountDomainFactory, IServiceProvider serviceProvider) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
  33. {
  34. _fixture = new Fixture();
  35. _defaultCallApplication = defaultCallApplication;
  36. _orderVisitRepository = orderVisitRepository;
  37. _callNativeRepository = callNativeRepository;
  38. _orderRepository = orderRepository;
  39. _callTelClient = callTelClient;
  40. }
  41. [Theory]
  42. [InlineData(16, 0)]
  43. [InlineData(0, 100)]
  44. [InlineData(1, 301)]
  45. [InlineData(2, 202)]
  46. [InlineData(3, 200)]
  47. [InlineData(17, 303)]
  48. [InlineData(30, 400)]
  49. public async Task GetStatus_Test(int xingtang, int hotline)
  50. {
  51. var result = await _callTelClient.GetStatusAsync(hotline);
  52. result.ShouldBe(xingtang);
  53. }
  54. [Fact]
  55. public async Task QueryCallsFixed_Test()
  56. {
  57. var inDto = new QueryCallsFixedDto();
  58. //inDto.CallStartTimeEnd = DateTime.Now;
  59. //inDto.CallStartTimeStart = "2024/10/01 00:00:00".ObjToDate();
  60. //inDto.StaffNo = "8029";
  61. inDto.Type = 2;
  62. inDto.ToNo = "15892228077";
  63. var items = await _defaultCallApplication.QueryCallsFixedAsync(inDto, new CancellationToken()).ToPageListWithoutTotalAsync(inDto, CancellationToken.None);
  64. items.ShouldNotBeNull();
  65. }
  66. [Fact]
  67. public async Task QueryCallsFixedThree_Test()
  68. {
  69. var inDto = new QueryCallsFixedDto();
  70. inDto.CallStartTimeEnd = DateTime.Now;
  71. inDto.CallStartTimeStart = "2024/11/08 00:00:00".ObjToDate();
  72. inDto.FromNo = "8205175";
  73. var items1 = await _defaultCallApplication.QueryCallsFixedAsync(inDto, new CancellationToken()).ToPageListWithoutTotalAsync(inDto, CancellationToken.None);
  74. items1.ShouldNotBeNull();
  75. foreach (var item in items1.Where(m => m.IsOrder))
  76. {
  77. item.Title.ShouldNotBeNull();
  78. item.OrderId.ShouldNotBeNull();
  79. item.OrderNo.ShouldNotBeNull();
  80. }
  81. inDto.ToNo = "13990006670";
  82. inDto.FromNo = null;
  83. inDto.Type = 2;
  84. var items = await _defaultCallApplication.QueryCallsFixedAsync(inDto, new CancellationToken()).ToPageListWithoutTotalAsync(inDto, CancellationToken.None);
  85. items.ShouldNotBeNull();
  86. items.Count().ShouldNotBe(0, "通过被叫号码查询失败");
  87. foreach (var item in items.Where(m => m.IsVisit))
  88. {
  89. item.Title.ShouldNotBeNull();
  90. item.OrderId.ShouldNotBeNull();
  91. item.OrderNo.ShouldNotBeNull();
  92. }
  93. }
  94. [Fact]
  95. public async Task GetCall_Test()
  96. {
  97. var result = await _defaultCallApplication.GetCallAsync("01J2ZP7J6X3K5FXN4B5KD54FBA", CancellationToken.None);
  98. result.ShouldNotBeNull();
  99. result = await _defaultCallApplication.GetCallAsync("2024062419085100943CTI", CancellationToken.None);
  100. result.ShouldNotBeNull();
  101. }
  102. [Fact]
  103. public async Task OrderVisitRelevanceCallId_Test()
  104. {
  105. var inDto = new VisitDto();
  106. inDto.CallId = "202411151100300273100069FLOW";
  107. inDto.Id = "08dd046b-b3b3-4ccf-8a15-09133d27dce0";
  108. await _defaultCallApplication.OrderVisitRelevanceCallIdAsync(inDto, CancellationToken.None);
  109. var visit = await _orderVisitRepository.GetAsync(inDto.Id);
  110. visit.CallId.ShouldBe("01JCPW9ZJ2683ZVN69ZGNZ0A4B");
  111. }
  112. /// <summary>
  113. /// 测试三方通话后, 工单保存时没有关联到正确的通话记录, 使用本方法能不能修复
  114. /// 测试如果通话记录有两通都是呼入的,就不需要修复了
  115. /// </summary>
  116. /// <returns></returns>
  117. [Fact]
  118. public async Task OrderRelateCallHandler_Test()
  119. {
  120. var callNo = DateTime.Now.ToString("yyyyMMddhhmmss") + "Flow";
  121. var inDto = _fixture.Build<CallNative>()
  122. .With(m => m.Id, Ulid.NewUlid().ToString())
  123. .With(m => m.CallNo, callNo)
  124. .With(m => m.Direction, ECallDirection.In)
  125. .With(m => m.IsDeleted, false)
  126. .Create();
  127. await _callNativeRepository.AddAsync(inDto);
  128. var inDto2 = _fixture.Build<CallNative>()
  129. .With(m => m.Id, Ulid.NewUlid().ToString())
  130. .With(m => m.Direction, ECallDirection.Out)
  131. .With(m => m.CallNo, callNo)
  132. .With(m => m.IsDeleted, false)
  133. .Create();
  134. await _callNativeRepository.AddAsync(inDto2);
  135. var orderId = await _orderRepository.Queryable()
  136. .Where(m => string.IsNullOrEmpty(m.CallId))
  137. .OrderByDescending(m => m.CreationTime)
  138. .Select(m => m.Id)
  139. .FirstAsync();
  140. await _orderRepository.Updateable()
  141. .SetColumns(m => m.CallId == inDto2.Id)
  142. .Where(m => m.Id == orderId)
  143. .ExecuteCommandAsync();
  144. await _defaultCallApplication.OrderRelateCallHandlerAsync(orderId, CancellationToken.None);
  145. (await _orderRepository.Queryable().Where(m => m.Id == orderId).Select(m => m.CallId).FirstAsync())
  146. .ShouldBe(inDto.Id);
  147. // 测试如果通话记录有两通都是呼入的,就不需要修复了
  148. callNo = DateTime.Now.ToString("yyyyMMddhhmmss") + "Flow";
  149. inDto = _fixture.Build<CallNative>()
  150. .With(m => m.Id, Ulid.NewUlid().ToString())
  151. .With(m => m.CallNo, callNo)
  152. .With(m => m.Direction, ECallDirection.In)
  153. .With(m => m.Duration, 20)
  154. .With(m => m.IsDeleted, false)
  155. .Create();
  156. await _callNativeRepository.AddAsync(inDto);
  157. inDto2 = _fixture.Build<CallNative>()
  158. .With(m => m.Id, Ulid.NewUlid().ToString())
  159. .With(m => m.Direction, ECallDirection.In)
  160. .With(m => m.CallNo, callNo)
  161. .With(m => m.Duration, 10)
  162. .With(m => m.IsDeleted, false)
  163. .Create();
  164. await _callNativeRepository.AddAsync(inDto2);
  165. orderId = await _orderRepository.Queryable()
  166. .Where(m => string.IsNullOrEmpty(m.CallId))
  167. .OrderByDescending(m => m.CreationTime)
  168. .Select(m => m.Id)
  169. .FirstAsync();
  170. await _orderRepository.Updateable()
  171. .SetColumns(m => m.CallId == inDto2.Id)
  172. .Where(m => m.Id == orderId)
  173. .ExecuteCommandAsync();
  174. await _defaultCallApplication.OrderRelateCallHandlerAsync(orderId, CancellationToken.None);
  175. (await _orderRepository.Queryable().Where(m => m.Id == orderId).Select(m => m.CallId).FirstAsync())
  176. .ShouldBe(inDto2.Id);
  177. }
  178. //[Fact]
  179. public async Task OrderRelateCallHandler2_Test()
  180. {
  181. var orderId = "08dd0d21-0221-43cf-8230-3179dc6aefca";
  182. await _defaultCallApplication.OrderRelateCallHandlerAsync(orderId, CancellationToken.None);
  183. }
  184. }