SnapshotBulletionApplicationTest.cs 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. 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) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
  36. {
  37. _snapshotBulletinApplication = snapshotBulletinApplication;
  38. _systemDicDataCacheManager = systemDicDataCacheManager;
  39. _safetyTypeRepository = safetyTypeRepository;
  40. _snapshotUserApplication = snapshotUserApplication;
  41. _sessionContext = sessionContext;
  42. _snapshotApplication = snapshotApplication;
  43. }
  44. [Fact]
  45. public async Task Bulletin_Test()
  46. {
  47. SetWeiXin();
  48. var bulletinType = _systemDicDataCacheManager.SnapshotBulletinType.First();
  49. var safetyType = await _safetyTypeRepository.Queryable().FirstAsync();
  50. var addRelationInDto = new AddCitizenRelationSafetyTypeInDto { SafetyTypeId = safetyType.Id, CitizenIds = [_sessionContext.UserId] };
  51. await _snapshotUserApplication.AddCitizenRelationSafetyType(addRelationInDto, CancellationToken.None);
  52. var inDto = new AddSnapshotBulletinInDto
  53. {
  54. Title = "测试公告" + DateTime.Now.ToLongDateTimeString(),
  55. Content = "没什么内容",
  56. BulletinTime = DateTime.Now,
  57. IsSnapshot = true,
  58. BulletinTypeId = bulletinType.DicDataValue,
  59. BulletinTypeName = bulletinType.DicDataName,
  60. SafetyTypeId = safetyType.Id,
  61. };
  62. var bulletinId = await _snapshotBulletinApplication.AddBulletinAsync(inDto, CancellationToken.None);
  63. await _snapshotBulletinApplication.CommitBulletinAsync(bulletinId, CancellationToken.None);
  64. var examineDto = new ExamineBulletinDto
  65. {
  66. Id = bulletinId,
  67. IsPass = true,
  68. Reason = "审核通过"
  69. };
  70. await _snapshotBulletinApplication.ExamineBulletinAsync(examineDto, CancellationToken.None);
  71. Thread.Sleep(5 * 1000);
  72. //await _snapshotBulletinApplication.NotifyUserAsync(bulletinId, CancellationToken.None);
  73. var notifyItems = await _snapshotApplication.GetNotificationAsync(new GetNotifyInDto(), CancellationToken.None);
  74. notifyItems.Any(m => m.Title == inDto.Title).ShouldBeTrue();
  75. }
  76. }