1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using DocumentFormat.OpenXml.Wordprocessing;
- using Hotline.Api.Controllers;
- using Hotline.Application.Snapshot;
- using Hotline.Identity.Accounts;
- using Hotline.Identity.Roles;
- using Hotline.Share.Dtos.Snapshot;
- using Hotline.Share.Tools;
- using Hotline.Snapshot;
- using Hotline.Snapshot.Interfaces;
- using Hotline.Users;
- using Mapster;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
- using Shouldly;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XF.Domain.Repository;
- namespace Hotline.Application.Tests.Application;
- public class IndustryApplicationTest : TestBase
- {
- private readonly IIndustryApplication _industryApplication;
- private readonly IIndustryRepository _industryRepository;
- 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)
- {
- _industryApplication = industryApplication;
- _industryRepository = industryRepository;
- }
- [Fact]
- public async Task UpdateIndustry_Test()
- {
- var industryItems = _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToList();
- industryItems.NotNullOrEmpty().ShouldBeTrue("行业集合为空");
- var industry = industryItems.First().Adapt<UpdateIndustryInDto>();
- var item = await _industryRepository.GetAsync(industry.Id);
- industry.ForeachClassProperties(async (industry, property, name, value) =>
- {
- if (name.ToUpper() == "ID") return true;
- if (value is String)
- industry.GetType().GetProperty(name).SetValue(industry, value + DateTime.Now.ToString("ss"));
- return true;
- });
- await _industryApplication.UpdateIndustryAsync(industry, CancellationToken.None);
- var updateIndustry = await _industryApplication.GetIndustryDetailAsync(item.Id);
- updateIndustry.ForeachClassProperties(async (industry, property, name, value) =>
- {
- industry.GetType().GetProperty(name).GetValue(industry).ShouldBe(value);
- return true;
- });
- await _industryApplication.UpdateIndustryAsync(item.Adapt<UpdateIndustryInDto>(), CancellationToken.None);
- }
- [Fact]
- public async Task AddIndustry_Test()
- {
- var industry = await _industryApplication.GetIndustres(new IndustryListInDto(null, null)).ToListAsync();
- var industryCase = new AddIndustryCaseDto
- {
- IndustryId = industry.First().Id,
- Name = "单元测试" + DateTime.Now.ToString("ss"),
- CitizenReadPackAmount = 10,
- GuiderReadPackAmount = 10,
- IsEnable = true,
- DisplayOrder = 1
- };
- var caseId = await _industryApplication.AddIndustryCaseAsync(industryCase);
- var items = await _industryApplication.GetIndustryCaseItems(new IndustryCaseItemInDto(null, null)).ToListAsync();
- items.Count.ShouldNotBe(0);
- items.Any(m => m.Id.IsNullOrEmpty()).ShouldBeFalse();
- items.Any(m => m.Name.IsNullOrEmpty()).ShouldBeFalse();
- }
- }
|