feat(instances): GetInstancesPagedAsync SQL-side filter/order/page

This commit is contained in:
Joseph Doherty
2026-10-22 06:06:27 -04:00
parent 6bcca4b344
commit bc1aca0ee6
3 changed files with 76 additions and 0 deletions
@@ -280,6 +280,38 @@ public class CentralUiRepositoryTests : IDisposable
Assert.Single(instances);
}
/// <summary>Verifies paged instances filter in SQL, order by name, page and report the total.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task GetInstancesPaged_FiltersOrdersAndPages()
{
var site1 = new Site("Site1", "S-001");
var site2 = new Site("Site2", "S-002");
var template = new Template("T1");
_context.Sites.AddRange(site1, site2);
_context.Templates.Add(template);
await _context.SaveChangesAsync();
_context.Instances.AddRange(
new Instance("Pump3") { SiteId = site1.Id, TemplateId = template.Id },
new Instance("Pump1") { SiteId = site1.Id, TemplateId = template.Id },
new Instance("Pump2") { SiteId = site2.Id, TemplateId = template.Id },
new Instance("XPump") { SiteId = site1.Id, TemplateId = template.Id });
await _context.SaveChangesAsync();
var (rows, total) = await _repository.GetInstancesPagedAsync(null, null, "Pump", 1, 2);
Assert.Equal(3, total);
Assert.Equal(new[] { "Pump2", "Pump3" }, rows.Select(r => r.UniqueName));
var (scoped, scopedTotal) = await _repository.GetInstancesPagedAsync(new[] { site1.Id }, template.Id, "Pump", 0, 10);
Assert.Equal(2, scopedTotal);
Assert.Equal(new[] { "Pump1", "Pump3" }, scoped.Select(r => r.UniqueName));
var (none, noneTotal) = await _repository.GetInstancesPagedAsync(Array.Empty<int>(), null, null, 0, 10);
Assert.Empty(none);
Assert.Equal(0, noneTotal);
}
/// <summary>Verifies that recent deployments are returned in reverse chronological order.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]