DefaultCallApplicationTest.cs 8.2 KB

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