Files
Nonemm/tests/Nonemm.App.Tests/UserPathsTests.cs
ericek111 d49c87f86b Move the files into N1MM's own folder
The root is Documents/N1MM Logger+ now, so a station that runs both programs
has one set of files rather than two: one Databases folder, one SupportFiles,
one Wav with a folder per operator in it. What N1MM has no place for goes in a
Nonemm folder inside it, which is where settings.json sits.

A system that does not say where Documents is — most Linux systems — gets
~/Documents/N1MM Logger+.

Files an older version kept in Documents\Nonemm or ~/.config/nonemm are copied
in the first time this version runs, and the log and call history paths in the
settings are moved with them, so the copy that opens is the copy that came
over. The older folder is left as it was.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
2026-08-31 23:07:03 +00:00

98 lines
3.1 KiB
C#

using Nonemm.App.Configuration;
namespace Nonemm.App.Tests;
/// The folders under the user's own directory, which are N1MM's.
public class UserPathsTests : IDisposable
{
private readonly string root = Path.Combine(Path.GetTempPath(), $"nonemm-{Guid.NewGuid():N}");
public void Dispose()
{
if (Directory.Exists(root))
{
Directory.Delete(root, recursive: true);
}
}
[Fact]
public void TheFoldersAreN1mmsOwnNames()
{
UserPaths paths = new(root);
paths.CreateFolders();
string[] made = [.. Directory.GetDirectories(root).Select(Path.GetFileName).OfType<string>().Order()];
Assert.Equal(
[
"CallHistoryFiles", "Databases", "Diagnostics", "ExportFiles", "FunctionKeyMessages",
"GoalFiles", "LettersFiles", "Nonemm", "QsoRecording", "SkinsAndLayouts",
"SupportFiles", "SystemFiles", "TransactionLogFiles", "UserDefinedContests", "Wav",
],
made);
}
/// N1MM plays `Wav\<operator>\Cq.wav`, so that is where the recordings of
/// whoever is at the microphone are looked for here as well.
[Fact]
public void AnOperatorHasHisOwnFolderOfRecordings()
{
UserPaths paths = new(root);
Assert.Equal(Path.Combine(root, "Wav", "OM3KFF"), paths.WavFor("om3kff"));
Assert.Equal(Path.Combine(root, "Wav"), paths.WavFor(" "));
}
[Fact]
public void MakingTheFoldersTwiceIsNotAnError()
{
UserPaths paths = new(root);
paths.CreateFolders();
paths.CreateFolders();
Assert.True(Directory.Exists(paths.Wav));
}
/// What N1MM has no place for lives in a folder of this program's own.
[Fact]
public void TheSettingsFileIsInOurOwnFolder()
{
UserPaths paths = new(root);
Assert.Equal(Path.Combine(root, "Nonemm", "settings.json"), paths.SettingsFile);
}
[Fact]
public void AnOlderVersionsFilesAreCopiedInOnce()
{
string older = Path.Combine(root, "older");
Directory.CreateDirectory(Path.Combine(older, "Databases"));
File.WriteAllText(Path.Combine(older, "Databases", "om5m.s3db"), "log");
string database = Path.Combine(older, "Databases", "om5m.s3db");
new Settings { DatabasePath = database }.Save(Path.Combine(older, "settings.json"));
UserPaths paths = new(Path.Combine(root, "new"));
paths.CreateFolders();
Assert.True(paths.AdoptOlderFiles(older));
Assert.Equal("log", File.ReadAllText(Path.Combine(paths.Databases, "om5m.s3db")));
// the log that was opened is the log that was brought over
Assert.Equal(
Path.Combine(paths.Databases, "om5m.s3db"),
Settings.Load(paths.SettingsFile).DatabasePath);
Assert.False(paths.AdoptOlderFiles(older));
// the older folder is left as it was
Assert.True(File.Exists(database));
}
[Fact]
public void NothingIsCopiedWhenThereIsNoOlderFolder()
{
UserPaths paths = new(root);
paths.CreateFolders();
Assert.False(paths.AdoptOlderFiles(Path.Combine(root, "nowhere")));
}
}