XingTangCallsSyncJobTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using AutoFixture;
  2. using Hotline.Application.Jobs;
  3. using Hotline.Caching.Interfaces;
  4. using Hotline.Repository.SqlSugar;
  5. using Quartz;
  6. using SqlSugar;
  7. using XingTang.Sdk;
  8. namespace Hotline.Tests.Application;
  9. public class XingTangCallsSyncJobTest
  10. {
  11. private readonly XingTangCallsSyncJob xingTangCallsSyncJob;
  12. private readonly ISqlSugarClient _db;
  13. private readonly IFixture _fixture;
  14. private readonly XingTangCallSatisfactionSyncJob _xingTangCallSatisfactionSyncJob;
  15. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  16. public XingTangCallsSyncJobTest(XingTangCallsSyncJob xingTangCallsSyncJob, ISugarUnitOfWork<XingTangDbContext> uow, XingTangCallSatisfactionSyncJob xingTangCallSatisfactionSyncJob, ISystemSettingCacheManager systemSettingCacheManager)
  17. {
  18. this.xingTangCallsSyncJob = xingTangCallsSyncJob;
  19. _db = uow.Db;
  20. _fixture = new Fixture();
  21. _xingTangCallSatisfactionSyncJob = xingTangCallSatisfactionSyncJob;
  22. _systemSettingCacheManager = systemSettingCacheManager;
  23. }
  24. [Fact]
  25. public async Task Handler_Test()
  26. {
  27. var unPushTime = _systemSettingCacheManager.CallSyncUnPushDateTime;
  28. var second = new Random().Next(0, 60);
  29. var inDto = _fixture.Create<XingtangCall>();
  30. inDto.CallStartTime = DateTime.Parse("2024/11/19 18:07:" + second);
  31. inDto.IsSync = false;
  32. inDto.Tries = 0;
  33. inDto.CallGuid = DateTime.Now.ToString("yyyyMMddhhmmss") + "FLOW";
  34. inDto.Ver = string.Empty;
  35. inDto.CustomerId = string.Empty;
  36. inDto.Id = new Random().Next(0, 100000);
  37. var inDto2 = _fixture.Create<XingtangCall>();
  38. inDto2.CallStartTime = DateTime.Now;
  39. inDto2.CallGuid = DateTime.Now.ToString("yyyyMMddhhmmss") + "FLOW";
  40. inDto2.IsSync = false;
  41. inDto2.Tries = 0;
  42. inDto2.Ver = string.Empty;
  43. inDto2.CustomerId = string.Empty;
  44. inDto2.Id = new Random().Next(0, 100000);
  45. await _db.Insertable(inDto).ExecuteCommandAsync();
  46. await _db.Insertable(inDto2).ExecuteCommandAsync();
  47. await xingTangCallsSyncJob.Execute(new JobContext());
  48. var s1 = _fixture.Create<XingtangSatisfaction>();
  49. s1.CallNo = inDto.CallGuid;
  50. s1.Result = new Random().Next(1, 5);
  51. s1.IsSync = false;
  52. s1.Tries = 0;
  53. await _db.Insertable(s1).ExecuteCommandAsync();
  54. await _xingTangCallSatisfactionSyncJob.Execute(new JobContext());
  55. }
  56. }
  57. public class JobContext : IJobExecutionContext
  58. {
  59. public IScheduler Scheduler => throw new NotImplementedException();
  60. public ITrigger Trigger => throw new NotImplementedException();
  61. public ICalendar? Calendar => throw new NotImplementedException();
  62. public bool Recovering => throw new NotImplementedException();
  63. public TriggerKey RecoveringTriggerKey => throw new NotImplementedException();
  64. public int RefireCount => throw new NotImplementedException();
  65. public JobDataMap MergedJobDataMap => throw new NotImplementedException();
  66. public IJobDetail JobDetail => throw new NotImplementedException();
  67. public IJob JobInstance => throw new NotImplementedException();
  68. public DateTimeOffset FireTimeUtc => throw new NotImplementedException();
  69. public DateTimeOffset? ScheduledFireTimeUtc => throw new NotImplementedException();
  70. public DateTimeOffset? PreviousFireTimeUtc => throw new NotImplementedException();
  71. public DateTimeOffset? NextFireTimeUtc => throw new NotImplementedException();
  72. public string FireInstanceId => throw new NotImplementedException();
  73. public object? Result { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  74. public TimeSpan JobRunTime => throw new NotImplementedException();
  75. public CancellationToken CancellationToken => CancellationToken.None;
  76. public object? Get(object key)
  77. {
  78. throw new NotImplementedException();
  79. }
  80. public void Put(object key, object objectValue)
  81. {
  82. throw new NotImplementedException();
  83. }
  84. }