DefaultCallApplicationTest.cs 8.3 KB

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