XingTangCallsSyncJobTest.cs 3.7 KB

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