SnapshotControllerTest.cs 3.9 KB

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