Browse Source

单元测试

qinchaoyue 3 months ago
parent
commit
a8ad7bc848
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/Hotline.Application.Tests/Controller/SnapshotControllerTest.cs

+ 14 - 1
src/Hotline.Application.Tests/Controller/SnapshotControllerTest.cs

@@ -1,4 +1,5 @@
 using AutoFixture;
+using EasyCaching.Core;
 using Hotline.Api.Controllers;
 using Hotline.Api.Controllers.Snapshot;
 using Hotline.Identity.Accounts;
@@ -27,7 +28,10 @@ public class SnapshotControllerTest : TestBase
     private readonly IOrderRepository _orderRepository;
     private readonly IOrderSnapshotRepository _orderSnapshotRepository;
     private readonly IIndustryRepository _industryRepository;
-    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)
+    private readonly IEasyCachingProvider _easyCaching;
+    private readonly IRedisCachingProvider _redisCaching;
+
+    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)
     {
         _snapshotController = snapshotController;
         _snapshotController.ControllerContext = new ControllerContext
@@ -37,6 +41,8 @@ public class SnapshotControllerTest : TestBase
         _orderRepository = orderRepository;
         _orderSnapshotRepository = orderSnapshotRepository;
         _industryRepository = industryRepository;
+        _easyCaching = easyCaching;
+        _redisCaching = redisCaching;
     }
 
     [Fact]
@@ -59,6 +65,12 @@ public class SnapshotControllerTest : TestBase
     [Fact]
     public async Task AddOrder_Test()
     {
+        var cacheKey = "Hotline:CollectionJobType";
+        await _easyCaching.RemoveAsync(cacheKey, CancellationToken.None);
+        var exist = await _easyCaching.ExistsAsync(cacheKey);
+        await _redisCaching.KeyDelAsync(cacheKey);
+        var existRedis = await _redisCaching.KeyExistsAsync(cacheKey);
+
         var homePage = await _snapshotController.GetHomePageAsync();
         var industry = homePage.Industrys.Where(m => m.IndustryType == EIndustryType.Declare).FirstOrDefault();
         var pageBase = await _snapshotController.GetIndustryBaseAsync(industry.Id);
@@ -86,5 +98,6 @@ public class SnapshotControllerTest : TestBase
         var orderSnapshotEntity = await _orderSnapshotRepository.GetAsync(order.Id);
         orderSnapshotEntity.ShouldNotBeNull();
         orderSnapshotEntity.JobType.ShouldBe(inDto.JobType);
+        orderSnapshotEntity.JobTypeName.ShouldBe("气割");
     }
 }