AccountingNext/Schaad.Accounting.Tests/SettingsServiceTestShould.cs
Claudio Schaad cbc1cd3f1f Restructure data folder to {mandator}/{year}, uploads and backup at root
New layout below DataPath (defined in DataFolders):
  {mandator}/{year}/*.json
  uploads/{mandator}/{year}/
  backup/{mandator}/{year}/

XmlToJsonMigrator becomes DataMigrator with two phases: first move the old
{year}/{mandator}/Data, uploads and {year}/backup folders into the new layout
unchanged, then convert the XML data files to JSON. Nothing is overwritten;
an identical file at the target is dropped, a different one stops startup.
Old folders are removed only once empty.

SettingsService builds the new paths; GetYearMandatorPath and
GetLastYearMandatorPath are removed as they now equal the data paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 13:57:58 +02:00

63 lines
2.1 KiB
C#

using Schaad.Accounting.Datasets;
using Schaad.Accounting.Services;
using Shouldly;
namespace Schaad.Accounting.Tests;
public class SettingsServiceTestShould : IDisposable
{
private readonly string dataPath;
private readonly SettingsService sut;
public SettingsServiceTestShould()
{
dataPath = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dataPath);
sut = new SettingsService(new SettingsDataset { DataPath = dataPath, DefaultMandator = "Mandator" });
sut.SetYear(2025);
}
public void Dispose()
{
if (Directory.Exists(dataPath))
{
Directory.Delete(dataPath, recursive: true);
}
}
[Fact]
public void ReturnMandatorYearFolderWhenGettingDbPath()
{
sut.GetDbPath().ShouldBe(Path.Combine(dataPath, "Mandator", "2025"));
sut.GetLastYearDbPath().ShouldBe(Path.Combine(dataPath, "Mandator", "2024"));
}
[Fact]
public void ReturnFoldersBelowRootUploadsWhenGettingUploadPaths()
{
sut.GetUploadPath().ShouldBe(Path.Combine(dataPath, "uploads", "Mandator", "2025"));
sut.GetCreditCardStatementPath().ShouldBe(Path.Combine(dataPath, "uploads", "Mandator", "2025", "creditCard"));
}
[Fact]
public void ReturnZipBelowRootBackupWhenGettingBackupFilePath()
{
var path = sut.GetBackupFilePath();
Path.GetDirectoryName(path).ShouldBe(Path.Combine(dataPath, "backup", "Mandator", "2025"));
Path.GetExtension(path).ShouldBe(".zip");
}
[Fact]
public void ListOnlyMandatorsWithThatYearWhenGettingMandators()
{
Directory.CreateDirectory(Path.Combine(dataPath, "Mandator", "2025"));
Directory.CreateDirectory(Path.Combine(dataPath, "Other", "2025"));
Directory.CreateDirectory(Path.Combine(dataPath, "OnlyOlder", "2023"));
Directory.CreateDirectory(Path.Combine(dataPath, "uploads", "2025"));
Directory.CreateDirectory(Path.Combine(dataPath, "backup", "2025"));
sut.GetMandators(2025).OrderBy(m => m).ShouldBe(["Mandator", "Other"]);
}
}