IndustryApplicationTest.cs 5.7 KB

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