diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ea8de59 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.verified.txt text eol=lf working-tree-encoding=UTF-8 +*.verified.xml text eol=lf working-tree-encoding=UTF-8 +*.verified.json text eol=lf working-tree-encoding=UTF-8 +*.verified.bin binary \ No newline at end of file diff --git a/src/ModuleCore/Calendar/CalendarGenerator.cs b/src/ModuleCore/Calendar/CalendarGenerator.cs index 8494fc9..daa81ce 100644 --- a/src/ModuleCore/Calendar/CalendarGenerator.cs +++ b/src/ModuleCore/Calendar/CalendarGenerator.cs @@ -1,4 +1,4 @@ -using System.Globalization; +using System.Globalization; using System.Text; namespace ModuleCore.Calendar; diff --git a/src/ModuleCore/Database/DatabaseManager.cs b/src/ModuleCore/Database/DatabaseManager.cs index 6f6810d..beac4f2 100644 --- a/src/ModuleCore/Database/DatabaseManager.cs +++ b/src/ModuleCore/Database/DatabaseManager.cs @@ -1,4 +1,4 @@ -using SQLite; +using SQLite; namespace ModuleCore.Database; @@ -51,6 +51,18 @@ public class DatabaseManager return exists ?? false; } + /// + /// Deletes the current database file. This will cause any future instance methods to fail on database action if + /// a new instance is not created. + /// + /// This method should be avoided unless calling from a test. + /// + /// + internal void DeleteDatabase() + { + _databaseLocation.Delete(); + } + /// /// Removes double dots from the filename and removes the file extension /// diff --git a/src/ModuleCore/Directory.Build.props b/src/ModuleCore/Directory.Build.props index e0bdda9..dd32fa3 100644 --- a/src/ModuleCore/Directory.Build.props +++ b/src/ModuleCore/Directory.Build.props @@ -1,4 +1,4 @@ - + 0.0.1 dev diff --git a/src/ModuleCore/Git/GitManager.cs b/src/ModuleCore/Git/GitManager.cs index 1312b03..bd7a135 100644 --- a/src/ModuleCore/Git/GitManager.cs +++ b/src/ModuleCore/Git/GitManager.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Diagnostics; using ModuleCore.Database; using ModuleCore.Git.Models; @@ -14,10 +14,12 @@ public class GitManager private readonly DatabaseManager _db; private readonly ConcurrentDictionary _registrations; - private GitManager() + private GitManager(string? databaseName = null) { _registrations = new ConcurrentDictionary(); - _db = new DatabaseManager("git.db"); + // Regular usage of this constructor will never pass a database name in. Currently only tests should be hitting + // a code path that has a different database name + _db = new DatabaseManager(databaseName ?? "git.db"); InitialiseRegistrations(); } @@ -27,7 +29,15 @@ public class GitManager /// /// Always returns a new clean instance of GitManager /// - internal static GitManager InternalFreshInstance => new(); + internal static GitManager InternalFreshInstance(string databaseName) => new(databaseName); + + /// + /// Deletes the underlying database file. + /// + /// Avoid calling this outside of tests. + /// + /// + internal void DeleteDatabase() => _db.DeleteDatabase(); /// /// Creates up any database tables and loads all previously saved git registrations. diff --git a/src/ModuleCore/Git/Models/GitRegistration.cs b/src/ModuleCore/Git/Models/GitRegistration.cs index 11eea11..1a94184 100644 --- a/src/ModuleCore/Git/Models/GitRegistration.cs +++ b/src/ModuleCore/Git/Models/GitRegistration.cs @@ -1,4 +1,4 @@ -namespace ModuleCore.Git.Models; +namespace ModuleCore.Git.Models; public class GitRegistration { diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-06-01.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-06-01.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-06-01.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-06-01.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-07-01.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-07-01.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-07-01.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-07-01.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-08-01.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-08-01.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-08-01.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-08-01.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/cs-CZ.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/cs-CZ.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/cs-CZ.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/cs-CZ.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/da-DK.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/da-DK.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/da-DK.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/da-DK.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/en-AU.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/en-AU.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/en-AU.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/en-AU.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/es-PR.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/es-PR.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/es-PR.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/es-PR.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/fr-LU.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/fr-LU.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/fr-LU.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/fr-LU.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/nl-NL.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/nl-NL.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/nl-NL.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/nl-NL.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/te-IN.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/te-IN.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/te-IN.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/te-IN.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt diff --git a/tests/ModuleTests/Calendar/snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt similarity index 100% rename from tests/ModuleTests/Calendar/snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt diff --git a/tests/ModuleTests/Git/AddRegistrationTests.cs b/tests/ModuleTests/Git/AddRegistrationTests.cs index 6c5d2a2..ced609b 100644 --- a/tests/ModuleTests/Git/AddRegistrationTests.cs +++ b/tests/ModuleTests/Git/AddRegistrationTests.cs @@ -24,13 +24,15 @@ public class AddRegistrationTests { Settings.UseFileName($"{nameof(BasicRepoRegistration)}_{testData.testId}"); - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitManager.InternalFreshInstance(nameof(BasicRepoRegistration)); var repoRegistration = gitManager.RegisterRepo("Test:/some/test/repo", testData.path); var sb = new StringBuilder(); sb.AppendLine($"Attempted to register: {testData.path}") .AppendLine($"Registration result: {repoRegistration}"); + gitManager.DeleteDatabase(); + return Verify(sb, Settings); } @@ -39,11 +41,13 @@ public class AddRegistrationTests { Settings.UseFileName(nameof(RepoRegistrationWithEmptyName)); - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithEmptyName)); var testRepoAbsolutePath = "Test:/some/test/repo"; var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, ""); + gitManager.DeleteDatabase(); + Assert.Equal("repo", emptyName); } @@ -52,13 +56,15 @@ public class AddRegistrationTests { Settings.UseFileName(nameof(RepoRegistrationWithNullName)); - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithNullName)); var testRepoAbsolutePath = "Test:/some/test/repo"; // Name is technically not-nullable, but string is a reference type so null can be passed in so we should test // it regardless var nullName = gitManager.RegisterRepo(testRepoAbsolutePath, null!); + gitManager.DeleteDatabase(); + Assert.Equal("repo", nullName); } @@ -67,11 +73,13 @@ public class AddRegistrationTests { Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName)); - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName)); var testRepoAbsolutePath = "Test:/some/test/repo"; var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " "); + gitManager.DeleteDatabase(); + Assert.Equal("repo", whitespaceName); } @@ -80,7 +88,7 @@ public class AddRegistrationTests { Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName)); - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName)); var testRepoAbsolutePath = "Test:/some/test/repo"; string[] paths = ["test", "nested", "path"]; var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths)); @@ -93,6 +101,8 @@ public class AddRegistrationTests Assert.Equal(Path.Combine(paths[..1]), secondRegistration); Assert.Throws(() => gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]))); + + gitManager.DeleteDatabase(); } [Fact] @@ -100,7 +110,7 @@ public class AddRegistrationTests { Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName)); - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName)); var testRepoAbsolutePath = "Test:/some/test/repo"; string[] paths = ["test", "nested", "path"]; var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths)); @@ -110,6 +120,8 @@ public class AddRegistrationTests var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])); var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator); + gitManager.DeleteDatabase(); + Assert.Equal(Path.Combine(paths), firstRegistration); Assert.Equal(Path.Combine(paths[..1]), secondRegistration); Assert.Equal(names.AltSeparator, differentPathSeparatorRegistration); diff --git a/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_0.verified.txt b/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_0.verified.txt index ee51d39..3183455 100644 --- a/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_0.verified.txt +++ b/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_0.verified.txt @@ -1,2 +1,2 @@ -Attempted to register: test +Attempted to register: test Registration result: test diff --git a/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_1.verified.txt b/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_1.verified.txt index 628d265..e9b945d 100644 --- a/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_1.verified.txt +++ b/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_1.verified.txt @@ -1,2 +1,2 @@ -Attempted to register: test\path +Attempted to register: test\path Registration result: test\path diff --git a/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_2.verified.txt b/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_2.verified.txt index 1b9406e..7f2c4e6 100644 --- a/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_2.verified.txt +++ b/tests/ModuleTests/Git/Snapshots/AddRegistrationTests/BasicRepoRegistration_2.verified.txt @@ -1,2 +1,2 @@ -Attempted to register: other/path +Attempted to register: other/path Registration result: other/path