暂时提交
This commit is contained in:
1 parent
5d017740c6
commit
b35f816a87
7 files changed
+96
-2
No files matched your search
@@ -54,6 +54,7 @@ public sealed class ShopHttpTests : IAsyncLifetime
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddScoped<ICurrentUser, CurrentUser>();
|
||||
builder.Services.AddSingleton(context.Db);
|
||||
builder.Services.AddSingleton(context.Repository);
|
||||
builder.Services.AddSingleton<IUserQueryService>(context);
|
||||
builder.Services.AddSingleton(context.Configuration);
|
||||
builder.Services.AddSingleton(context.Gateway);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using Store.Shops.Services;
|
||||
using Store.Users.Entities;
|
||||
using YourNamespace;
|
||||
|
||||
namespace Store.Shops.Tests;
|
||||
|
||||
/// <summary>验证公共到期查询集中后仍保留批量范围和列表到期规则。</summary>
|
||||
public sealed class ShopQueryTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Expirations_ReadRequestedShopsInOneQuery_AndEmptyInputReturnsNothing()
|
||||
{
|
||||
using var context = new ShopTestContext();
|
||||
await context.Db.Insert(new[]
|
||||
{
|
||||
new ShopExpireEntity { ShopId = "first", ExpireTime = 100 },
|
||||
new ShopExpireEntity { ShopId = "second", ExpireTime = 200 },
|
||||
new ShopExpireEntity { ShopId = "outside", ExpireTime = 300 }
|
||||
}).ExecuteAffrowsAsync();
|
||||
var queries = 0;
|
||||
context.Db.Aop.CurdBefore += (_, _) => queries++;
|
||||
|
||||
var rows = await context.Repository.GetExpireTimes(["first", "second", "first", "missing"]);
|
||||
|
||||
Assert.Equal(1, queries);
|
||||
Assert.Equal(new[] { "first", "second" }, rows.Select(r => r.ShopId).Order().ToArray());
|
||||
Assert.Equal(100, rows.Single(r => r.ShopId == "first").ExpireTime);
|
||||
Assert.Equal(200, rows.Single(r => r.ShopId == "second").ExpireTime);
|
||||
Assert.Empty(await context.Repository.GetExpireTimes([]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Search_PreservesMissingAndPermanentExpiration_AndReadsUpdatedValue()
|
||||
{
|
||||
using var context = new ShopTestContext { UserName = "admin" };
|
||||
await context.Db.Insert(new[]
|
||||
{
|
||||
new ShopEntity { ShopId = "dated", UserName = "owner" },
|
||||
new ShopEntity { ShopId = "missing", UserName = "owner" },
|
||||
new ShopEntity { ShopId = "permanent", UserName = "owner", NeverExpires = true }
|
||||
}).ExecuteAffrowsAsync();
|
||||
await context.Db.Insert(new ShopExpireEntity { ShopId = "dated", ExpireTime = 100 }).ExecuteAffrowsAsync();
|
||||
var service = new ShopService(context.Db, context, context, context.Gateway,
|
||||
context.Configuration, context.Repository);
|
||||
|
||||
var page = await service.Search(new(), admin: true);
|
||||
|
||||
Assert.Equal(3, page.Total);
|
||||
Assert.Equal(100, page.Items.Single(s => s.ShopId == "dated").ExpireTime);
|
||||
Assert.Equal(0, page.Items.Single(s => s.ShopId == "missing").ExpireTime);
|
||||
Assert.Equal(1893427200, page.Items.Single(s => s.ShopId == "permanent").ExpireTime);
|
||||
|
||||
await context.Db.Update<ShopExpireEntity>().Where(e => e.ShopId == "dated")
|
||||
.Set(e => e.ExpireTime, 200).ExecuteAffrowsAsync();
|
||||
var updated = await service.Search(new() { ShopIds = ["dated"] }, admin: true);
|
||||
Assert.Equal(200, Assert.Single(updated.Items).ExpireTime);
|
||||
Assert.Empty((await service.Search(new() { Page = 2 }, admin: true)).Items);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ using MAX.Framework.Security;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Store.Shops.Entities;
|
||||
using Store.Shops.Services;
|
||||
using Store.Shops.Repositories;
|
||||
using Store.Users.Entities;
|
||||
using YourNamespace;
|
||||
using Store.Users.Contracts;
|
||||
using Store.Users.Contracts.Dtos;
|
||||
using Store.Users.Contracts.Enums;
|
||||
@@ -28,6 +31,7 @@ internal sealed class ShopTestContext : IDisposable, ICurrentUser, IUserQuerySer
|
||||
public StubHttp Handler { get; } = new();
|
||||
public PddTokenClient Gateway { get; }
|
||||
public ShopManagementService Service { get; }
|
||||
public IShopRepository Repository { get; }
|
||||
public IConfiguration Configuration { get; } = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["Shops:PddClients:0:ClientId"] = "test-client",
|
||||
@@ -45,6 +49,11 @@ internal sealed class ShopTestContext : IDisposable, ICurrentUser, IUserQuerySer
|
||||
Db.CodeFirst.ConfigEntity<ShopApiAuthEntity>(e => e.Name("shop_auth"));
|
||||
Db.CodeFirst.ConfigEntity<ShopProductQuotaEntity>(e => e.Name("shop_quota"));
|
||||
Db.CodeFirst.SyncStructure(typeof(PddShopEntity), typeof(WeidianShopEntity), typeof(ShopApiAuthEntity), typeof(ShopProductQuotaEntity));
|
||||
Db.CodeFirst.ConfigEntity<ShopEntity>(e => e.Name("shops"));
|
||||
Db.CodeFirst.ConfigEntity<ShopExpireEntity>(e => e.Name("shop_expirations"));
|
||||
Db.CodeFirst.SyncStructure(typeof(ShopEntity), typeof(ShopExpireEntity));
|
||||
Repository = (IShopRepository)Activator.CreateInstance(
|
||||
typeof(ShopService).Assembly.GetType("Store.Shops.Repositories.ShopRepository", true)!, Db)!;
|
||||
Gateway = new(new HttpClient(Handler));
|
||||
Service = new(Db, this, this, Configuration, Gateway);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user