SnapshotBulletionApplicationTest.cs 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Hotline.Api.Controllers;
  2. using Hotline.Application.Snapshot.Contracts;
  3. using Hotline.Caching.Interfaces;
  4. using Hotline.Identity.Accounts;
  5. using Hotline.Identity.Roles;
  6. using Hotline.Repository.SqlSugar.Snapshot;
  7. using Hotline.Settings;
  8. using Hotline.Share.Dtos.Article;
  9. using Hotline.Share.Dtos.Snapshot;
  10. using Hotline.Share.Tools;
  11. using Hotline.Snapshot.IRepository;
  12. using Hotline.ThirdAccountDomainServices;
  13. using Hotline.ThirdAccountDomainServices.Interfaces;
  14. using Hotline.Users;
  15. using Microsoft.AspNetCore.Http;
  16. using Microsoft.Extensions.DependencyInjection;
  17. using Shouldly;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using XF.Domain.Authentications;
  24. using XF.Domain.Cache;
  25. using XF.Domain.Repository;
  26. namespace Hotline.Tests.Application;
  27. public class SnapshotBulletionApplicationTest : TestBase
  28. {
  29. private readonly ISnapshotBulletinApplication _snapshotBulletinApplication;
  30. private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
  31. private readonly ISafetyTypeRepository _safetyTypeRepository;
  32. private readonly ISnapshotUserApplication _snapshotUserApplication;
  33. private readonly ISessionContext _sessionContext;
  34. private readonly ISnapshotApplication _snapshotApplication;
  35. private readonly ISnapshotBulletinRepository _bulletinRepository;
  36. public SnapshotBulletionApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, ITypedCache<SystemSetting> cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory, IServiceProvider serviceProvider, ISnapshotBulletinApplication snapshotBulletinApplication, ISystemDicDataCacheManager systemDicDataCacheManager, ISafetyTypeRepository safetyTypeRepository, ISnapshotUserApplication snapshotUserApplication, ISessionContext sessionContext, ISnapshotApplication snapshotApplication, ISnapshotBulletinRepository bulletinRepository) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
  37. {
  38. _snapshotBulletinApplication = snapshotBulletinApplication;
  39. _systemDicDataCacheManager = systemDicDataCacheManager;
  40. _safetyTypeRepository = safetyTypeRepository;
  41. _snapshotUserApplication = snapshotUserApplication;
  42. _sessionContext = sessionContext;
  43. _snapshotApplication = snapshotApplication;
  44. _bulletinRepository = bulletinRepository;
  45. }
  46. [Fact]
  47. public async Task Bulletin_Test()
  48. {
  49. SetWeiXin();
  50. var bulletinType = _systemDicDataCacheManager.SnapshotBulletinType.First();
  51. var safetyType = await _safetyTypeRepository.Queryable().FirstAsync();
  52. var addRelationInDto = new AddCitizenRelationSafetyTypeInDto { SafetyTypeId = safetyType.Id, CitizenIds = [_sessionContext.UserId] };
  53. await _snapshotUserApplication.AddCitizenRelationSafetyType(addRelationInDto, CancellationToken.None);
  54. var inDto = new AddSnapshotBulletinInDto
  55. {
  56. Title = "测试公告" + DateTime.Now.ToLongDateTimeString(),
  57. Content = "没什么内容",
  58. BulletinTime = DateTime.Now,
  59. IsSnapshot = true,
  60. BulletinTypeId = bulletinType.DicDataValue,
  61. BulletinTypeName = bulletinType.DicDataName,
  62. SafetyTypeId = [safetyType.Id],
  63. VideoCoverImgUrl = "222222",
  64. VideoPath = "333333"
  65. };
  66. var bulletinId = await _snapshotBulletinApplication.AddBulletinAsync(inDto, CancellationToken.None);
  67. var bulletin = await _bulletinRepository.GetAsync(bulletinId);
  68. bulletin.IsSnapshot.ShouldBe(true);
  69. bulletin.SafetyTypeId.First().ShouldBe(safetyType.Id);
  70. bulletin.VideoPath.ShouldBe(inDto.VideoPath);
  71. bulletin.VideoCoverImgUrl.ShouldBe(inDto.VideoCoverImgUrl);
  72. await _snapshotBulletinApplication.CommitBulletinAsync(bulletinId, CancellationToken.None);
  73. var examineDto = new ExamineBulletinDto
  74. {
  75. Id = bulletinId,
  76. IsPass = true,
  77. Reason = "审核通过"
  78. };
  79. await _snapshotBulletinApplication.ExamineBulletinAsync(examineDto, CancellationToken.None);
  80. Thread.Sleep(5 * 1000);
  81. //await _snapshotBulletinApplication.NotifyUserAsync(bulletinId, CancellationToken.None);
  82. var notifyItems = await _snapshotApplication.GetNotificationAsync(new GetNotifyInDto(), CancellationToken.None);
  83. notifyItems.Any(m => m.Title == inDto.Title).ShouldBeTrue();
  84. }
  85. }