fix: 更新单元测试适配新模型

- RouteCacheTests: 使用 Fengling.Platform.Domain
- 更新 Id 类型为 string (Guid)
- 更新 PathPattern 为 Match.Path
- TenantRoutingMiddlewareTests: 更新 Id 类型为 string
This commit is contained in:
movingsam 2026-03-04 13:45:04 +08:00
parent 449fe3a385
commit cc11c7258f
2 changed files with 35 additions and 35 deletions

View File

@ -87,7 +87,7 @@ public class TenantRoutingMiddlewareTests
// Arrange // Arrange
var routeInfo = new RouteInfo var routeInfo = new RouteInfo
{ {
Id = 1, Id = "1",
ClusterId = "cluster-user-service", ClusterId = "cluster-user-service",
PathPattern = "/api/user-service/**", PathPattern = "/api/user-service/**",
Priority = 1, Priority = 1,
@ -147,7 +147,7 @@ public class TenantRoutingMiddlewareTests
// Arrange // Arrange
var routeInfo = new RouteInfo var routeInfo = new RouteInfo
{ {
Id = 1, Id = "1",
ClusterId = "cluster-1", ClusterId = "cluster-1",
IsGlobal = false IsGlobal = false
}; };
@ -173,7 +173,7 @@ public class TenantRoutingMiddlewareTests
// Arrange // Arrange
var routeInfo = new RouteInfo var routeInfo = new RouteInfo
{ {
Id = 1, Id = "1",
ClusterId = "cluster-1", ClusterId = "cluster-1",
IsGlobal = false IsGlobal = false
}; };
@ -224,7 +224,7 @@ public class TenantRoutingMiddlewareTests
// Arrange // Arrange
var routeInfo = new RouteInfo var routeInfo = new RouteInfo
{ {
Id = 1, Id = "1",
ClusterId = "cluster-1", ClusterId = "cluster-1",
IsGlobal = false IsGlobal = false
}; };
@ -249,7 +249,7 @@ public class TenantRoutingMiddlewareTests
// Arrange // Arrange
var routeInfo = new RouteInfo var routeInfo = new RouteInfo
{ {
Id = 1, Id = "1",
ClusterId = "global-cluster", ClusterId = "global-cluster",
IsGlobal = true IsGlobal = true
}; };
@ -292,7 +292,7 @@ public class TenantRoutingMiddlewareTests
var tenantRoute = new RouteInfo var tenantRoute = new RouteInfo
{ {
Id = 1, Id = "1",
ClusterId = "tenant-specific-cluster", ClusterId = "tenant-specific-cluster",
IsGlobal = false IsGlobal = false
}; };

View File

@ -4,7 +4,7 @@ using Moq;
using Xunit; using Xunit;
using FluentAssertions; using FluentAssertions;
using YarpGateway.Data; using YarpGateway.Data;
using YarpGateway.Models; using Fengling.Platform.Domain.AggregatesModel.GatewayAggregate;
using YarpGateway.Services; using YarpGateway.Services;
namespace YarpGateway.Tests.Unit.Services; namespace YarpGateway.Tests.Unit.Services;
@ -53,11 +53,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "user-service", ServiceName = "user-service",
ClusterId = "cluster-user", ClusterId = "cluster-user",
PathPattern = "/api/user/**", Match = new GwRouteMatch { Path = "/api/user/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -65,11 +65,11 @@ public class RouteCacheTests
}, },
new GwTenantRoute new GwTenantRoute
{ {
Id = 2, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "order-service", ServiceName = "order-service",
ClusterId = "cluster-order", ClusterId = "cluster-order",
PathPattern = "/api/order/**", Match = new GwRouteMatch { Path = "/api/order/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -97,11 +97,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "tenant-1", TenantCode = "tenant-1",
ServiceName = "user-service", ServiceName = "user-service",
ClusterId = "cluster-tenant-user", ClusterId = "cluster-tenant-user",
PathPattern = "/api/user/**", Match = new GwRouteMatch { Path = "/api/user/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = false, IsGlobal = false,
@ -129,11 +129,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "tenant-1", TenantCode = "tenant-1",
ServiceName = "user-service", ServiceName = "user-service",
ClusterId = "tenant-cluster", ClusterId = "tenant-cluster",
PathPattern = "/api/user/**", Match = new GwRouteMatch { Path = "/api/user/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = false, IsGlobal = false,
@ -141,11 +141,11 @@ public class RouteCacheTests
}, },
new GwTenantRoute new GwTenantRoute
{ {
Id = 2, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "user-service", ServiceName = "user-service",
ClusterId = "global-cluster", ClusterId = "global-cluster",
PathPattern = "/api/user/**", Match = new GwRouteMatch { Path = "/api/user/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -173,11 +173,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "user-service", ServiceName = "user-service",
ClusterId = "global-cluster", ClusterId = "global-cluster",
PathPattern = "/api/user/**", Match = new GwRouteMatch { Path = "/api/user/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -222,11 +222,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "user-service", ServiceName = "user-service",
ClusterId = "cluster-user", ClusterId = "cluster-user",
PathPattern = "/api/user/**", Match = new GwRouteMatch { Path = "/api/user/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -271,11 +271,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "old-service", ServiceName = "old-service",
ClusterId = "old-cluster", ClusterId = "old-cluster",
PathPattern = "/api/old/**", Match = new GwRouteMatch { Path = "/api/old/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -294,11 +294,11 @@ public class RouteCacheTests
context.TenantRoutes.RemoveRange(context.TenantRoutes); context.TenantRoutes.RemoveRange(context.TenantRoutes);
context.TenantRoutes.Add(new GwTenantRoute context.TenantRoutes.Add(new GwTenantRoute
{ {
Id = 2, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "new-service", ServiceName = "new-service",
ClusterId = "new-cluster", ClusterId = "new-cluster",
PathPattern = "/api/new/**", Match = new GwRouteMatch { Path = "/api/new/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -322,11 +322,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "active-service", ServiceName = "active-service",
ClusterId = "cluster-1", ClusterId = "cluster-1",
PathPattern = "/api/active/**", Match = new GwRouteMatch { Path = "/api/active/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -334,11 +334,11 @@ public class RouteCacheTests
}, },
new GwTenantRoute new GwTenantRoute
{ {
Id = 2, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "deleted-service", ServiceName = "deleted-service",
ClusterId = "cluster-2", ClusterId = "cluster-2",
PathPattern = "/api/deleted/**", Match = new GwRouteMatch { Path = "/api/deleted/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -363,11 +363,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "active-service", ServiceName = "active-service",
ClusterId = "cluster-1", ClusterId = "cluster-1",
PathPattern = "/api/active/**", Match = new GwRouteMatch { Path = "/api/active/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,
@ -375,11 +375,11 @@ public class RouteCacheTests
}, },
new GwTenantRoute new GwTenantRoute
{ {
Id = 2, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "inactive-service", ServiceName = "inactive-service",
ClusterId = "cluster-2", ClusterId = "cluster-2",
PathPattern = "/api/inactive/**", Match = new GwRouteMatch { Path = "/api/inactive/**" },
Priority = 1, Priority = 1,
Status = 0, // Inactive Status = 0, // Inactive
IsGlobal = true, IsGlobal = true,
@ -404,11 +404,11 @@ public class RouteCacheTests
{ {
new GwTenantRoute new GwTenantRoute
{ {
Id = 1, Id = Guid.CreateVersion7().ToString("N"),
TenantCode = "", TenantCode = "",
ServiceName = "user-service", ServiceName = "user-service",
ClusterId = "cluster-user", ClusterId = "cluster-user",
PathPattern = "/api/user/**", Match = new GwRouteMatch { Path = "/api/user/**" },
Priority = 1, Priority = 1,
Status = 1, Status = 1,
IsGlobal = true, IsGlobal = true,