DefaultCallApplicationTest.cs 7.4 KB

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