refactor: 移除平台公告与跨租户目标

This commit is contained in:
root
2026-01-29 13:15:53 +00:00
parent 0d9402d204
commit 77836e270f
16 changed files with 110 additions and 58 deletions

View File

@@ -21,7 +21,7 @@ public sealed class GetAnnouncementByIdQueryHandlerTests
var announcementRepository = new Mock<ITenantAnnouncementRepository>();
announcementRepository
.Setup(x => x.FindByIdInScopeAsync(99, 500, It.IsAny<CancellationToken>()))
.Setup(x => x.FindByIdAsync(99, 500, It.IsAny<CancellationToken>()))
.ReturnsAsync((TenantAnnouncement?)null);
var readRepository = new Mock<ITenantAnnouncementReadRepository>();
@@ -55,7 +55,7 @@ public sealed class GetAnnouncementByIdQueryHandlerTests
var announcementRepository = new Mock<ITenantAnnouncementRepository>();
announcementRepository
.Setup(x => x.FindByIdInScopeAsync(100, 1, It.IsAny<CancellationToken>()))
.Setup(x => x.FindByIdAsync(100, 1, It.IsAny<CancellationToken>()))
.ReturnsAsync(announcement);
var readRepository = new Mock<ITenantAnnouncementReadRepository>();
@@ -94,7 +94,7 @@ public sealed class GetAnnouncementByIdQueryHandlerTests
var announcementRepository = new Mock<ITenantAnnouncementRepository>();
announcementRepository
.Setup(x => x.FindByIdInScopeAsync(200, 10, It.IsAny<CancellationToken>()))
.Setup(x => x.FindByIdAsync(200, 10, It.IsAny<CancellationToken>()))
.ReturnsAsync(announcement);
var readRepository = new Mock<ITenantAnnouncementReadRepository>();

View File

@@ -17,7 +17,7 @@ public static class AnnouncementTestData
EffectiveFrom = DateTime.UtcNow.AddHours(-1),
EffectiveTo = DateTime.UtcNow.AddHours(2),
PublisherScope = PublisherScope.Tenant,
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
TargetParameters = null
};
@@ -28,7 +28,7 @@ public static class AnnouncementTestData
AnnouncementId = 9001,
Title = "更新公告",
Content = "更新内容",
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
TargetParameters = null,
RowVersion = new byte[] { 1, 2, 3 }
};

View File

@@ -65,7 +65,7 @@ public sealed class AnnouncementRegressionTests
AnnouncementId = announcement.Id,
Title = "更新后的标题",
Content = "更新后的内容",
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
RowVersion = announcement.RowVersion
};
@@ -92,7 +92,7 @@ public sealed class AnnouncementRegressionTests
EffectiveTo = null,
PublisherScope = PublisherScope.Tenant,
Status = AnnouncementStatus.Draft,
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
TargetParameters = null,
RowVersion = new byte[] { 1 }
};

View File

@@ -146,7 +146,7 @@ public sealed class AnnouncementWorkflowTests
AnnouncementId = announcement.Id,
Title = "更新标题",
Content = "更新内容",
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
RowVersion = announcement.RowVersion
};
@@ -185,7 +185,7 @@ public sealed class AnnouncementWorkflowTests
AnnouncementId = announcement.Id,
Title = "并发更新",
Content = "内容",
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
RowVersion = new byte[] { 1 }
};
@@ -210,7 +210,7 @@ public sealed class AnnouncementWorkflowTests
EffectiveTo = DateTime.UtcNow.AddMinutes(30),
PublisherScope = PublisherScope.Tenant,
Status = AnnouncementStatus.Draft,
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
TargetParameters = null,
RowVersion = new byte[] { 1 }
};

View File

@@ -9,16 +9,16 @@ namespace TakeoutSaaS.Integration.Tests.App.Tenants;
public sealed class TenantAnnouncementRepositoryScopeTests
{
[Fact]
public async Task GivenTenantAndPlatformAnnouncements_WhenSearchAsync_ThenReturnsBoth()
public async Task GivenDifferentTenantsAnnouncements_WhenSearchAsync_ThenReturnsOnlyCurrentTenant()
{
// Arrange
using var database = new SqliteTestDatabase();
using var context = database.CreateContext(tenantId: 800);
var tenantAnnouncement = CreateAnnouncement(tenantId: 800, id: 9200);
var platformAnnouncement = CreateAnnouncement(tenantId: 0, id: 9201);
var otherTenantAnnouncement = CreateAnnouncement(tenantId: 801, id: 9201);
context.TenantAnnouncements.AddRange(tenantAnnouncement, platformAnnouncement);
context.TenantAnnouncements.AddRange(tenantAnnouncement, otherTenantAnnouncement);
await context.SaveChangesAsync();
context.ChangeTracker.Clear();
@@ -37,7 +37,8 @@ public sealed class TenantAnnouncementRepositoryScopeTests
cancellationToken: CancellationToken.None);
// Assert
results.Select(x => x.Id).Should().Contain(new[] { tenantAnnouncement.Id, platformAnnouncement.Id });
results.Select(x => x.Id).Should().Contain(tenantAnnouncement.Id);
results.Select(x => x.Id).Should().NotContain(otherTenantAnnouncement.Id);
}
private static TenantAnnouncement CreateAnnouncement(long tenantId, long id)
@@ -52,7 +53,7 @@ public sealed class TenantAnnouncementRepositoryScopeTests
EffectiveFrom = DateTime.UtcNow.AddMinutes(-5),
PublisherScope = PublisherScope.Tenant,
Status = AnnouncementStatus.Draft,
TargetType = "ALL_TENANTS",
TargetType = "TENANT_ALL",
RowVersion = new byte[] { 1 }
};
}

View File

@@ -21,8 +21,8 @@ public sealed class AnnouncementQueryPerformanceTests
var announcements = new List<TenantAnnouncement>();
for (var i = 0; i < 1000; i++)
{
var tenantId = i % 2 == 0 ? 900 : 0;
var targetType = i % 10 == 0 ? "ROLES" : "ALL_TENANTS";
var tenantId = 900;
var targetType = i % 10 == 0 ? "ROLES" : "TENANT_ALL";
var targetParameters = i % 10 == 0 ? "{\"roles\":[\"ops\"]}" : null;
announcements.Add(new TenantAnnouncement
@@ -34,7 +34,7 @@ public sealed class AnnouncementQueryPerformanceTests
AnnouncementType = TenantAnnouncementType.System,
Priority = i % 5,
EffectiveFrom = DateTime.UtcNow.AddDays(-1),
PublisherScope = tenantId == 0 ? PublisherScope.Platform : PublisherScope.Tenant,
PublisherScope = PublisherScope.Tenant,
Status = AnnouncementStatus.Published,
TargetType = targetType,
TargetParameters = targetParameters,