Co-authored-by: Claudio Schaad <c.schaad@pog.ch> Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
69 lines
2.3 KiB
C#
69 lines
2.3 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 ReturnMandatorFolderWithoutYearWhenGettingMandatorPath()
|
|
{
|
|
sut.GetMandatorPath().ShouldBe(Path.Combine(dataPath, "Mandator"));
|
|
}
|
|
|
|
[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"]);
|
|
}
|
|
}
|