using Admin.NET.Plugin.AiDOP.Entity; using Admin.NET.Plugin.AiDOP.SmartOps; namespace Admin.NET.Plugin.AiDOP.Tests.SmartOps; internal sealed class FakeKpiTargetStore : IKpiTargetConfigStore { public List Kpis { get; } = new(); public List Configs { get; } = new(); public List Batches { get; } = new(); public HashSet ReferencedIds { get; } = new(); private long _id = 1; private long _batchId = 1; public Task FindKpiAsync(long tenantId, string metricCode, CancellationToken ct = default) => Task.FromResult(Kpis.FirstOrDefault(x => x.TenantId == tenantId && x.MetricCode == metricCode)); public Task> ListAsync(long tenantId, string metricCode, long? factoryId, CancellationToken ct = default) => Task.FromResult(Configs.Where(x => x.TenantId == tenantId && x.MetricCode == metricCode && (!factoryId.HasValue || x.FactoryId == factoryId.Value)).ToList()); public Task> ListActiveScopeAsync(long tenantId, long factoryId, string metricCode, CancellationToken ct = default) => Task.FromResult(Configs.Where(x => x.TenantId == tenantId && x.FactoryId == factoryId && x.MetricCode == metricCode && x.Status == 1).ToList()); public Task GetByIdAsync(long tenantId, long id, CancellationToken ct = default) => Task.FromResult(Configs.FirstOrDefault(x => x.TenantId == tenantId && x.Id == id)); public Task InsertAsync(AdoSmartOpsKpiTargetConfig row, CancellationToken ct = default) { row.Id = _id++; Configs.Add(row); return Task.FromResult(row); } public Task UpdateAsync(AdoSmartOpsKpiTargetConfig row, CancellationToken ct = default) => Task.CompletedTask; public Task IsReferencedByDailyAsync(long tenantId, long configId, CancellationToken ct = default) => Task.FromResult(ReferencedIds.Contains(configId)); public Task CountCommittedHashAsync(long tenantId, string sha256, CancellationToken ct = default) => Task.FromResult(Batches.Count(x => x.TenantId == tenantId && x.FileSha256 == sha256 && x.Status == "COMMITTED")); public Task InsertBatchAsync(AdoSmartOpsKpiTargetImportBatch batch, CancellationToken ct = default) { batch.Id = _batchId++; Batches.Add(batch); return Task.FromResult(batch); } public Task GetBatchAsync(long tenantId, long batchId, CancellationToken ct = default) => Task.FromResult(Batches.FirstOrDefault(x => x.TenantId == tenantId && x.Id == batchId)); public Task UpdateBatchAsync(AdoSmartOpsKpiTargetImportBatch batch, CancellationToken ct = default) => Task.CompletedTask; } internal sealed class FakeDailyReader : IKpiDailyTargetReader { public decimal? Current { get; set; } public decimal? Prior { get; set; } public Task GetCurrentTargetAsync(long tenantId, long factoryId, string moduleCode, string metricCode, DateTime bizDate, CancellationToken ct = default) => Task.FromResult(Current); public Task GetPriorTargetAsync(long tenantId, long factoryId, string moduleCode, string metricCode, DateTime bizDate, CancellationToken ct = default) => Task.FromResult(Prior); }