Il servizio stava in Mimante/ con, alla radice, il README e il .gitignore della vecchia app WPF. Come negli altri progetti (Febe), soluzione, sorgenti, documenti e Docker stanno ora alla radice. Solo spostamenti con git mv, così la storia di ogni file si segue con --follow; nessun contenuto cambia. Tolti: il README della app WPF (quello del bot prende il suo posto), Modifiche.txt (vuoto) e i due flussi di .gitea/workflows, che non sono mai partiti e pubblicavano la porta 5432 sul Docker dove gira il PostgreSQL vero: li sostituisce la CI nuova. Fino ad allora nessun flusso parte. .gitignore unico, preso da Febe, con le voci del bot più /dati/ (i dati scaricati per l'analisi) e .claude/worktrees/. Build e 288 test verdi dalla radice (14 sul database saltati senza TEST_DB_HOST). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4.0 KiB
C#
94 lines
4.0 KiB
C#
using System.Reflection;
|
|
using System.Text.Json;
|
|
using BidooBidBot.Settings;
|
|
using Xunit;
|
|
|
|
namespace BidooBidBot.Tests;
|
|
|
|
/// <summary>Le impostazioni che valgono solo dal prossimo avvio (<see cref="SettingsStore.RestartRequired"/>).</summary>
|
|
public class SettingsRestartTests
|
|
{
|
|
private static Dictionary<string, JsonElement> Patch(string json) =>
|
|
JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json)!;
|
|
|
|
private const string StartupKey = nameof(AppSettings.LearningBootstrapSecondsPerStart);
|
|
|
|
[Fact]
|
|
public void Ogni_chiave_dell_elenco_del_riavvio_e_un_impostazione_vera_con_la_sua_etichetta()
|
|
{
|
|
Assert.NotEmpty(SettingsStore.RestartRequired);
|
|
foreach (var key in SettingsStore.RestartRequired)
|
|
{
|
|
var prop = typeof(AppSettings).GetProperty(key, BindingFlags.Public | BindingFlags.Instance);
|
|
Assert.True(prop is { CanRead: true, CanWrite: true }, $"{key} non è una proprietà di AppSettings");
|
|
Assert.NotEqual(nameof(AppSettings.SettingsSchemaVersion), key);
|
|
|
|
var label = SettingsStore.RestartLabel(key);
|
|
Assert.False(string.IsNullOrWhiteSpace(label));
|
|
Assert.NotEqual(key, label);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Lo_studio_all_avvio_vale_dal_prossimo_riavvio_e_il_resto_subito()
|
|
{
|
|
Assert.Contains(StartupKey, SettingsStore.RestartRequired);
|
|
// Riapplicate a ogni salvataggio (Bot.ApplyLogSettings e Bot.OnSettingsChanged): non chiedono il riavvio.
|
|
Assert.DoesNotContain(nameof(AppSettings.MaxLogLinesPerAuction), SettingsStore.RestartRequired);
|
|
Assert.DoesNotContain(nameof(AppSettings.MaxGlobalLogLines), SettingsStore.RestartRequired);
|
|
Assert.DoesNotContain(nameof(AppSettings.MaxRequestsPerSecond), SettingsStore.RestartRequired);
|
|
// L'etichetta per una chiave fuori elenco è la chiave stessa.
|
|
Assert.Equal("DailyBudgetEuro", SettingsStore.RestartLabel("DailyBudgetEuro"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Il_salvataggio_segnala_le_chiavi_che_chiedono_il_riavvio()
|
|
{
|
|
var store = new SettingsStore(null, null);
|
|
|
|
var mixed = await store.SaveAsync(Patch($$"""{"{{StartupKey}}": 300, "DailyBudgetEuro": 5}"""));
|
|
Assert.True(mixed.Ok);
|
|
Assert.Equal(new[] { StartupKey }, mixed.RestartKeys);
|
|
Assert.Equal(300, store.Current.LearningBootstrapSecondsPerStart);
|
|
Assert.Equal(2, mixed.Changes.Count);
|
|
|
|
// Solo chiavi che valgono subito: nessun avviso.
|
|
var live = await store.SaveAsync(Patch("""{"DailyBudgetEuro": 7, "MaxLogLinesPerAuction": 800}"""));
|
|
Assert.True(live.Ok);
|
|
Assert.Empty(live.RestartKeys);
|
|
|
|
// Lo stesso valore di prima non è una modifica: niente da segnalare.
|
|
var same = await store.SaveAsync(Patch($$"""{"{{StartupKey}}": 300}"""));
|
|
Assert.True(same.Ok);
|
|
Assert.Empty(same.Changes);
|
|
Assert.Empty(same.RestartKeys);
|
|
|
|
// Un salvataggio rifiutato non segnala nulla.
|
|
var bad = await store.SaveAsync(Patch($$"""{"{{StartupKey}}": "tanto"}"""));
|
|
Assert.False(bad.Ok);
|
|
Assert.Empty(bad.RestartKeys);
|
|
}
|
|
|
|
[Fact]
|
|
public void Le_chiavi_cambiate_si_confrontano_dopo_la_normalizzazione()
|
|
{
|
|
var before = new AppSettings();
|
|
var after = SettingsStore.Clone(before);
|
|
after.DailyBudgetEuro = 12;
|
|
Assert.Empty(SettingsStore.RestartKeysChanged(before, after));
|
|
|
|
after.LearningBootstrapSecondsPerStart = 5; // sotto il minimo: diventa 10, sempre diverso da 120
|
|
SettingsStore.Normalize(after);
|
|
Assert.Equal(new[] { StartupKey }, SettingsStore.RestartKeysChanged(before, after));
|
|
}
|
|
|
|
[Fact]
|
|
public void Il_messaggio_elenca_le_etichette_della_pagina()
|
|
{
|
|
var msg = SettingsStore.RestartMessage(new[] { StartupKey });
|
|
Assert.StartsWith("Salvato. Queste modifiche valgono dal prossimo riavvio: ", msg);
|
|
Assert.Contains("Studio all'avvio (secondi)", msg);
|
|
Assert.DoesNotContain(StartupKey, msg);
|
|
}
|
|
}
|