Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba07e1618a | |||
| cf782211aa | |||
| cb01efd323 | |||
| e1bd84c05e |
26 changed files with 55 additions and 17 deletions
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
|
|
@ -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
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace ModuleCore.Calendar;
|
namespace ModuleCore.Calendar;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using SQLite;
|
using SQLite;
|
||||||
|
|
||||||
namespace ModuleCore.Database;
|
namespace ModuleCore.Database;
|
||||||
|
|
||||||
|
|
@ -51,6 +51,18 @@ public class DatabaseManager
|
||||||
return exists ?? false;
|
return exists ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the current database file. This will cause any future instance methods to fail on database action if
|
||||||
|
/// a new instance is not created.
|
||||||
|
/// <para>
|
||||||
|
/// This method should be avoided unless calling from a test.
|
||||||
|
/// </para>
|
||||||
|
/// </summary>
|
||||||
|
internal void DeleteDatabase()
|
||||||
|
{
|
||||||
|
_databaseLocation.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes double dots from the filename and removes the file extension
|
/// Removes double dots from the filename and removes the file extension
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>0.0.1</VersionPrefix>
|
<VersionPrefix>0.0.1</VersionPrefix>
|
||||||
<VersionSuffix>dev</VersionSuffix>
|
<VersionSuffix>dev</VersionSuffix>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using ModuleCore.Database;
|
using ModuleCore.Database;
|
||||||
using ModuleCore.Git.Models;
|
using ModuleCore.Git.Models;
|
||||||
|
|
@ -14,10 +14,12 @@ public class GitManager
|
||||||
private readonly DatabaseManager _db;
|
private readonly DatabaseManager _db;
|
||||||
private readonly ConcurrentDictionary<string, InternalGitRegistration> _registrations;
|
private readonly ConcurrentDictionary<string, InternalGitRegistration> _registrations;
|
||||||
|
|
||||||
private GitManager()
|
private GitManager(string? databaseName = null)
|
||||||
{
|
{
|
||||||
_registrations = new ConcurrentDictionary<string, InternalGitRegistration>();
|
_registrations = new ConcurrentDictionary<string, InternalGitRegistration>();
|
||||||
_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();
|
InitialiseRegistrations();
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +29,15 @@ public class GitManager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Always returns a new clean instance of GitManager
|
/// Always returns a new clean instance of GitManager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static GitManager InternalFreshInstance => new();
|
internal static GitManager InternalFreshInstance(string databaseName) => new(databaseName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the underlying database file.
|
||||||
|
/// <para>
|
||||||
|
/// Avoid calling this outside of tests.
|
||||||
|
/// </para>
|
||||||
|
/// </summary>
|
||||||
|
internal void DeleteDatabase() => _db.DeleteDatabase();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates up any database tables and loads all previously saved git registrations.
|
/// Creates up any database tables and loads all previously saved git registrations.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace ModuleCore.Git.Models;
|
namespace ModuleCore.Git.Models;
|
||||||
|
|
||||||
public class GitRegistration
|
public class GitRegistration
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,15 @@ public class AddRegistrationTests
|
||||||
{
|
{
|
||||||
Settings.UseFileName($"{nameof(BasicRepoRegistration)}_{testData.testId}");
|
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 repoRegistration = gitManager.RegisterRepo("Test:/some/test/repo", testData.path);
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.AppendLine($"Attempted to register: {testData.path}")
|
sb.AppendLine($"Attempted to register: {testData.path}")
|
||||||
.AppendLine($"Registration result: {repoRegistration}");
|
.AppendLine($"Registration result: {repoRegistration}");
|
||||||
|
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
|
||||||
return Verify(sb, Settings);
|
return Verify(sb, Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,11 +41,13 @@ public class AddRegistrationTests
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithEmptyName));
|
Settings.UseFileName(nameof(RepoRegistrationWithEmptyName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance;
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithEmptyName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
|
|
||||||
var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, "");
|
var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, "");
|
||||||
|
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
|
||||||
Assert.Equal("repo", emptyName);
|
Assert.Equal("repo", emptyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,13 +56,15 @@ public class AddRegistrationTests
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithNullName));
|
Settings.UseFileName(nameof(RepoRegistrationWithNullName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance;
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithNullName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
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
|
// Name is technically not-nullable, but string is a reference type so null can be passed in so we should test
|
||||||
// it regardless
|
// it regardless
|
||||||
var nullName = gitManager.RegisterRepo(testRepoAbsolutePath, null!);
|
var nullName = gitManager.RegisterRepo(testRepoAbsolutePath, null!);
|
||||||
|
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
|
||||||
Assert.Equal("repo", nullName);
|
Assert.Equal("repo", nullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,11 +73,13 @@ public class AddRegistrationTests
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance;
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
|
|
||||||
var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " ");
|
var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " ");
|
||||||
|
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
|
||||||
Assert.Equal("repo", whitespaceName);
|
Assert.Equal("repo", whitespaceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,7 +88,7 @@ public class AddRegistrationTests
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance;
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
string[] paths = ["test", "nested", "path"];
|
string[] paths = ["test", "nested", "path"];
|
||||||
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
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.Equal(Path.Combine(paths[..1]), secondRegistration);
|
||||||
|
|
||||||
Assert.Throws<Exception>(() => gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])));
|
Assert.Throws<Exception>(() => gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])));
|
||||||
|
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -100,7 +110,7 @@ public class AddRegistrationTests
|
||||||
{
|
{
|
||||||
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
|
|
||||||
var gitManager = GitManager.InternalFreshInstance;
|
var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
|
||||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||||
string[] paths = ["test", "nested", "path"];
|
string[] paths = ["test", "nested", "path"];
|
||||||
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
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 secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
|
||||||
var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator);
|
var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator);
|
||||||
|
|
||||||
|
gitManager.DeleteDatabase();
|
||||||
|
|
||||||
Assert.Equal(Path.Combine(paths), firstRegistration);
|
Assert.Equal(Path.Combine(paths), firstRegistration);
|
||||||
Assert.Equal(Path.Combine(paths[..1]), secondRegistration);
|
Assert.Equal(Path.Combine(paths[..1]), secondRegistration);
|
||||||
Assert.Equal(names.AltSeparator, differentPathSeparatorRegistration);
|
Assert.Equal(names.AltSeparator, differentPathSeparatorRegistration);
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
Attempted to register: test
|
Attempted to register: test
|
||||||
Registration result: test
|
Registration result: test
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
Attempted to register: test\path
|
Attempted to register: test\path
|
||||||
Registration result: test\path
|
Registration result: test\path
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
Attempted to register: other/path
|
Attempted to register: other/path
|
||||||
Registration result: other/path
|
Registration result: other/path
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue