using DynamicCrud.Tests.Fixtures; using ServicesDAO.Repositories; using Xunit; namespace DynamicCrud.Tests; public class BackupOperationsTests : IClassFixture { private readonly DbContextFixture _fixture; public BackupOperationsTests(DbContextFixture fixture) { _fixture = fixture; } // Mismo patrón de cola que backup_restore: client_bkps/services_backups_daas encuentran // operaciones pendientes con Search(supply isnull) y las reclaman con BulkUpdate(in sobre la PK). [Fact] public async Task Search_IsNull_And_BulkUpdate_In_SetSupply_LikeThePendingJobQuery() { var entityType = ModelRegistry.Resolve("backup_operations")!; var targetName = $"test-op-{Guid.NewGuid():N}"; var createData = new Dictionary { ["operation"] = "pause", ["targetType"] = "schedule", ["targetName"] = targetName, ["k8sContext"] = "test-context-ops", // request_datetime es NOT NULL sin default manejado por ApplyAuditCreate // (backup_operations no tiene CreatedAt/UpdatedAt) — hay que darlo explícito. ["requestDatetime"] = DateTime.UtcNow, // supply queda sin especificar -> NULL (pendiente) }; using var ctx1 = _fixture.CreateContext(); var (createOk, _, insertedId, createDetail) = await RepoHelper.CreateRecord(RepoHelper.Create(ctx1, entityType), createData); Assert.True(createOk, $"Create falló: {createDetail}"); using var ctx2 = _fixture.CreateContext(); var pending = await RepoHelper.Search( RepoHelper.Create(ctx2, entityType), and: new[] { new FilterCondition("targetName", "eq", targetName), new FilterCondition("supply", "isnull", ""), }); Assert.Single(pending); using var ctx3 = _fixture.CreateContext(); var (bulkOk, bulkMsg, affected, bulkDetail) = await RepoHelper.BulkUpdate( RepoHelper.Create(ctx3, entityType), and: new[] { new FilterCondition("backupOperationsID", "in", insertedId!.ToString()!) }, or: null, data: new Dictionary { ["supply"] = true }); Assert.True(bulkOk, $"BulkUpdate falló: {bulkDetail}"); Assert.Equal(1, affected); using var ctx4 = _fixture.CreateContext(); await RepoHelper.Delete(RepoHelper.Create(ctx4, entityType), insertedId); } }