IndustryApplicationTest.cs 5.3 KB

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