IndustryApplicationTest.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using AutoFixture;
  2. using Hotline.Api.Controllers;
  3. using Hotline.Application.Snapshot;
  4. using Hotline.Identity.Accounts;
  5. using Hotline.Identity.Roles;
  6. using Hotline.Settings;
  7. using Hotline.Share.Dtos.Snapshot;
  8. using Hotline.Share.Tools;
  9. using Hotline.Users;
  10. using Mapster;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.DependencyInjection;
  13. using Shouldly;
  14. using XF.Domain.Repository;
  15. using Hotline.Settings;
  16. using XF.Domain.Cache;
  17. using Hotline.ThirdAccountDomainServices.Interfaces;
  18. using Hotline.ThirdAccountDomainServices;
  19. using Hotline.Repository.SqlSugar.Extensions;
  20. using Hotline.Snapshot.IRepository;
  21. namespace Hotline.Tests.Application;
  22. public class IndustryApplicationTest : TestBase
  23. {
  24. private readonly IIndustryApplication _industryApplication;
  25. private readonly IIndustryRepository _industryRepository;
  26. private readonly ISystemOrganizeRepository _systemOrganizeRepository;
  27. public IndustryApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, IIndustryApplication industryApplication, IIndustryRepository industryRepository, ISystemOrganizeRepository systemOrganizeRepository, ITypedCache<SystemSetting> cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory)
  28. {
  29. _industryApplication = industryApplication;
  30. _industryRepository = industryRepository;
  31. _systemOrganizeRepository = systemOrganizeRepository;
  32. }
  33. [Fact]
  34. public async Task GetVolunteerReportItems_Test()
  35. {
  36. var inDto = new VolunteerReportItemsInDto(null, null);
  37. var items = await _industryApplication.GetVolunteerReportItems(inDto).ToListAsync();
  38. items.ShouldNotBeNull();
  39. }
  40. [Fact]
  41. public async Task UpdateIndustry_Test()
  42. {
  43. var industryItems = _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToList();
  44. industryItems.NotNullOrEmpty().ShouldBeTrue("行业集合为空");
  45. var industry = industryItems.First().Adapt<UpdateIndustryInDto>();
  46. var item = await _industryRepository.GetAsync(industry.Id);
  47. industry.ForeachClassProperties(async (industry, property, name, value) =>
  48. {
  49. if (name.ToUpper() == "ID") return true;
  50. if (value is String)
  51. industry.GetType().GetProperty(name).SetValue(industry, value + DateTime.Now.ToString("ss"));
  52. return true;
  53. });
  54. var orgs = await _systemOrganizeRepository.GetOrgEnabled();
  55. industry.ApproveOrgId = orgs.First().Key;
  56. industry.ApproveOrgName = null;
  57. await _industryApplication.UpdateIndustryAsync(industry, CancellationToken.None);
  58. var updateIndustry = await _industryApplication.GetIndustryDetailAsync(item.Id, CancellationToken.None);
  59. updateIndustry.ForeachClassProperties(async (industry, property, name, value) =>
  60. {
  61. industry.GetType().GetProperty(name).GetValue(industry).ShouldBe(value);
  62. return true;
  63. });
  64. await _industryApplication.UpdateIndustryAsync(item.Adapt<UpdateIndustryInDto>(), CancellationToken.None);
  65. }
  66. [Fact]
  67. public async Task IndustryCase_Test()
  68. {
  69. var industry = await _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToListAsync();
  70. var industryCase = new AddIndustryCaseDto
  71. {
  72. IndustryId = industry.First().Id,
  73. Name = "单元测试" + DateTime.Now.ToString("ss"),
  74. CitizenReadPackAmount = 10,
  75. GuiderReadPackAmount = 10,
  76. IsEnable = true,
  77. DisplayOrder = 1
  78. };
  79. var caseId = await _industryApplication.AddIndustryCaseAsync(industryCase);
  80. var items = await _industryApplication.GetIndustryCaseItems(new IndustryCaseItemInDto(null, null)).ToListAsync();
  81. items.Count.ShouldNotBe(0);
  82. items.Any(m => m.Id.IsNullOrEmpty()).ShouldBeFalse();
  83. items.Any(m => m.Name.IsNullOrEmpty()).ShouldBeFalse();
  84. var caseEntity = await _industryApplication.GetIndustryCaseAsync(caseId);
  85. var updateDto = caseEntity.Adapt<UpdateIndustryCaseDto>();
  86. updateDto.DisplayOrder = 2;
  87. await _industryApplication.UpdateIndustryCaseAsync(updateDto);
  88. var caseEntityUpdate = await _industryApplication.GetIndustryCaseAsync(caseId);
  89. caseEntityUpdate.DisplayOrder.ShouldBe(updateDto.DisplayOrder);
  90. caseEntityUpdate.Name.ShouldBe(updateDto.Name);
  91. }
  92. /// <summary>
  93. /// 新增行业短信模板
  94. /// 行业短信模板集合
  95. /// </summary>
  96. /// <returns></returns>
  97. [Fact]
  98. public async Task SMSTemplate_Test()
  99. {
  100. var industryItems = await _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToListAsync();
  101. var industry = industryItems.First();
  102. var inDto = _fixture.Create<AddSnapshotSMSTemplateInDto>();
  103. inDto.IndustryId = industry.Id;
  104. var smsId = await _industryApplication.AddSMSTemplateAsync(inDto);
  105. var items = await _industryApplication.GetSMSTemplates(new SnapshotSMSTemplateItemsInDto(null)).ToListAsync();
  106. items.Count.ShouldNotBe(0);
  107. var sms = items.Where(m => m.Id == smsId).First();
  108. sms.Content.ShouldBe(inDto.Content);
  109. sms.IndustryName.ShouldNotBeNullOrEmpty();
  110. sms.IsEnable.ShouldBe(inDto.IsEnable);
  111. }
  112. }