You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.9 KiB

2 years ago
  1. using Shentun.Sms.SmsTasks;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Volo.Abp.Domain.Repositories;
  8. using Volo.Abp.Guids;
  9. using Volo.Abp.Uow;
  10. using Xunit.Abstractions;
  11. using Xunit;
  12. namespace Shentun.Sms.SmsTasks
  13. {
  14. public class SmsTaskManagerTest : SmsDomainTestBase
  15. {
  16. private readonly IRepository<SmsTask, Guid> _smsTaskRepository;
  17. private readonly SmsTaskManager _smsTaskManager;
  18. private readonly IGuidGenerator _guidGenerator;
  19. private readonly IUnitOfWorkManager _unitOfWorkManager;
  20. private readonly ITestOutputHelper _output;
  21. public SmsTaskManagerTest(
  22. ITestOutputHelper output
  23. )
  24. {
  25. _output = output;
  26. _smsTaskManager = GetRequiredService<SmsTaskManager>();
  27. _guidGenerator = GetRequiredService<IGuidGenerator>();
  28. _smsTaskRepository = GetRequiredService<IRepository<SmsTask, Guid>>();
  29. _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
  30. }
  31. [Fact]
  32. public async Task CreateAsyncTest()
  33. {
  34. using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
  35. {
  36. var entity = new SmsTask(_guidGenerator.Create())
  37. {
  38. Content = "这是一个短信内容",
  39. IsActive = 'Y',
  40. MobileTelephone = "13787791681",
  41. CountryCode = "86",
  42. PersonId = Guid.NewGuid().ToString(),
  43. PersonName = "文先德",
  44. SmsAppId = Guid.Parse("3a11921f-5caa-a313-8d61-dae87d1f2185"),
  45. SmsTypeId = Guid.Parse("3a119222-2219-ba1a-d411-ecf96ab3f0de"),
  46. StopTime = DateTime.Now.AddDays(15),
  47. TaskCycleType = '1',
  48. TaskCorn = "0 0 * * * ?",
  49. SenderId = "",
  50. SenderName = "",
  51. ThirdId = ""
  52. };
  53. entity = await _smsTaskManager.CreateAsync(entity);
  54. await _smsTaskRepository.InsertAsync(entity);
  55. await unitOfWork.CompleteAsync();
  56. _output.WriteLine(entity.Id.ToString());
  57. }
  58. }
  59. [Fact]
  60. public async Task UpdateAsyncTest()
  61. {
  62. using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
  63. {
  64. var Id = Guid.Parse("3a118c1d-b8d2-898a-b135-d75f50135e62");
  65. var entity = await _smsTaskRepository.GetAsync(Id);
  66. var newEntity = new SmsTask(_guidGenerator.Create())
  67. {
  68. Content = entity.Content,
  69. IsActive = entity.IsActive,
  70. MobileTelephone = entity.MobileTelephone,
  71. CountryCode = entity.CountryCode,
  72. PersonId = entity.PersonId,
  73. PersonName = entity.PersonName,
  74. SmsAppId = entity.SmsAppId,
  75. SmsTypeId = entity.SmsTypeId,
  76. StopTime = entity.StopTime,
  77. TaskCycleType = entity.TaskCycleType,
  78. TaskCorn = entity.TaskCorn,
  79. SenderId = entity.SenderId,
  80. SenderName = entity.SenderName,
  81. ThirdId = entity.ThirdId
  82. };
  83. await _smsTaskManager.UpdateAsync(newEntity, entity);
  84. await _smsTaskRepository.UpdateAsync(entity);
  85. await unitOfWork.CompleteAsync();
  86. }
  87. }
  88. [Fact]
  89. public async Task DeleteAsyncTest()
  90. {
  91. using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
  92. {
  93. var Id = Guid.Parse("3a118c1d-b8d2-898a-b135-d75f50135e62");
  94. await _smsTaskManager.CheckIsDeleteAsync(Id);
  95. await unitOfWork.CompleteAsync();
  96. }
  97. }
  98. }
  99. }