IndustryApplicationTest.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 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. industry.IsPoints = false;
  58. await _industryApplication.UpdateIndustryAsync(industry, CancellationToken.None);
  59. var updateIndustry = await _industryApplication.GetIndustryDetailAsync(item.Id, CancellationToken.None);
  60. updateIndustry.ForeachClassProperties(async (industry, property, name, value) =>
  61. {
  62. industry.GetType().GetProperty(name).GetValue(industry).ShouldBe(value);
  63. return true;
  64. });
  65. updateIndustry.IsPoints.ShouldBe(false);
  66. await _industryApplication.UpdateIndustryAsync(item.Adapt<UpdateIndustryInDto>(), CancellationToken.None);
  67. var changeItem = await _industryRepository.GetAsync(industry.Id);
  68. changeItem.ModuleCode.ShouldNotBeNull();
  69. }
  70. [Fact]
  71. public async Task IndustryCase_Test()
  72. {
  73. var industry = await _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToListAsync();
  74. var industryCase = new AddIndustryCaseDto
  75. {
  76. IndustryId = industry.First().Id,
  77. Name = "单元测试" + DateTime.Now.ToString("ss"),
  78. CitizenReadPackAmount = 10,
  79. GuiderReadPackAmount = 10,
  80. IsEnable = true,
  81. DisplayOrder = 1
  82. };
  83. var caseId = await _industryApplication.AddIndustryCaseAsync(industryCase);
  84. var items = await _industryApplication.GetIndustryCaseItems(new IndustryCaseItemInDto(null, null)).ToListAsync();
  85. items.Count.ShouldNotBe(0);
  86. items.Any(m => m.Id.IsNullOrEmpty()).ShouldBeFalse();
  87. items.Any(m => m.Name.IsNullOrEmpty()).ShouldBeFalse();
  88. var caseEntity = await _industryApplication.GetIndustryCaseAsync(caseId);
  89. var updateDto = caseEntity.Adapt<UpdateIndustryCaseDto>();
  90. updateDto.DisplayOrder = 2;
  91. await _industryApplication.UpdateIndustryCaseAsync(updateDto);
  92. var caseEntityUpdate = await _industryApplication.GetIndustryCaseAsync(caseId);
  93. caseEntityUpdate.DisplayOrder.ShouldBe(updateDto.DisplayOrder);
  94. caseEntityUpdate.Name.ShouldBe(updateDto.Name);
  95. }
  96. /// <summary>
  97. /// 新增行业短信模板
  98. /// 行业短信模板集合
  99. /// </summary>
  100. /// <returns></returns>
  101. [Fact]
  102. public async Task SMSTemplate_Test()
  103. {
  104. var industryItems = await _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToListAsync();
  105. var industry = industryItems.First();
  106. var inDto = _fixture.Create<AddSnapshotSMSTemplateInDto>();
  107. inDto.IndustryId = industry.Id;
  108. var smsId = await _industryApplication.AddSMSTemplateAsync(inDto);
  109. var items = await _industryApplication.GetSMSTemplates(new SnapshotSMSTemplateItemsInDto(null)).ToListAsync();
  110. items.Count.ShouldNotBe(0);
  111. var sms = items.Where(m => m.Id == smsId).First();
  112. sms.Content.ShouldBe(inDto.Content);
  113. sms.IndustryName.ShouldNotBeNullOrEmpty();
  114. sms.IsEnable.ShouldBe(inDto.IsEnable);
  115. }
  116. }