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/build/BuildContext.cs b/build/BuildContext.cs index 29634e9..a4c2588 100644 --- a/build/BuildContext.cs +++ b/build/BuildContext.cs @@ -1,6 +1,7 @@ -using Cake.Common.IO; +using Cake.Common.IO; using Cake.Common.IO.Paths; using Cake.Core; +using Cake.Core.IO; using Cake.Frosting; namespace Build; @@ -10,7 +11,7 @@ public class BuildContext : FrostingContext /// /// Base source directory /// - public ConvertableDirectoryPath BaseSourceLocation { get; set; } + public DirectoryPath BaseSourceLocation { get; set; } /// /// Powershell module project folder @@ -32,19 +33,29 @@ public class BuildContext : FrostingContext /// public ConvertableFilePath CreateModuleManifestScript { get; set; } + /// + /// Suffix to tag the build with, defaults to pre-release. + /// + /// Immediately follows the version number and before the commit hash. + /// + /// public string BuildSuffix { get; set; } + + /// + /// Disable the commit hash from being added + /// public bool DisableCommitHash { get; set; } public BuildContext(ICakeContext context) : base(context) { - BaseSourceLocation = context.Directory("../src"); + BaseSourceLocation = context.Directory("../src").Path.MakeAbsolute(context.Environment); PowershellModuleProjectDirectory = BaseSourceLocation + context.Directory("PowershellModule"); PowershellModuleCsproj = PowershellModuleProjectDirectory + context.File("PowershellModule.csproj"); PowershellModuleOutputDir = context.Directory("../") + context.Directory("output") + context.Directory("PowershellModule"); var buildScriptDirectory = context.Directory("./Scripts"); CreateModuleManifestScript = buildScriptDirectory + context.File("CreateModuleManifest.ps1"); - BuildSuffix = context.Configuration.GetValue(nameof(BuildSuffix)); + BuildSuffix = context.Configuration.GetValue(nameof(BuildSuffix)) ?? "pre-release"; DisableCommitHash = context.Configuration.GetBoolValue(nameof(DisableCommitHash)); } } \ No newline at end of file diff --git a/build/Helpers.cs b/build/Helpers.cs new file mode 100644 index 0000000..a8f2bcb --- /dev/null +++ b/build/Helpers.cs @@ -0,0 +1,48 @@ +using System.Diagnostics; +using System.IO; +using System.Text.RegularExpressions; + +namespace Build; + +public class Helpers +{ + /// + /// Returns a formatted version of the assembly that contains PowerShell cmdlets + /// + /// + /// + public static string GetPowershellModuleVersion(string powershelModuleOutputLocation) + { + // When the project name changes, this dll will also need to be updated + var moduleVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(powershelModuleOutputLocation, "PowershellModule.dll")); + + // It's (almost) impossible to not have a product version tag here. There is a reason why the implementation + // returns a string? but I can't find it and I don't really care too much. If we have null return an empty string + // and append no version to the archive bundle. + if (moduleVersionInfo.ProductVersion == null) + { + return string.Empty; + } + + var versionRegex = new Regex(@"(\d+\.\d+\.\d+)(?:\-?([\w\-]+)\+?(\w+)?)?"); + var match = versionRegex.Match(moduleVersionInfo.ProductVersion); + if (match.Success) + { + // If we have 4 groups, we've got a version number, suffix, and commit hash, so we return the first 2 as is + // and the commit has capped to 8 characters + if (match.Groups.Count == 4) + { + return $"{match.Groups[1]}-{match.Groups[2]}+{match.Groups[3].Value.Substring(0, 8)}"; + } + + if (match.Groups.Count == 3) + { + return $"{match.Groups[1]}-{match.Groups[2]}"; + } + + return $"{match.Groups[1]}"; + } + + return string.Empty; + } +} \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs index 1c348c5..d94f389 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -8,8 +8,6 @@ public static class Program { return new CakeHost() .UseContext() - // Uncomment this if you don't want to set the suffix via the run profile program arguments - //.UseCakeSetting(nameof(BuildContext.BuildSuffix), "") .Run(args); } } \ No newline at end of file diff --git a/build/Scripts/CreateModuleManifest.ps1 b/build/Scripts/CreateModuleManifest.ps1 index 740983d..d7dbd59 100644 --- a/build/Scripts/CreateModuleManifest.ps1 +++ b/build/Scripts/CreateModuleManifest.ps1 @@ -1,4 +1,4 @@ -param ( +param ( [string]$powershellModuleFileLocation, [string]$guid, [string]$author, diff --git a/build/Tasks/BuildTask.cs b/build/Tasks/BuildTask.cs index d11cc79..089ac75 100644 --- a/build/Tasks/BuildTask.cs +++ b/build/Tasks/BuildTask.cs @@ -1,4 +1,4 @@ -using Cake.Common.Tools.DotNet; +using Cake.Common.Tools.DotNet; using Cake.Common.Tools.DotNet.Build; using Cake.Common.Tools.DotNet.MSBuild; using Cake.Core.Diagnostics; diff --git a/build/Tasks/CleanTask.cs b/build/Tasks/CleanTask.cs index 36ab859..7335f97 100644 --- a/build/Tasks/CleanTask.cs +++ b/build/Tasks/CleanTask.cs @@ -1,4 +1,4 @@ -using Cake.Common; +using Cake.Common; using Cake.Common.Tools.DotNet; using Cake.Core.Diagnostics; using Cake.Frosting; diff --git a/build/Tasks/CopyOutputTask.cs b/build/Tasks/CopyOutputTask.cs index f51763a..1bcd241 100644 --- a/build/Tasks/CopyOutputTask.cs +++ b/build/Tasks/CopyOutputTask.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Cake.Core.Diagnostics; @@ -15,8 +15,8 @@ public class CopyOutputTask : FrostingTask public override void Run(BuildContext context) { var powershellModuleName = "PowershellModule"; - // TODO: probably don't create full file locations when I can pass the output dir in and have the script - // make the path + // TODO: [#10] Refactor file paths used in build project to be more explict and easier to understand + // Probably don't create full file locations when I can pass the output dir in and have the script make the path var scriptParams = new { PowershellModuleFileLocation = $"{context.PowershellModuleOutputDir}/{powershellModuleName}.psd1", diff --git a/build/Tasks/CreateBundleArchiveTask.cs b/build/Tasks/CreateBundleArchiveTask.cs index 0abd876..52a2313 100644 --- a/build/Tasks/CreateBundleArchiveTask.cs +++ b/build/Tasks/CreateBundleArchiveTask.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Text.RegularExpressions; @@ -79,7 +80,7 @@ public class CreateBundleArchiveTask : FrostingTask context.Log.Information($"Bundle files copied"); GenerateModuleImportScript(moduleFolderLocation, context); - var moduleVersionForFilename = GetPowershellModuleVersion(powershelModuleOutputLocation); + var moduleVersionForFilename = Helpers.GetPowershellModuleVersion(powershelModuleOutputLocation); CreateBundleZip(bundleRootLocation, moduleFolderLocation, moduleVersionForFilename, context); } @@ -132,38 +133,4 @@ public class CreateBundleArchiveTask : FrostingTask ZipFile.CreateFromDirectory(moduleFolderLocation, bundleZipFileLocaiton, CompressionLevel.Fastest, true); context.Log.Information($"Archive created at '{bundleZipFileLocaiton}'"); } - - private static string GetPowershellModuleVersion(string powershelModuleOutputLocation) - { - var moduleVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(powershelModuleOutputLocation, "PowershellModule.dll")); - - // It's (almost) impossible to not have a product version tag here. There is a reason why the implementation - // returns a string? but I can't find it and I don't really care too much. If we have null return an empty string - // and append no version to the archive bundle. - if (moduleVersionInfo.ProductVersion == null) - { - return string.Empty; - } - - var versionRegex = new Regex(@"(\d+\.\d+\.\d+)(?:\-?([\w\-]+)\+?(\w+)?)?"); - var match = versionRegex.Match(moduleVersionInfo.ProductVersion); - if (match.Success) - { - // If we have 4 groups, we've got a version number, suffix, and commit hash, so we return the first 2 as is - // and the commit has capped to 8 characters - if (match.Groups.Count == 4) - { - return $"{match.Groups[1]}-{match.Groups[2]}+{match.Groups[3].Value.Substring(0, 8)}"; - } - - if (match.Groups.Count == 3) - { - return $"{match.Groups[1]}-{match.Groups[2]}"; - } - - return $"{match.Groups[1]}"; - } - - return string.Empty; - } } \ No newline at end of file diff --git a/build/Tasks/DefaultTask.cs b/build/Tasks/DefaultTask.cs index 7f4bf67..217c75c 100644 --- a/build/Tasks/DefaultTask.cs +++ b/build/Tasks/DefaultTask.cs @@ -1,4 +1,4 @@ -using Cake.Core; +using Cake.Core; using Cake.Core.Diagnostics; using Cake.Frosting; @@ -7,6 +7,7 @@ namespace Build.Tasks; // Consider this the "entry" point for builds, task order is defined by a chain of IsDependentOn [TaskName("Default")] [IsDependentOn(typeof(BuildTask))] +[IsDependentOn(typeof(TagCommitTask))] [IsDependentOn(typeof(CopyOutputTask))] [IsDependentOn(typeof(CreateBundleArchiveTask))] public class DefaultTask : FrostingTask diff --git a/build/Tasks/TagCommitTask.cs b/build/Tasks/TagCommitTask.cs new file mode 100644 index 0000000..35b53f8 --- /dev/null +++ b/build/Tasks/TagCommitTask.cs @@ -0,0 +1,54 @@ +using System; +using System.Diagnostics; +using Cake.Core.Diagnostics; +using Cake.Frosting; + +namespace Build.Tasks; + +[TaskName("TagCurrentCommitWithVersion")] +[IsDependentOn(typeof(BuildTask))] +public class TagCommitTask : FrostingTask +{ + public override void Run(BuildContext context) + { + // This task only really exists to create pre-release builds for pull requests. + // It'll tag the current commit with the same version that'll be used for the bundle archive filename. + // TODO: update build.ps1 in the solution root so it doesn't do this tagging task + TagCommit(context); + base.Run(context); + } + + private static void TagCommit(BuildContext context) + { + var moduleVersionForFilename = Helpers.GetPowershellModuleVersion(context.PowershellModuleOutputDir.Path.MakeAbsolute(context.Environment).FullPath); + + var ps = new ProcessStartInfo("git", + ["-C", context.BaseSourceLocation.FullPath, "tag", moduleVersionForFilename]) + { + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + + // If the user doesn't have git on their path, this will throw an exception that I don't have to do anything + // special with, it'll be unhandled and powershell will handle it + var gitProcess = Process.Start(ps); + + // This probably shouldn't be possible? + if (gitProcess is null) + { + throw new Exception("git failed to start") + { + Source = "git-process", + }; + } + + gitProcess.WaitForExit(); + + if (!gitProcess.StandardError.EndOfStream) + { + throw new Exception($"Unable to tag: {gitProcess.StandardError.ReadToEnd().Trim()}. Either remove the existing tag, or commit your changes before running a build"); + } + + context.Log.Information($"Tagged commit with {moduleVersionForFilename}"); + } +} \ No newline at end of file diff --git a/docs/GitRepositoryRegistration.md b/docs/GitRepositoryRegistration.md index 0f8a7c4..935dd8e 100644 --- a/docs/GitRepositoryRegistration.md +++ b/docs/GitRepositoryRegistration.md @@ -1,4 +1,4 @@ -# Git Repo Registration +# Git Repo Registration - all commands support `-debug` - at its simplest level these commands allow you to register a git repo against a simple name, and provide the ability to quickly pushd to a location 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..f4e8afe 100644 --- a/src/ModuleCore/Database/DatabaseManager.cs +++ b/src/ModuleCore/Database/DatabaseManager.cs @@ -1,4 +1,4 @@ -using SQLite; +using SQLite; namespace ModuleCore.Database; @@ -26,12 +26,22 @@ public class DatabaseManager } } + /// + /// Runs the given action within a new database connection + /// + /// public void InConnection(Action dbAction) { using var conn = new SQLiteConnection(_databaseLocation.FullName); dbAction(conn); } + /// + /// Runs the given func in a new database connection, returning the result + /// + /// + /// + /// public T InConnection(Func dbAction) { using var conn = new SQLiteConnection(_databaseLocation.FullName); @@ -51,6 +61,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/GitRepoRegistrationManager.cs similarity index 86% rename from src/ModuleCore/Git/GitManager.cs rename to src/ModuleCore/Git/GitRepoRegistrationManager.cs index 1312b03..98cab87 100644 --- a/src/ModuleCore/Git/GitManager.cs +++ b/src/ModuleCore/Git/GitRepoRegistrationManager.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Diagnostics; using ModuleCore.Database; using ModuleCore.Git.Models; @@ -6,28 +6,44 @@ using SQLite; namespace ModuleCore.Git; -// TODO: better name for this -public class GitManager +/// +/// Manages git repo registration, including creating any registration persistence via a backing +/// +public class GitRepoRegistrationManager { - private static readonly Lazy GitManagerInstance = new(() => new GitManager()); + private static readonly Lazy GitManagerInstance = new(() => new GitRepoRegistrationManager()); private static Action? _debugWriterDelegate; private readonly DatabaseManager _db; private readonly ConcurrentDictionary _registrations; - private GitManager() + private GitRepoRegistrationManager(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(); } - public static GitManager Instance => GitManagerInstance.Value; + /// + /// Returns the current instance. If no instance has been created, returns a new instance + /// and then the same instance every call after. + /// + public static GitRepoRegistrationManager Instance => GitManagerInstance.Value; /// /// Always returns a new clean instance of GitManager /// - internal static GitManager InternalFreshInstance => new(); + internal static GitRepoRegistrationManager 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. @@ -118,6 +134,11 @@ public class GitManager }); } + /// + /// Unregisters a git repo registration by name. If no registration exists an exception will be thrown. + /// + /// + /// public void UnregisterRepo(string registrationName) { _db.InConnection(conn => @@ -185,7 +206,13 @@ public class GitManager .ToList(); } - public string GetRepo(string? registeredName) + /// + /// Returns the file location for a git repo registration by name. + /// + /// + /// + /// + public string GetDirectoryForRegisteredRepo(string? registeredName) { if (string.IsNullOrEmpty(registeredName)) { @@ -312,7 +339,7 @@ public class GitManager /// public string CurrentBranch => GetCurrentBranch(); - // TODO: not fully decided on if I want this feature or not, but keeping it in for now + // TODO: [#13] Create GitManager to centralise calls to git process private string GetCurrentBranch() { var now = DateTime.Now; @@ -363,20 +390,4 @@ public class GitManager return _currentBranch.Trim(); } } -} - -/// -/// The directory details of the directory returned from git rev-parse --show-toplevel -/// -public class ParsedGitFolderDetails -{ - /// - /// The full path to the top level folder containing a git repository - /// - public string Directory { get; init; } = null!; - - /// - /// The last folder name of the directory - /// - public string Folder { get; init; } = null!; } \ No newline at end of file diff --git a/src/ModuleCore/Git/Models/GitRegistration.cs b/src/ModuleCore/Git/Models/GitRegistration.cs index 11eea11..8c38d03 100644 --- a/src/ModuleCore/Git/Models/GitRegistration.cs +++ b/src/ModuleCore/Git/Models/GitRegistration.cs @@ -1,8 +1,21 @@ -namespace ModuleCore.Git.Models; +namespace ModuleCore.Git.Models; +/// +/// Details for a registered git repo +/// public class GitRegistration { + /// + /// Display name for the registration. Can either be the name of the repo retrieved from git, or a user supplied + /// alias + /// public required string Name { get; set; } + /// + /// Location on disk for the top level of the registered git repo. Not guaranteed to exist on disk + /// public required string Location { get; set; } + /// + /// Current branch for the git repo + /// public required string CurrentBranch { get; set; } } \ No newline at end of file diff --git a/src/ModuleCore/Git/Models/ParsedGitFolderDetails.cs b/src/ModuleCore/Git/Models/ParsedGitFolderDetails.cs new file mode 100644 index 0000000..a785be0 --- /dev/null +++ b/src/ModuleCore/Git/Models/ParsedGitFolderDetails.cs @@ -0,0 +1,17 @@ +namespace ModuleCore.Git.Models; + +/// +/// The directory details of the directory returned from git rev-parse --show-toplevel +/// +public class ParsedGitFolderDetails +{ + /// + /// The full path to the top level folder containing a git repository + /// + public string Directory { get; init; } = null!; + + /// + /// The last folder name of the directory + /// + public string Folder { get; init; } = null!; +} \ No newline at end of file diff --git a/src/ModuleCore/ModuleCore.csproj b/src/ModuleCore/ModuleCore.csproj index 81bd88b..dd723a8 100644 --- a/src/ModuleCore/ModuleCore.csproj +++ b/src/ModuleCore/ModuleCore.csproj @@ -1,4 +1,4 @@ - + net10.0 @@ -14,7 +14,7 @@ - + diff --git a/src/PowershellModule/Calendar/GetCalendarCommand.cs b/src/PowershellModule/Calendar/GetCalendarCommand.cs index f70d6e0..ff16bc3 100644 --- a/src/PowershellModule/Calendar/GetCalendarCommand.cs +++ b/src/PowershellModule/Calendar/GetCalendarCommand.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.Management.Automation; using ModuleCore.Calendar; diff --git a/src/PowershellModule/Directory.Build.props b/src/PowershellModule/Directory.Build.props index e0bdda9..dd32fa3 100644 --- a/src/PowershellModule/Directory.Build.props +++ b/src/PowershellModule/Directory.Build.props @@ -1,4 +1,4 @@ - + 0.0.1 dev diff --git a/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs index d1885ec..506aee2 100644 --- a/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs +++ b/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs @@ -1,4 +1,4 @@ -using System.Management.Automation; +using System.Management.Automation; using ModuleCore.Git; using ModuleCore.Git.Models; @@ -13,7 +13,7 @@ public class GetGitRepoRegistrationCommand : PSCmdlet { protected override void BeginProcessing() { - var repos = GitManager.Instance.ListRepos(); + var repos = GitRepoRegistrationManager.Instance.ListRepos(); WriteObject(repos); diff --git a/src/PowershellModule/Git/Commands/GitCommands.cs b/src/PowershellModule/Git/Commands/GitCommands.cs index 8dc36f6..7fe1856 100644 --- a/src/PowershellModule/Git/Commands/GitCommands.cs +++ b/src/PowershellModule/Git/Commands/GitCommands.cs @@ -1,4 +1,4 @@ -namespace PowershellModule.Git.Commands; +namespace PowershellModule.Git.Commands; public class GitCommands { diff --git a/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs index ec460eb..9e0729f 100644 --- a/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs +++ b/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Management.Automation; using ModuleCore.Git; @@ -17,19 +17,19 @@ public sealed class NewGitRepoRegistrationCommand : PSCmdlet { try { - GitManager.SetDebugWriter(WriteDebug); + GitRepoRegistrationManager.SetDebugWriter(WriteDebug); // Test that we're in a git repo first. If we aren't (or git isn't available), this method will throw // so we don't need to handle for null (yet). - var repoFolder = GitManager.IsGitRepo(SessionState.Path.CurrentLocation.Path); + var repoFolder = GitRepoRegistrationManager.IsGitRepo(SessionState.Path.CurrentLocation.Path); if (string.IsNullOrWhiteSpace(Name)) { WriteDebug("No name given for registration, defaulting to git folder root."); } - GitManager.Instance.RegisterRepo(repoFolder.Directory, Name ?? repoFolder.Folder); - GitManager.ClearDebugWriter(); + GitRepoRegistrationManager.Instance.RegisterRepo(repoFolder.Directory, Name ?? repoFolder.Folder); + GitRepoRegistrationManager.ClearDebugWriter(); base.BeginProcessing(); } diff --git a/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs index 36b192e..a79060e 100644 --- a/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs +++ b/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Management.Automation; using ModuleCore.Git; @@ -17,21 +17,21 @@ public class RemoveGitRepoRegistrationCommand : PSCmdlet { try { - GitManager.SetDebugWriter(WriteDebug); + GitRepoRegistrationManager.SetDebugWriter(WriteDebug); // If we aren't given a value for the Name argument, default behaviour is to attempt to remove a registration // by the current git repo folder name for the current location. // If we have a name, don't bother testing for a git repo, just attempt to remove the registration by name // regardless of where we're being called from var registrationNameToRemove = string.IsNullOrEmpty(Name) - ? GitManager.IsGitRepo(SessionState.Path.CurrentLocation.Path).Folder + ? GitRepoRegistrationManager.IsGitRepo(SessionState.Path.CurrentLocation.Path).Folder : Name; - GitManager.Instance.UnregisterRepo(registrationNameToRemove); + GitRepoRegistrationManager.Instance.UnregisterRepo(registrationNameToRemove); // Removing a registration works similar to registering a new one - we either remove by exact name, or by // the folder if no name is given (so a user can remove a registration from a git repo they're currently in) - GitManager.ClearDebugWriter(); + GitRepoRegistrationManager.ClearDebugWriter(); base.BeginProcessing(); } diff --git a/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs index 61b7561..e4eb647 100644 --- a/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs +++ b/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs @@ -1,4 +1,4 @@ -using System.Management.Automation; +using System.Management.Automation; using ModuleCore.Git; namespace PowershellModule.Git.Commands; @@ -21,7 +21,7 @@ public class ShowGitRepoRegistrationCommand : PSCmdlet protected override void BeginProcessing() { - var location = GitManager.Instance.GetRepo(Name); + var location = GitRepoRegistrationManager.Instance.GetDirectoryForRegisteredRepo(Name); // By default instead of doing the same as cd, we instead do pushd so a user can popd straight back to where // they came from. diff --git a/src/PowershellModule/Git/GitProvider.cs b/src/PowershellModule/Git/GitProvider.cs index 7d643ee..b9ece49 100644 --- a/src/PowershellModule/Git/GitProvider.cs +++ b/src/PowershellModule/Git/GitProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Management.Automation; using System.Management.Automation.Provider; diff --git a/src/PowershellModule/Git/GitPsDriveInfo.cs b/src/PowershellModule/Git/GitPsDriveInfo.cs index 7b0d691..b1c761d 100644 --- a/src/PowershellModule/Git/GitPsDriveInfo.cs +++ b/src/PowershellModule/Git/GitPsDriveInfo.cs @@ -1,4 +1,4 @@ -using System.Management.Automation; +using System.Management.Automation; namespace PowershellModule.Git; diff --git a/src/PowershellModule/PostBuild.ps1 b/src/PowershellModule/PostBuild.ps1 index cb7b8de..518b78a 100644 --- a/src/PowershellModule/PostBuild.ps1 +++ b/src/PowershellModule/PostBuild.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Removes all non-core files from build output #> diff --git a/src/PowershellModule/PowershellModule.csproj b/src/PowershellModule/PowershellModule.csproj index 56f10c3..7cb5192 100644 --- a/src/PowershellModule/PowershellModule.csproj +++ b/src/PowershellModule/PowershellModule.csproj @@ -1,25 +1,25 @@ - - net10.0 - PowershellModule - latestmajor - enable - true - + + net10.0 + PowershellModule + latestmajor + enable + true + - - - All - - - + + + All + + + - - - + + + - - - + + + diff --git a/tests/ModuleTests/Calendar/BasicRenderTest.cs b/tests/ModuleTests/Calendar/BasicRenderTest.cs index 3bc791f..b08f0bd 100644 --- a/tests/ModuleTests/Calendar/BasicRenderTest.cs +++ b/tests/ModuleTests/Calendar/BasicRenderTest.cs @@ -1,4 +1,4 @@ -using ModuleCore.Calendar; +using ModuleCore.Calendar; using ModuleTests.Calendar.TestData; using System.Globalization; diff --git a/tests/ModuleTests/Calendar/MarkedDayRenderTests.cs b/tests/ModuleTests/Calendar/MarkedDayRenderTests.cs index 24af2ce..a169518 100644 --- a/tests/ModuleTests/Calendar/MarkedDayRenderTests.cs +++ b/tests/ModuleTests/Calendar/MarkedDayRenderTests.cs @@ -1,4 +1,4 @@ -using System.Text; +using System.Text; using ModuleCore.Calendar; namespace ModuleTests.Calendar; 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 92% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-06-01.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-06-01.verified.txt index de75dd0..39f169d 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-06-01.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-06-01.verified.txt @@ -1,4 +1,4 @@ -┌─────────────────────────────────────────┐ +┌─────────────────────────────────────────┐ │ June 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ 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 92% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-07-01.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-07-01.verified.txt index a74744c..0f44012 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-07-01.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-07-01.verified.txt @@ -1,4 +1,4 @@ -┌─────────────────────────────────────────┐ +┌─────────────────────────────────────────┐ │ July 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ 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 92% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-08-01.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-08-01.verified.txt index 9598b49..f3c1199 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/2026-08-01.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/2026-08-01.verified.txt @@ -1,4 +1,4 @@ -┌─────────────────────────────────────────┐ +┌─────────────────────────────────────────┐ │ August 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/cs-CZ.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/cs-CZ.verified.txt similarity index 81% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/cs-CZ.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/cs-CZ.verified.txt index 797c58a..a1a264b 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/cs-CZ.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/cs-CZ.verified.txt @@ -1,4 +1,4 @@ -┌──────────────────────────────────┐ +┌──────────────────────────────────┐ │ srpen 2026 │ ├────┬────┬────┬────┬────┬────┬────┤ │ po │ út │ st │ čt │ pá │ so │ ne │ diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/da-DK.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/da-DK.verified.txt similarity index 92% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/da-DK.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/da-DK.verified.txt index 58618a1..d69d3f7 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/da-DK.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/da-DK.verified.txt @@ -1,4 +1,4 @@ -┌─────────────────────────────────────────┐ +┌─────────────────────────────────────────┐ │ august 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ │ man │ tir │ ons │ tor │ fre │ lør │ søn │ diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/en-AU.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/en-AU.verified.txt similarity index 92% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/en-AU.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/en-AU.verified.txt index 9598b49..f3c1199 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/en-AU.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/en-AU.verified.txt @@ -1,4 +1,4 @@ -┌─────────────────────────────────────────┐ +┌─────────────────────────────────────────┐ │ August 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/es-PR.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/es-PR.verified.txt similarity index 90% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/es-PR.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/es-PR.verified.txt index 9395157..4a4de20 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/es-PR.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/es-PR.verified.txt @@ -1,4 +1,4 @@ -┌────────────────────────────────────────────────┐ +┌────────────────────────────────────────────────┐ │ agosto 2026 │ ├──────┬──────┬──────┬──────┬──────┬──────┬──────┤ │ lun. │ mar. │ mié. │ jue. │ vie. │ sáb. │ dom. │ diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/fr-LU.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/fr-LU.verified.txt similarity index 90% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/fr-LU.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/fr-LU.verified.txt index 101ef77..9a7e138 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/fr-LU.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/fr-LU.verified.txt @@ -1,4 +1,4 @@ -┌────────────────────────────────────────────────┐ +┌────────────────────────────────────────────────┐ │ août 2026 │ ├──────┬──────┬──────┬──────┬──────┬──────┬──────┤ │ lun. │ mar. │ mer. │ jeu. │ ven. │ sam. │ dim. │ diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/nl-NL.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/nl-NL.verified.txt similarity index 81% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/nl-NL.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/nl-NL.verified.txt index 1aac604..2a9615a 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/nl-NL.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/nl-NL.verified.txt @@ -1,4 +1,4 @@ -┌──────────────────────────────────┐ +┌──────────────────────────────────┐ │ augustus 2026 │ ├────┬────┬────┬────┬────┬────┬────┤ │ ma │ di │ wo │ do │ vr │ za │ zo │ diff --git a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/te-IN.verified.txt b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/te-IN.verified.txt similarity index 88% rename from tests/ModuleTests/Calendar/snapshots/BasicRenderTest/te-IN.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/te-IN.verified.txt index 5568a20..bee6c08 100644 --- a/tests/ModuleTests/Calendar/snapshots/BasicRenderTest/te-IN.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/BasicRenderTest/te-IN.verified.txt @@ -1,4 +1,4 @@ -┌───────────────────────────────────────────────────────┐ +┌───────────────────────────────────────────────────────┐ │ ఆగస్టు 2026 │ ├───────┬───────┬───────┬───────┬───────┬───────┬───────┤ │ సోమ │ మంగళ │ బుధ │ గురు │ శుక్ర │ శని │ ఆది │ diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt similarity index 92% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt index 4181cc1..a134a32 100644 --- a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DefaultMarkedDayRender.verified.txt @@ -1,4 +1,4 @@ -┌─────────────────────────────────────────┐ +┌─────────────────────────────────────────┐ │ August 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt similarity index 91% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt index cc27f4f..3fb6ad7 100644 --- a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/DoubleWideMarkedDayRender.verified.txt @@ -1,4 +1,4 @@ -Double-wide characters will display incorrectly but still tested until rendering can be improved +Double-wide characters will display incorrectly but still tested until rendering can be improved ┌─────────────────────────────────────────┐ │ August 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt similarity index 91% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt index a02a725..fc7c092 100644 --- a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/EmojiMarkedDayRender.verified.txt @@ -1,4 +1,4 @@ -Emojis will display incorrectly in text but output correctly in terminals with UTF-8 encoding. +Emojis will display incorrectly in text but output correctly in terminals with UTF-8 encoding. ┌─────────────────────────────────────────┐ │ August 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt similarity index 90% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt index a8ebbf6..14e0523 100644 --- a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/LongMarkedDayRender.verified.txt @@ -1,4 +1,4 @@ -┌──────────────────────────────────────────────────────────────┐ +┌──────────────────────────────────────────────────────────────┐ │ August 2026 │ ├────────┬────────┬────────┬────────┬────────┬────────┬────────┤ │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ diff --git a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt similarity index 92% rename from tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt index f546aac..007bfcb 100644 --- a/tests/ModuleTests/Calendar/snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/MarkedDayRenderTests/SimpleMarkedDayRender.verified.txt @@ -1,4 +1,4 @@ -┌─────────────────────────────────────────┐ +┌─────────────────────────────────────────┐ │ August 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ diff --git a/tests/ModuleTests/Calendar/snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt b/tests/ModuleTests/Calendar/Snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt similarity index 99% rename from tests/ModuleTests/Calendar/snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt rename to tests/ModuleTests/Calendar/Snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt index 8393453..aaa4fa5 100644 --- a/tests/ModuleTests/Calendar/snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt +++ b/tests/ModuleTests/Calendar/Snapshots/StartDayOfWeekTests/StartOfDayRender.verified.txt @@ -1,4 +1,4 @@ -Start Day: Sunday +Start Day: Sunday ┌─────────────────────────────────────────┐ │ August 2026 │ ├─────┬─────┬─────┬─────┬─────┬─────┬─────┤ diff --git a/tests/ModuleTests/Calendar/StartDayOfWeekTests.cs b/tests/ModuleTests/Calendar/StartDayOfWeekTests.cs index c6680c7..fb4c52c 100644 --- a/tests/ModuleTests/Calendar/StartDayOfWeekTests.cs +++ b/tests/ModuleTests/Calendar/StartDayOfWeekTests.cs @@ -1,4 +1,4 @@ -using System.Text; +using System.Text; using ModuleCore.Calendar; namespace ModuleTests.Calendar; diff --git a/tests/ModuleTests/Calendar/TestData/CalendarTestDates.cs b/tests/ModuleTests/Calendar/TestData/CalendarTestDates.cs index 189b4a4..3c5b048 100644 --- a/tests/ModuleTests/Calendar/TestData/CalendarTestDates.cs +++ b/tests/ModuleTests/Calendar/TestData/CalendarTestDates.cs @@ -1,4 +1,4 @@ -namespace ModuleTests.Calendar.TestData; +namespace ModuleTests.Calendar.TestData; public class CalendarTestDates : TestDataEnumerator { diff --git a/tests/ModuleTests/Calendar/TestData/CultureCodeTestData.cs b/tests/ModuleTests/Calendar/TestData/CultureCodeTestData.cs index 9bdf1f0..f72e6c3 100644 --- a/tests/ModuleTests/Calendar/TestData/CultureCodeTestData.cs +++ b/tests/ModuleTests/Calendar/TestData/CultureCodeTestData.cs @@ -1,4 +1,4 @@ -namespace ModuleTests.Calendar.TestData; +namespace ModuleTests.Calendar.TestData; public class CultureCodeTestData : TestDataEnumerator { diff --git a/tests/ModuleTests/Git/AddRegistrationTests.cs b/tests/ModuleTests/Git/AddRegistrationTests.cs index 511833a..c862773 100644 --- a/tests/ModuleTests/Git/AddRegistrationTests.cs +++ b/tests/ModuleTests/Git/AddRegistrationTests.cs @@ -1,10 +1,10 @@ -using System.Text; -using ModuleCore.Calendar; +using System.Text; using ModuleCore.Git; using ModuleTests.Git.TestData; namespace ModuleTests.Git; +// TODO: [#12] GitRepoRegistration tests should reset database at start of each test public class AddRegistrationTests { private static readonly VerifySettings Settings; @@ -23,43 +23,60 @@ public class AddRegistrationTests public Task BasicRepoRegistration((int testId, string path) testData) { Settings.UseFileName($"{nameof(BasicRepoRegistration)}_{testData.testId}"); + var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(BasicRepoRegistration)); - var gitManager = GitManager.InternalFreshInstance; + try + { + 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}"); - 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}"); - - return Verify(sb, Settings); + return Verify(sb, Settings); + } + finally + { + gitManager.DeleteDatabase(); + } } [Fact] public void RepoRegistrationWithEmptyName() { Settings.UseFileName(nameof(RepoRegistrationWithEmptyName)); - - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithEmptyName)); var testRepoAbsolutePath = "Test:/some/test/repo"; - var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, ""); + try + { + var emptyName = gitManager.RegisterRepo(testRepoAbsolutePath, ""); - Assert.Equal("repo", emptyName); + Assert.Equal("repo", emptyName); + } + finally + { + gitManager.DeleteDatabase(); + } } [Fact] public void RepoRegistrationWithNullName() { Settings.UseFileName(nameof(RepoRegistrationWithNullName)); - - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithNullName)); var testRepoAbsolutePath = "Test:/some/test/repo"; + try + { + // 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!); - // 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!); - - Assert.Equal("repo", nullName); + Assert.Equal("repo", nullName); + } + finally + { + gitManager.DeleteDatabase(); + } } [Fact] @@ -67,51 +84,67 @@ public class AddRegistrationTests { Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName)); - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName)); var testRepoAbsolutePath = "Test:/some/test/repo"; + try + { + var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " "); - var whitespaceName = gitManager.RegisterRepo(testRepoAbsolutePath, " "); - - Assert.Equal("repo", whitespaceName); + Assert.Equal("repo", whitespaceName); + } + finally + { + gitManager.DeleteDatabase(); + } } [Fact] public void DuplicateRepoRegistrationShouldFail() { Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName)); - - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitRepoRegistrationManager.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)); - var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator); - // TODO: make nested registrations fail in both directions and test - var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])); + try + { + var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator); + var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])); - Assert.Equal(Path.Combine(paths), firstRegistration); - Assert.Equal(Path.Combine(paths[..1]), secondRegistration); + Assert.Equal(Path.Combine(paths), firstRegistration); + Assert.Equal(Path.Combine(paths[..1]), secondRegistration); - Assert.Throws(() => gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]))); + Assert.Throws(() => gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]))); + } + finally + { + gitManager.DeleteDatabase(); + } } [Fact] public void DuplicateRepoRegistrationDifferentSlashShouldNotFail() { Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName)); - - var gitManager = GitManager.InternalFreshInstance; + var gitManager = GitRepoRegistrationManager.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)); - var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator); - // TODO: make nested registrations fail in both directions and test - var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])); - var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator); + try + { + var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator); + var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1])); + var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator); - Assert.Equal(Path.Combine(paths), firstRegistration); - Assert.Equal(Path.Combine(paths[..1]), secondRegistration); - Assert.Equal(names.AltSeparator, differentPathSeparatorRegistration); + Assert.Equal(Path.Combine(paths), firstRegistration); + Assert.Equal(Path.Combine(paths[..1]), secondRegistration); + Assert.Equal(names.AltSeparator, differentPathSeparatorRegistration); + } + finally + { + gitManager.DeleteDatabase(); + } } } \ No newline at end of file diff --git a/tests/ModuleTests/Git/TestData/AddRegistrationTestData.cs b/tests/ModuleTests/Git/TestData/AddRegistrationTestData.cs index 3668ba2..2d44e39 100644 --- a/tests/ModuleTests/Git/TestData/AddRegistrationTestData.cs +++ b/tests/ModuleTests/Git/TestData/AddRegistrationTestData.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; namespace ModuleTests.Git.TestData; diff --git a/tests/ModuleTests/ModuleTests.csproj b/tests/ModuleTests/ModuleTests.csproj index 7343cfd..4b97606 100644 --- a/tests/ModuleTests/ModuleTests.csproj +++ b/tests/ModuleTests/ModuleTests.csproj @@ -1,4 +1,4 @@ - + net10.0 diff --git a/tests/ModuleTests/TestConstants.cs b/tests/ModuleTests/TestConstants.cs index e32b3cd..812da26 100644 --- a/tests/ModuleTests/TestConstants.cs +++ b/tests/ModuleTests/TestConstants.cs @@ -1,4 +1,4 @@ -namespace ModuleTests; +namespace ModuleTests; public class TestConstants { diff --git a/tests/ModuleTests/TestDataEnumerator.cs b/tests/ModuleTests/TestDataEnumerator.cs index 92937f5..f756af4 100644 --- a/tests/ModuleTests/TestDataEnumerator.cs +++ b/tests/ModuleTests/TestDataEnumerator.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; namespace ModuleTests;