SnapshotControllerTest.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using AutoFixture;
  2. using EasyCaching.Core;
  3. using Hotline.Api.Controllers;
  4. using Hotline.Api.Controllers.Snapshot;
  5. using Hotline.Identity.Accounts;
  6. using Hotline.Identity.Roles;
  7. using Hotline.Orders;
  8. using Hotline.Share.Dtos.Snapshot;
  9. using Hotline.Share.Enums.Snapshot;
  10. using Hotline.Share.Tools;
  11. using Hotline.Snapshot.Interfaces;
  12. using Hotline.Users;
  13. using Microsoft.AspNetCore.Http;
  14. using Microsoft.AspNetCore.Mvc;
  15. using Microsoft.Extensions.DependencyInjection;
  16. using Shouldly;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using XF.Domain.Repository;
  23. namespace Hotline.Application.Tests.Controller;
  24. public class SnapshotControllerTest : TestBase
  25. {
  26. private readonly SnapshotController _snapshotController;
  27. private readonly IOrderRepository _orderRepository;
  28. private readonly IOrderSnapshotRepository _orderSnapshotRepository;
  29. private readonly IIndustryRepository _industryRepository;
  30. private readonly IEasyCachingProvider _easyCaching;
  31. private readonly IRedisCachingProvider _redisCaching;
  32. public SnapshotControllerTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, SnapshotController snapshotController, IOrderRepository orderRepository, IOrderSnapshotRepository orderSnapshotRepository, IIndustryRepository industryRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, IEasyCachingProvider easyCaching, IRedisCachingProvider redisCaching) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount)
  33. {
  34. _snapshotController = snapshotController;
  35. _snapshotController.ControllerContext = new ControllerContext
  36. {
  37. HttpContext = new DefaultHttpContext()
  38. };
  39. _orderRepository = orderRepository;
  40. _orderSnapshotRepository = orderSnapshotRepository;
  41. _industryRepository = industryRepository;
  42. _easyCaching = easyCaching;
  43. _redisCaching = redisCaching;
  44. }
  45. [Fact]
  46. public async Task GetAreaTree_Test()
  47. {
  48. var result = await _snapshotController.GetAreaTreeAsync();
  49. result.ShouldNotBeNull();
  50. var zgs = result.Where(m => m.AreaName == "自贡市").FirstOrDefault();
  51. zgs.ShouldNotBeNull();
  52. var rx = zgs.Children.Where(m => m.AreaName == "荣县").FirstOrDefault();
  53. rx.ShouldNotBeNull();
  54. var zzz = rx.Children.Where(m => m.AreaName == "正紫镇").FirstOrDefault();
  55. zzz.ShouldNotBeNull();
  56. }
  57. /// <summary>
  58. /// 测试创建随手拍工单
  59. /// </summary>
  60. /// <returns></returns>
  61. [Fact]
  62. public async Task AddOrder_Test()
  63. {
  64. var cacheKey = "Hotline:CollectionJobType";
  65. await _easyCaching.RemoveAsync(cacheKey, CancellationToken.None);
  66. var exist = await _easyCaching.ExistsAsync(cacheKey);
  67. await _redisCaching.KeyDelAsync(cacheKey);
  68. var existRedis = await _redisCaching.KeyExistsAsync(cacheKey);
  69. var homePage = await _snapshotController.GetHomePageAsync();
  70. var industry = homePage.Industrys.Where(m => m.IndustryType == EIndustryType.Declare).FirstOrDefault();
  71. var pageBase = await _snapshotController.GetIndustryBaseAsync(industry.Id);
  72. var inDto = _fixture.Create<AddSnapshotOrderInDto>();
  73. inDto.Street = "单元测试街道" + DateTime.Now.ToLongDateTimeString();
  74. inDto.IndustryId = industry.Id;
  75. inDto.Town = "仙市镇";
  76. inDto.County = "沿滩区";
  77. inDto.Description = "单元测试添加的时间描述";
  78. inDto.IsSecret = false;
  79. inDto.JobType = 1;
  80. foreach (var item in inDto.Files)
  81. {
  82. item.FileName = DateTime.Now.ToShortTimeString() + "文件.doc";
  83. }
  84. var order = await _snapshotController.AddOrderAsync(inDto);
  85. var orderEntity = await _orderRepository.GetAsync(order.Id);
  86. orderEntity.ShouldNotBeNull();
  87. orderEntity.Latitude.ShouldBe(inDto.Latitude);
  88. orderEntity.Longitude.ShouldBe(inDto.Longitude);
  89. orderEntity.Title.ShouldNotBeNullOrEmpty();
  90. orderEntity.Content.ShouldNotBeNullOrEmpty();
  91. var orderSnapshotEntity = await _orderSnapshotRepository.GetAsync(order.Id);
  92. orderSnapshotEntity.ShouldNotBeNull();
  93. orderSnapshotEntity.JobType.ShouldBe(inDto.JobType);
  94. orderSnapshotEntity.JobTypeName.ShouldBe("气割");
  95. }
  96. }