|
@@ -1,10 +1,19 @@
|
|
|
using AutoFixture;
|
|
|
using Hotline.Api.Controllers;
|
|
|
+using Hotline.Application.Tests.Infrastructure;
|
|
|
+using Hotline.Identity.Accounts;
|
|
|
+using Hotline.Identity.Roles;
|
|
|
+using Hotline.Orders;
|
|
|
+using Hotline.Settings.Hotspots;
|
|
|
+using Hotline.Share.Dtos.File;
|
|
|
using Hotline.Share.Dtos.Order;
|
|
|
+using Hotline.Share.Dtos.Users;
|
|
|
using Hotline.Share.Enums.Settings;
|
|
|
+using Hotline.Share.Tools;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
+using Microsoft.Extensions.DependencyInjection;
|
|
|
using Moq;
|
|
|
using Shouldly;
|
|
|
using System;
|
|
@@ -12,32 +21,25 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Repository;
|
|
|
|
|
|
namespace Hotline.Application.Tests.Controller;
|
|
|
-public class OrderControllerTest : IClassFixture<WebApplicationFactory<Startup>>
|
|
|
+public class OrderControllerTest : TestBase
|
|
|
{
|
|
|
private readonly OrderController _orderController;
|
|
|
- private readonly IFixture _fixture;
|
|
|
- private readonly WebApplicationFactory<Startup> _factory;
|
|
|
+ private readonly IRepository<Hotspot> _hotspotRepository;
|
|
|
+ private readonly IOrderRepository _orderRepository;
|
|
|
|
|
|
- public OrderControllerTest(OrderController orderController, WebApplicationFactory<Startup> factory)
|
|
|
- //public OrderControllerTest(HttpClient testClient)
|
|
|
+ public OrderControllerTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IRepository<Hotspot> hotspotRepository, OrderController orderController, IOrderRepository orderRepository, IServiceScopeFactory scopeFactory) : base(accountRepository, roleRepository, userController, scopeFactory)
|
|
|
{
|
|
|
- _fixture = new Fixture();
|
|
|
+ _hotspotRepository = hotspotRepository;
|
|
|
_orderController = orderController;
|
|
|
- //_testClient = testClient;
|
|
|
- _factory = factory;
|
|
|
_orderController.ControllerContext = new ControllerContext
|
|
|
{
|
|
|
HttpContext = new DefaultHttpContext()
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public async Task SendSMS_Test()
|
|
|
- {
|
|
|
- var inDto = _fixture.Create<VisitSmsInDto>();
|
|
|
- await _orderController.VisitPushSMSAsync(inDto);
|
|
|
+ _orderRepository = orderRepository;
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -48,4 +50,24 @@ public class OrderControllerTest : IClassFixture<WebApplicationFactory<Startup>>
|
|
|
result.TimeText.ShouldBe("1个工作日");
|
|
|
result.TimeType.ShouldBe(ETimeType.WorkDay);
|
|
|
}
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public async Task CreateOrder_Test()
|
|
|
+ {
|
|
|
+ await SetPaiDanYuan();
|
|
|
+ var orderDto = _fixture.Create<AddOrderDto>();
|
|
|
+ var hotspot = await _hotspotRepository.Queryable()
|
|
|
+ .OrderByDescending(m => m.CreationTime)
|
|
|
+ .FirstAsync();
|
|
|
+ orderDto.HotspotId = hotspot.Id;
|
|
|
+ orderDto.HotspotName = hotspot.HotSpotName;
|
|
|
+ orderDto.HotspotSpliceName = hotspot.HotSpotFullName;
|
|
|
+ orderDto.Files = new List<FileDto>();
|
|
|
+
|
|
|
+ var orderResult = await _orderController.Add(orderDto);
|
|
|
+ var orderId = orderResult.ToJson().FromJson<OrderDto>().Id;
|
|
|
+ var order = await _orderRepository.GetAsync(orderId);
|
|
|
+ order.ShouldNotBeNull();
|
|
|
+ order.CreatorId.ShouldBe(TestSessionConstants.UserId);
|
|
|
+ }
|
|
|
}
|