IndustryApplicationTest.cs 5.1 KB

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