fix(external-system-gateway): resolve ExternalSystemGateway-011 — name-keyed repository lookups replace fetch-all-then-filter on the call hot path
This commit is contained in:
@@ -84,6 +84,101 @@ public class SiteRepositoryTests : IDisposable
|
||||
Assert.Equal("StableSystem", found.Name);
|
||||
}
|
||||
|
||||
// ── ExternalSystemGateway-011: name-keyed repository lookups ──
|
||||
|
||||
/// <summary>
|
||||
/// ExternalSystemGateway-011: the site repository's name-keyed external-system
|
||||
/// lookup returns the matching row, and the same synthetic ID as the by-ID path.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ExternalSystemRepository_GetByName_ReturnsMatchingDefinition()
|
||||
{
|
||||
var storage = NewStorage();
|
||||
await storage.InitializeAsync();
|
||||
await storage.StoreExternalSystemAsync(
|
||||
"Alpha", "https://alpha.test", "ApiKey", "{\"key\":\"x\"}", null);
|
||||
await storage.StoreExternalSystemAsync(
|
||||
"Beta", "https://beta.test", "Basic", null, null);
|
||||
|
||||
var repo = new SiteExternalSystemRepository(storage);
|
||||
|
||||
var found = await repo.GetExternalSystemByNameAsync("Beta");
|
||||
Assert.NotNull(found);
|
||||
Assert.Equal("Beta", found!.Name);
|
||||
Assert.Equal("https://beta.test", found.EndpointUrl);
|
||||
|
||||
// The by-name path must produce the same synthetic ID as the by-id path.
|
||||
var byId = await repo.GetExternalSystemByIdAsync(found.Id);
|
||||
Assert.NotNull(byId);
|
||||
Assert.Equal("Beta", byId!.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ExternalSystemGateway-011: a missing name resolves to <c>null</c>.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ExternalSystemRepository_GetByName_MissingName_ReturnsNull()
|
||||
{
|
||||
var storage = NewStorage();
|
||||
await storage.InitializeAsync();
|
||||
await storage.StoreExternalSystemAsync(
|
||||
"Alpha", "https://alpha.test", "ApiKey", null, null);
|
||||
|
||||
var repo = new SiteExternalSystemRepository(storage);
|
||||
|
||||
Assert.Null(await repo.GetExternalSystemByNameAsync("DoesNotExist"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ExternalSystemGateway-011: the site repository's name-keyed method lookup
|
||||
/// returns the method scoped to its parent system, or <c>null</c> for a miss.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ExternalSystemRepository_GetMethodByName_ResolvesScopedToSystem()
|
||||
{
|
||||
var storage = NewStorage();
|
||||
await storage.InitializeAsync();
|
||||
var methodDefs = "[{\"Name\":\"getData\",\"HttpMethod\":\"GET\",\"Path\":\"/data\"}]";
|
||||
await storage.StoreExternalSystemAsync(
|
||||
"WeatherApi", "https://api.example.com", "ApiKey", null, methodDefs);
|
||||
|
||||
var repo = new SiteExternalSystemRepository(storage);
|
||||
var system = await repo.GetExternalSystemByNameAsync("WeatherApi");
|
||||
Assert.NotNull(system);
|
||||
|
||||
var method = await repo.GetMethodByNameAsync(system!.Id, "getData");
|
||||
Assert.NotNull(method);
|
||||
Assert.Equal("getData", method!.Name);
|
||||
Assert.Equal("GET", method.HttpMethod);
|
||||
|
||||
Assert.Null(await repo.GetMethodByNameAsync(system.Id, "noSuchMethod"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ExternalSystemGateway-011: the site repository's name-keyed database-connection
|
||||
/// lookup returns the matching row, or <c>null</c> for a miss.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DatabaseConnectionRepository_GetByName_ReturnsMatchingDefinition()
|
||||
{
|
||||
var storage = NewStorage();
|
||||
await storage.InitializeAsync();
|
||||
await storage.StoreDatabaseConnectionAsync(
|
||||
"Plant", "Server=plant;Database=p;", maxRetries: 3, retryDelay: TimeSpan.FromSeconds(2));
|
||||
await storage.StoreDatabaseConnectionAsync(
|
||||
"Historian", "Server=hist;Database=h;", maxRetries: 0, retryDelay: TimeSpan.FromSeconds(5));
|
||||
|
||||
var repo = new SiteExternalSystemRepository(storage);
|
||||
|
||||
var found = await repo.GetDatabaseConnectionByNameAsync("Historian");
|
||||
Assert.NotNull(found);
|
||||
Assert.Equal("Historian", found!.Name);
|
||||
Assert.Equal("Server=hist;Database=h;", found.ConnectionString);
|
||||
Assert.Equal(0, found.MaxRetries);
|
||||
|
||||
Assert.Null(await repo.GetDatabaseConnectionByNameAsync("DoesNotExist"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SiteRuntime-007: the same stability guarantee for notification lists.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user