using Hotline.Api.Controllers; using Hotline.Application.Snapshot; using Hotline.Identity.Accounts; using Hotline.Identity.Roles; using Hotline.Settings; using Hotline.Share.Dtos.Snapshot; using Hotline.Share.Enums.Snapshot; using Hotline.Snapshot.Interfaces; using Hotline.Users; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Shouldly; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using XF.Domain.Cache; using XF.Domain.Repository; namespace Hotline.Tests.Application; public class RedPackApplicationTest : TestBase { private readonly IRedPackApplication _redPackApplication; private readonly IRedPackRecordRepository _redPackRecordRepository; public RedPackApplicationTest(IAccountRepository accountRepository, IRepository roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, IRedPackApplication redPackApplication, IRedPackRecordRepository redPackRecordRepository, ITypedCache cacheSettingData) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData) { _redPackApplication = redPackApplication; _redPackRecordRepository = redPackRecordRepository; } /// /// 获取审核集合 /// 获取审核短信模板 /// 审核通过 /// 获取红包记录 /// /// [Fact] public async Task AuditRedPackAudit_Test() { var items = await _redPackApplication.GetRedPackAuditItems(new SnapshotOrderAuditItemsInDto(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0)).ToListAsync(); var audit = items.First(); var smsTemplate = await _redPackApplication.GetRedPackAuditSMSTemplateAsync(new GetRedPackAuditSMSTemplateInDto(audit.OrderId, ESnapshotSMSStatus.Agree)); var inDto = new UpdateRedPackAuditInDto { Status = ESnapshotSMSStatus.Agree, Opinion = "单元测试" + DateTime.Now.ToShortDateString(), SMSTemplateId = smsTemplate.First().Id, IsSendSms = true, RedPackAuditId = audit.Id, }; await _redPackApplication.AuditRedPackAuditAsync(inDto); var suInDto = new UpdateRedPackRecordInDto { RedPackAuditId = audit.Id, Name = "单元测试Name", BankCardNo = "单元测试银行号", OpenBank = "单元测试开户行", ReplenishAmount = 100.01, ReplenishTime = DateTime.Now, ReplenishRemark = "单元测试补发备注", IsSendSMS = false, ReplenishType = "%15", ReplenishTypeId = "1", }; await _redPackApplication.UpdateRedPackRecordAsync(suInDto); items = await _redPackApplication.GetRedPackAuditItems(new SnapshotOrderAuditItemsInDto(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 1)).ToListAsync(); items.Any(m => m.Id == audit.Id).ShouldBeTrue(); var record = await _redPackRecordRepository.Queryable() .Where(m => m.OrderId == audit.OrderId) .FirstAsync(); record.ShouldNotBeNull(); var recordItems = await _redPackApplication.GetRedPackRecordItems(new SnapshotRedPackRecordItemsInDto { Status =2}).ToListAsync(); recordItems.Count.ShouldNotBe(0); var redPackRecord = recordItems.First(); var redPackRecordEntity = await _redPackRecordRepository.GetAsync(redPackRecord.Id); redPackRecordEntity.PickupStatus = ERedPackPickupStatus.Received; redPackRecordEntity.DistributionState = EReadPackSendStatus.Successful; redPackRecordEntity.ReceiveTime = DateTime.Now; await _redPackRecordRepository.UpdateAsync(redPackRecordEntity); var sendRecordItems = await _redPackApplication.GetRedPackRecordDetail(new SnapshotRedPackRecordSendInDto { IsReceive = true, }).ToListAsync(); sendRecordItems.Count.ShouldNotBe(0); } }