DefaultCallApplicationTest.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. var items = await _defaultCallApplication.QueryCallsFixedAsync(inDto, new CancellationToken()).ToPageListWithoutTotalAsync(inDto, CancellationToken.None);
  62. items.ShouldNotBeNull();
  63. }
  64. [Fact]
  65. public async Task QueryCallsFixedThree_Test()
  66. {
  67. var inDto = new QueryCallsFixedDto();
  68. inDto.CallStartTimeEnd = DateTime.Now;
  69. inDto.CallStartTimeStart = "2024/11/08 00:00:00".ObjToDate();
  70. inDto.FromNo = "8205175";
  71. var items1 = await _defaultCallApplication.QueryCallsFixedAsync(inDto, new CancellationToken()).ToPageListWithoutTotalAsync(inDto, CancellationToken.None);
  72. items1.ShouldNotBeNull();
  73. foreach (var item in items1.Where(m => m.IsOrder))
  74. {
  75. item.Title.ShouldNotBeNull();
  76. item.OrderId.ShouldNotBeNull();
  77. item.OrderNo.ShouldNotBeNull();
  78. }
  79. inDto.ToNo = "13990006670";
  80. inDto.FromNo = null;
  81. inDto.Type = 2;
  82. var items = await _defaultCallApplication.QueryCallsFixedAsync(inDto, new CancellationToken()).ToPageListWithoutTotalAsync(inDto, CancellationToken.None);
  83. items.ShouldNotBeNull();
  84. items.Count().ShouldNotBe(0, "通过被叫号码查询失败");
  85. foreach (var item in items.Where(m => m.IsVisit))
  86. {
  87. item.Title.ShouldNotBeNull();
  88. item.OrderId.ShouldNotBeNull();
  89. item.OrderNo.ShouldNotBeNull();
  90. }
  91. }
  92. [Fact]
  93. public async Task GetCall_Test()
  94. {
  95. var result = await _defaultCallApplication.GetCallAsync("01J2ZP7J6X3K5FXN4B5KD54FBA", CancellationToken.None);
  96. result.ShouldNotBeNull();
  97. result = await _defaultCallApplication.GetCallAsync("2024062419085100943CTI", CancellationToken.None);
  98. result.ShouldNotBeNull();
  99. }
  100. [Fact]
  101. public async Task OrderVisitRelevanceCallId_Test()
  102. {
  103. var inDto = new VisitDto();
  104. inDto.CallId = "202411151100300273100069FLOW";
  105. inDto.Id = "08dd046b-b3b3-4ccf-8a15-09133d27dce0";
  106. await _defaultCallApplication.OrderVisitRelevanceCallIdAsync(inDto, CancellationToken.None);
  107. var visit = await _orderVisitRepository.GetAsync(inDto.Id);
  108. visit.CallId.ShouldBe("01JCPW9ZJ2683ZVN69ZGNZ0A4B");
  109. }
  110. /// <summary>
  111. /// 测试三方通话后, 工单保存时没有关联到正确的通话记录, 使用本方法能不能修复
  112. /// 测试如果通话记录有两通都是呼入的,就不需要修复了
  113. /// </summary>
  114. /// <returns></returns>
  115. [Fact]
  116. public async Task OrderRelateCallHandler_Test()
  117. {
  118. var callNo = DateTime.Now.ToString("yyyyMMddhhmmss") + "Flow";
  119. var inDto = _fixture.Build<CallNative>()
  120. .With(m => m.Id, Ulid.NewUlid().ToString())
  121. .With(m => m.CallNo, callNo)
  122. .With(m => m.Direction, ECallDirection.In)
  123. .With(m => m.IsDeleted, false)
  124. .Create();
  125. await _callNativeRepository.AddAsync(inDto);
  126. var inDto2 = _fixture.Build<CallNative>()
  127. .With(m => m.Id, Ulid.NewUlid().ToString())
  128. .With(m => m.Direction, ECallDirection.Out)
  129. .With(m => m.CallNo, callNo)
  130. .With(m => m.IsDeleted, false)
  131. .Create();
  132. await _callNativeRepository.AddAsync(inDto2);
  133. var orderId = await _orderRepository.Queryable()
  134. .Where(m => string.IsNullOrEmpty(m.CallId))
  135. .OrderByDescending(m => m.CreationTime)
  136. .Select(m => m.Id)
  137. .FirstAsync();
  138. await _orderRepository.Updateable()
  139. .SetColumns(m => m.CallId == inDto2.Id)
  140. .Where(m => m.Id == orderId)
  141. .ExecuteCommandAsync();
  142. await _defaultCallApplication.OrderRelateCallHandlerAsync(orderId, CancellationToken.None);
  143. (await _orderRepository.Queryable().Where(m => m.Id == orderId).Select(m => m.CallId).FirstAsync())
  144. .ShouldBe(inDto.Id);
  145. // 测试如果通话记录有两通都是呼入的,就不需要修复了
  146. callNo = DateTime.Now.ToString("yyyyMMddhhmmss") + "Flow";
  147. inDto = _fixture.Build<CallNative>()
  148. .With(m => m.Id, Ulid.NewUlid().ToString())
  149. .With(m => m.CallNo, callNo)
  150. .With(m => m.Direction, ECallDirection.In)
  151. .With(m => m.Duration, 20)
  152. .With(m => m.IsDeleted, false)
  153. .Create();
  154. await _callNativeRepository.AddAsync(inDto);
  155. inDto2 = _fixture.Build<CallNative>()
  156. .With(m => m.Id, Ulid.NewUlid().ToString())
  157. .With(m => m.Direction, ECallDirection.In)
  158. .With(m => m.CallNo, callNo)
  159. .With(m => m.Duration, 10)
  160. .With(m => m.IsDeleted, false)
  161. .Create();
  162. await _callNativeRepository.AddAsync(inDto2);
  163. orderId = await _orderRepository.Queryable()
  164. .Where(m => string.IsNullOrEmpty(m.CallId))
  165. .OrderByDescending(m => m.CreationTime)
  166. .Select(m => m.Id)
  167. .FirstAsync();
  168. await _orderRepository.Updateable()
  169. .SetColumns(m => m.CallId == inDto2.Id)
  170. .Where(m => m.Id == orderId)
  171. .ExecuteCommandAsync();
  172. await _defaultCallApplication.OrderRelateCallHandlerAsync(orderId, CancellationToken.None);
  173. (await _orderRepository.Queryable().Where(m => m.Id == orderId).Select(m => m.CallId).FirstAsync())
  174. .ShouldBe(inDto2.Id);
  175. }
  176. //[Fact]
  177. public async Task OrderRelateCallHandler2_Test()
  178. {
  179. var orderId = "08dd0d21-0221-43cf-8230-3179dc6aefca";
  180. await _defaultCallApplication.OrderRelateCallHandlerAsync(orderId, CancellationToken.None);
  181. }
  182. }