IndustryApplicationTest.cs 5.1 KB

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