using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using FinlyticCore.Dtos.Settings; using FinlyticCore.Models.Settings; using FinlyticCore.Services; namespace FinlyticEngine.Tests.TestSupport; /// /// Hand-written in-memory fake for . Rules.md ยง13 forbids test mocks inside /// production assemblies, so this fake lives exclusively in the test project. Only the /// overloads are exercised by the services under test /// (CompositeOpportunityScorer, TradeLifecycleService); the remaining interface members throw /// so an accidental new dependency on them fails loudly instead of /// silently returning a wrong default. /// public class FakeSettingsService : ISettingsService { private readonly ConcurrentDictionary _overrides = new(StringComparer.Ordinal); /// /// Registers an explicit value for the given setting key, overriding its compiled-in default for the /// lifetime of this fake instance. /// public void Set(SettingKey key, T value) => _overrides[key.Name] = value; /// public Task GetSettingAsync(SettingKey key, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(key); if (_overrides.TryGetValue(key.Name, out var value) && value is T typed) { return Task.FromResult(typed); } return Task.FromResult(key.DefaultValue); } /// public Task SetSettingAsync(SettingKey key, T value, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(key); _overrides[key.Name] = value; return Task.CompletedTask; } /// public Task GetSettingAsync(TEnum enumKey, T defaultValue = default!, CancellationToken cancellationToken = default) where TEnum : struct, Enum => throw new NotSupportedException("Not exercised by any service under test in this suite."); /// public Task SetSettingAsync(TEnum enumKey, T value, CancellationToken cancellationToken = default) where TEnum : struct, Enum => throw new NotSupportedException("Not exercised by any service under test in this suite."); /// public Task GetSettingAsync(string key, T defaultValue = default!, CancellationToken cancellationToken = default) => throw new NotSupportedException("Not exercised by any service under test in this suite."); /// public Task SetSettingAsync(string key, T value, CancellationToken cancellationToken = default) => throw new NotSupportedException("Not exercised by any service under test in this suite."); /// public Task> GetAllRegisteredSettingsAsync(IEnumerable? customKeyHolders = null, CancellationToken cancellationToken = default) => throw new NotSupportedException("Not exercised by any service under test in this suite."); /// public Task UpdateSettingsAsync(Dictionary updatedSettings, CancellationToken cancellationToken = default) => throw new NotSupportedException("Not exercised by any service under test in this suite."); }