| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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<AdoSmartOpsKpiMaster> Kpis { get; } = new();
- public List<AdoSmartOpsKpiTargetConfig> Configs { get; } = new();
- public List<AdoSmartOpsKpiTargetImportBatch> Batches { get; } = new();
- public HashSet<long> ReferencedIds { get; } = new();
- private long _id = 1;
- private long _batchId = 1;
- public Task<AdoSmartOpsKpiMaster?> FindKpiAsync(long tenantId, string metricCode, CancellationToken ct = default) =>
- Task.FromResult(Kpis.FirstOrDefault(x => x.TenantId == tenantId && x.MetricCode == metricCode));
- public Task<List<AdoSmartOpsKpiTargetConfig>> 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<List<AdoSmartOpsKpiTargetConfig>> 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<AdoSmartOpsKpiTargetConfig?> GetByIdAsync(long tenantId, long id, CancellationToken ct = default) =>
- Task.FromResult(Configs.FirstOrDefault(x => x.TenantId == tenantId && x.Id == id));
- public Task<AdoSmartOpsKpiTargetConfig> 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<bool> IsReferencedByDailyAsync(long tenantId, long configId, CancellationToken ct = default) =>
- Task.FromResult(ReferencedIds.Contains(configId));
- public Task<int> CountCommittedHashAsync(long tenantId, string sha256, CancellationToken ct = default) =>
- Task.FromResult(Batches.Count(x => x.TenantId == tenantId && x.FileSha256 == sha256 && x.Status == "COMMITTED"));
- public Task<AdoSmartOpsKpiTargetImportBatch> InsertBatchAsync(AdoSmartOpsKpiTargetImportBatch batch, CancellationToken ct = default)
- {
- batch.Id = _batchId++;
- Batches.Add(batch);
- return Task.FromResult(batch);
- }
- public Task<AdoSmartOpsKpiTargetImportBatch?> 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<decimal?> GetCurrentTargetAsync(long tenantId, long factoryId, string moduleCode, string metricCode, DateTime bizDate, CancellationToken ct = default)
- => Task.FromResult(Current);
- public Task<decimal?> GetPriorTargetAsync(long tenantId, long factoryId, string moduleCode, string metricCode, DateTime bizDate, CancellationToken ct = default)
- => Task.FromResult(Prior);
- }
|