using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using PolyTrader.Modules.CopyTrading.Persistence.Ef;
using PolyTraderSharp.Models;
using Xunit;
namespace PolyTrader.Tests
{
///
/// Sichert die Befunde des Linux-Sichttests vom 26.08.2026 ab
/// (docs/pruefplaene/BEFUND-Linux-Betrieb-2026-08-26.md), damit sie nicht zurückkehren.
///
public class LinuxFindingsTests
{
// ── B-5: Windows-Pfad als Standardwert unter Linux ──────────────────────────────
[Fact]
public void Mullvad_default_path_matches_the_platform()
{
string expected = System.OperatingSystem.IsWindows()
? @"C:\Program Files\Mullvad VPN\resources\mullvad.exe"
: "/usr/bin/mullvad";
Assert.Equal(expected, ServerSettings.DefaultMullvadCliPath);
Assert.Equal(expected, new ServerSettings().MullvadCliPath);
}
// ── B-14: mehrzeilige Texte in einzeiligen Feldern ──────────────────────────────
[Theory]
[InlineData(nameof(TrackedTrader.Description))]
[InlineData(nameof(TrackedTrader.Reasoning))]
public void Long_free_text_properties_are_marked_multiline(string propertyName)
{
var p = typeof(TrackedTrader).GetProperty(propertyName)!;
var attr = p.GetCustomAttribute();
Assert.NotNull(attr);
Assert.Equal(DataType.MultilineText, attr!.DataType);
}
// ── B-15: ein fehlerhafter Datensatz legt die Modul-Hydration lahm ──────────────
[Fact]
public void Assigned_accounts_round_trip_through_json()
{
var set = new System.Collections.Generic.HashSet { 1, 2 };
Assert.Equal(set, AccountIdSetJson.Deserialize(AccountIdSetJson.Serialize(set)));
}
[Fact]
public void Empty_column_becomes_an_empty_assignment()
{
Assert.Empty(AccountIdSetJson.Deserialize(null));
Assert.Empty(AccountIdSetJson.Deserialize(""));
Assert.Empty(AccountIdSetJson.Deserialize("[]"));
}
// Der Zaehler ist prozessweit. Deshalb wird die DIFFERENZ geprueft und nicht der
// absolute Wert - so bleibt der Test auch dann richtig, wenn vorher schon jemand
// einen unlesbaren Wert durchgereicht hat.
[Fact]
public void Plain_number_list_is_still_understood()
{
int before = AccountIdSetJson.MalformedCount;
Assert.Equal(new System.Collections.Generic.HashSet { 1, 2 },
AccountIdSetJson.Deserialize("1,2"));
Assert.Equal(before, AccountIdSetJson.MalformedCount);
}
[Fact]
public void Unreadable_value_yields_an_empty_set_and_is_counted()
{
int before = AccountIdSetJson.MalformedCount;
// Der Fall aus dem Test: kaputter Wert statt JSON-Array. Frueher warf die
// EF-Wertkonvertierung hier und es wurde KEIN einziger Trader geladen.
Assert.Empty(AccountIdSetJson.Deserialize("{kaputt"));
Assert.Equal(before + 1, AccountIdSetJson.MalformedCount);
Assert.Equal("{kaputt", AccountIdSetJson.LastMalformedValue);
}
[Fact]
public void Text_that_is_not_a_number_list_is_not_silently_accepted()
{
int before = AccountIdSetJson.MalformedCount;
Assert.Empty(AccountIdSetJson.Deserialize("1,zwei"));
Assert.Equal(before + 1, AccountIdSetJson.MalformedCount);
}
}
}