IndustryApplicationTest.cs 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using DocumentFormat.OpenXml.Wordprocessing;
  2. using Hotline.Api.Controllers;
  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;
  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 System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using XF.Domain.Repository;
  21. namespace Hotline.Application.Tests.Application;
  22. public class IndustryApplicationTest : TestBase
  23. {
  24. private readonly IIndustryApplication _industryApplication;
  25. private readonly IIndustryRepository _industryRepository;
  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) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository)
  27. {
  28. _industryApplication = industryApplication;
  29. _industryRepository = industryRepository;
  30. }
  31. [Fact]
  32. public async Task UpdateIndustry_Test()
  33. {
  34. var industryItems = _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToList();
  35. industryItems.NotNullOrEmpty().ShouldBeTrue("行业集合为空");
  36. var industry = industryItems.First().Adapt<UpdateIndustryInDto>();
  37. var item = await _industryRepository.GetAsync(industry.Id);
  38. industry.ForeachClassProperties(async (industry, property, name, value) =>
  39. {
  40. if (name.ToUpper() == "ID") return true;
  41. if (value is String)
  42. industry.GetType().GetProperty(name).SetValue(industry, value + DateTime.Now.ToString("ss"));
  43. return true;
  44. });
  45. await _industryApplication.UpdateIndustryAsync(industry, CancellationToken.None);
  46. var updateIndustry = await _industryApplication.GetIndustryDetailAsync(item.Id);
  47. updateIndustry.ForeachClassProperties(async (industry, property, name, value) =>
  48. {
  49. industry.GetType().GetProperty(name).GetValue(industry).ShouldBe(value);
  50. return true;
  51. });
  52. await _industryApplication.UpdateIndustryAsync(item.Adapt<UpdateIndustryInDto>(), CancellationToken.None);
  53. }
  54. [Fact]
  55. public async Task IndustryCase_Test()
  56. {
  57. var industry = await _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToListAsync();
  58. var industryCase = new AddIndustryCaseDto
  59. {
  60. IndustryId = industry.First().Id,
  61. Name = "单元测试" + DateTime.Now.ToString("ss"),
  62. CitizenReadPackAmount = 10,
  63. GuiderReadPackAmount = 10,
  64. IsEnable = true,
  65. DisplayOrder = 1
  66. };
  67. var caseId = await _industryApplication.AddIndustryCaseAsync(industryCase);
  68. var items = await _industryApplication.GetIndustryCaseItems(new IndustryCaseItemInDto(null, null)).ToListAsync();
  69. items.Count.ShouldNotBe(0);
  70. items.Any(m => m.Id.IsNullOrEmpty()).ShouldBeFalse();
  71. items.Any(m => m.Name.IsNullOrEmpty()).ShouldBeFalse();
  72. var caseEntity = await _industryApplication.GetIndustryCaseAsync(caseId);
  73. var updateDto = caseEntity.Adapt<UpdateIndustryCaseDto>();
  74. updateDto.DisplayOrder = 2;
  75. await _industryApplication.UpdateIndustryCaseAsync(updateDto);
  76. var caseEntityUpdate = await _industryApplication.GetIndustryCaseAsync(caseId);
  77. caseEntityUpdate.DisplayOrder.ShouldBe(updateDto.DisplayOrder);
  78. caseEntityUpdate.Name.ShouldBe(updateDto.Name);
  79. }
  80. }