DefaultCallApplicationTest.cs 7.5 KB

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