暂时提交
This commit is contained in:
1 parent
5d017740c6
commit
b35f816a87
7 files changed
+96
-2
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user