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.

92 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. using AutoMapper.Internal.Mappers;
  2. using Microsoft.VisualBasic;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Volo.Abp.Domain.Repositories;
  9. using Volo.Abp.Guids;
  10. using Volo.Abp.Uow;
  11. using Xunit;
  12. using Xunit.Abstractions;
  13. using Yitter.IdGenerator;
  14. namespace Shentun.Sms.SmsApps
  15. {
  16. public class SmsAppManagerTest : SmsDomainTestBase
  17. {
  18. private readonly IRepository<SmsApp, Guid> _smsAppRepository;
  19. private readonly SmsAppManager _smsAppManager;
  20. private readonly IGuidGenerator _guidGenerator;
  21. private readonly IUnitOfWorkManager _unitOfWorkManager;
  22. private readonly ITestOutputHelper _output;
  23. public SmsAppManagerTest(
  24. ITestOutputHelper output
  25. )
  26. {
  27. _output = output;
  28. _smsAppManager = GetRequiredService<SmsAppManager>();
  29. _guidGenerator = GetRequiredService<IGuidGenerator>();
  30. _smsAppRepository = GetRequiredService<IRepository<SmsApp, Guid>>();
  31. _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
  32. }
  33. [Fact]
  34. public async Task CreateAsyncTest()
  35. {
  36. using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
  37. {
  38. var entity = new SmsApp(_guidGenerator.Create())
  39. {
  40. DisplayName = "神豚集团",
  41. IsThisSystem = 'N'
  42. };
  43. entity = await _smsAppManager.CreateAsync(entity);
  44. await _smsAppRepository.InsertAsync(entity);
  45. await unitOfWork.CompleteAsync();
  46. _output.WriteLine(entity.Id.ToString());
  47. }
  48. }
  49. [Fact]
  50. public async Task UpdateAsyncTest()
  51. {
  52. using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
  53. {
  54. var Id = Guid.Parse("3a118c1d-b8d2-898a-b135-d75f50135e62");
  55. var entity = await _smsAppRepository.GetAsync(Id);
  56. var newEntity = new SmsApp(_guidGenerator.Create())
  57. {
  58. DisplayName = "测试数据1",
  59. IsThisSystem = 'N'
  60. };
  61. await _smsAppManager.UpdateAsync(newEntity, entity);
  62. await _smsAppRepository.UpdateAsync(entity);
  63. await unitOfWork.CompleteAsync();
  64. }
  65. }
  66. [Fact]
  67. public async Task DeleteAsyncTest()
  68. {
  69. using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
  70. {
  71. var Id = Guid.Parse("3a118c1d-b8d2-898a-b135-d75f50135e62");
  72. await _smsAppManager.CheckIsDeleteAsync(Id);
  73. await unitOfWork.CompleteAsync();
  74. }
  75. }
  76. }
  77. }