DefaultCallApplicationTest.cs 7.7 KB

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