using StellaOps.AirGap.Importer.Models; using StellaOps.AirGap.Importer.Repositories; namespace StellaOps.AirGap.Importer.Tests; public class InMemoryBundleRepositoriesTests { [Fact] public async Task CatalogUpsertOverwritesPerTenant() { var repo = new InMemoryBundleCatalogRepository(); var entry1 = new BundleCatalogEntry("t1", "b1", "d1", DateTimeOffset.UnixEpoch, new[] { "a" }); var entry2 = new BundleCatalogEntry("t1", "b1", "d2", DateTimeOffset.UnixEpoch.AddMinutes(1), new[] { "b" }); await repo.UpsertAsync(entry1, default); await repo.UpsertAsync(entry2, default); var list = await repo.ListAsync("t1", default); Assert.Single(list); Assert.Equal("d2", list[0].Digest); } [Fact] public async Task CatalogIsTenantIsolated() { var repo = new InMemoryBundleCatalogRepository(); await repo.UpsertAsync(new BundleCatalogEntry("t1", "b1", "d1", DateTimeOffset.UnixEpoch, Array.Empty()), default); await repo.UpsertAsync(new BundleCatalogEntry("t2", "b1", "d2", DateTimeOffset.UnixEpoch, Array.Empty()), default); var t1 = await repo.ListAsync("t1", default); Assert.Single(t1); Assert.Equal("d1", t1[0].Digest); } [Fact] public async Task ItemsOrderedByPath() { var repo = new InMemoryBundleItemRepository(); await repo.UpsertManyAsync(new[] { new BundleItem("t1", "b1", "b.txt", "d2", 10), new BundleItem("t1", "b1", "a.txt", "d1", 5) }, default); var list = await repo.ListByBundleAsync("t1", "b1", default); Assert.Equal(new[] { "a.txt", "b.txt" }, list.Select(i => i.Path).ToArray()); } [Fact] public async Task ItemsTenantIsolated() { var repo = new InMemoryBundleItemRepository(); await repo.UpsertManyAsync(new[] { new BundleItem("t1", "b1", "a.txt", "d1", 1), new BundleItem("t2", "b1", "a.txt", "d2", 1) }, default); var list = await repo.ListByBundleAsync("t1", "b1", default); Assert.Single(list); Assert.Equal("d1", list[0].Digest); } }