IndustryApplicationTest.cs 6.3 KB

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