feat(engine): add FinlyticEngine microservice with trade lifecycle, AI reasoning gate, composite scoring, and unit tests
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Hand-written in-memory fake for <see cref="ISettingsService"/>. Rules.md §13 forbids test mocks inside
|
||||
/// production assemblies, so this fake lives exclusively in the test project. Only the
|
||||
/// <see cref="SettingKey{T}"/> overloads are exercised by the services under test
|
||||
/// (CompositeOpportunityScorer, TradeLifecycleService); the remaining interface members throw
|
||||
/// <see cref="NotSupportedException"/> so an accidental new dependency on them fails loudly instead of
|
||||
/// silently returning a wrong default.
|
||||
/// </summary>
|
||||
public class FakeSettingsService : ISettingsService
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, object?> _overrides = new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>
|
||||
/// Registers an explicit value for the given setting key, overriding its compiled-in default for the
|
||||
/// lifetime of this fake instance.
|
||||
/// </summary>
|
||||
public void Set<T>(SettingKey<T> key, T value) => _overrides[key.Name] = value;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<T> GetSettingAsync<T>(SettingKey<T> 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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetSettingAsync<T>(SettingKey<T> key, T value, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(key);
|
||||
_overrides[key.Name] = value;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<T> GetSettingAsync<TEnum, T>(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.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetSettingAsync<TEnum, T>(TEnum enumKey, T value, CancellationToken cancellationToken = default)
|
||||
where TEnum : struct, Enum
|
||||
=> throw new NotSupportedException("Not exercised by any service under test in this suite.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<T> GetSettingAsync<T>(string key, T defaultValue = default!, CancellationToken cancellationToken = default)
|
||||
=> throw new NotSupportedException("Not exercised by any service under test in this suite.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task SetSettingAsync<T>(string key, T value, CancellationToken cancellationToken = default)
|
||||
=> throw new NotSupportedException("Not exercised by any service under test in this suite.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<List<DynamicSettingDto>> GetAllRegisteredSettingsAsync(IEnumerable<Type>? customKeyHolders = null, CancellationToken cancellationToken = default)
|
||||
=> throw new NotSupportedException("Not exercised by any service under test in this suite.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task UpdateSettingsAsync(Dictionary<string, object?> updatedSettings, CancellationToken cancellationToken = default)
|
||||
=> throw new NotSupportedException("Not exercised by any service under test in this suite.");
|
||||
}
|
||||
Reference in New Issue
Block a user