diff --git a/src/RepoM.Api/Git/RepositoryViewModel.cs b/src/RepoM.Api/Git/RepositoryViewModel.cs index f9dba708..abb0e9ee 100644 --- a/src/RepoM.Api/Git/RepositoryViewModel.cs +++ b/src/RepoM.Api/Git/RepositoryViewModel.cs @@ -46,9 +46,8 @@ private void EnsureStatusCache() return; } - var compressor = new StatusCompressor(StatusCharacterMap.Instance); - _cachedRepositoryStatus = compressor.Compress(Repository); - _cachedRepositoryStatusWithBranch = compressor.CompressWithBranch(Repository); + _cachedRepositoryStatus = StatusCompressor.Compress(Repository); + _cachedRepositoryStatusWithBranch = StatusCompressor.CompressWithBranch(Repository); _cachedRepositoryStatusCode = repositoryStatusCode; } diff --git a/src/RepoM.Api/Git/StatusCharacterMap.cs b/src/RepoM.Api/Git/StatusCharacterMap.cs index 70abb5c7..ba352f30 100644 --- a/src/RepoM.Api/Git/StatusCharacterMap.cs +++ b/src/RepoM.Api/Git/StatusCharacterMap.cs @@ -1,22 +1,16 @@ namespace RepoM.Api.Git; -public class StatusCharacterMap +public static class StatusCharacterMap { - private StatusCharacterMap() - { - } + public const char IDENTICAL_SIGN = '\u2261'; - public static StatusCharacterMap Instance { get; } = new StatusCharacterMap(); + public const char NO_UPSTREAM_SIGN = '\u2302'; - public string IdenticalSign => "\u2261"; + public const char ARROW_UP_SIGN = '\u2191'; - public string NoUpstreamSign => "\u2302"; + public const char ARROW_DOWN_SIGN = '\u2193'; - public string ArrowUpSign => "\u2191"; + public const char ELLIPSES_SIGN = '\u2026'; - public string ArrowDownSign => "\u2193"; - - public string EllipsesSign => "\u2026"; - - public string StashSign => "\u205E"; + public const char STASH_SIGN = '\u205E'; } \ No newline at end of file diff --git a/src/RepoM.Api/Git/StatusCompressor.cs b/src/RepoM.Api/Git/StatusCompressor.cs index 6ec1d3b8..7667788c 100644 --- a/src/RepoM.Api/Git/StatusCompressor.cs +++ b/src/RepoM.Api/Git/StatusCompressor.cs @@ -1,20 +1,12 @@ namespace RepoM.Api.Git; -using System; using System.Text; -public class StatusCompressor +public static class StatusCompressor { private const int COMMIT_SHA_DISPLAY_CHARS = 7; - private readonly StatusCharacterMap _statusCharacterMap; - - public StatusCompressor(StatusCharacterMap statusCharacterMap) - { - _statusCharacterMap = statusCharacterMap ?? throw new ArgumentNullException(nameof(statusCharacterMap)); - } - - public string Compress(Repository repository) + public static string Compress(Repository repository) { if (string.IsNullOrEmpty(repository.CurrentBranch)) { @@ -35,13 +27,13 @@ public string Compress(Repository repository) { if (isOnCommitLevel) { - builder.Append(_statusCharacterMap.IdenticalSign); + builder.Append(StatusCharacterMap.IDENTICAL_SIGN); } else { if (isBehind) { - builder.Append($"{_statusCharacterMap.ArrowDownSign}{repository.BehindBy}"); + builder.Append($"{StatusCharacterMap.ARROW_DOWN_SIGN}{repository.BehindBy}"); } if (isAhead) @@ -51,13 +43,13 @@ public string Compress(Repository repository) builder.Append(' '); } - builder.Append($"{_statusCharacterMap.ArrowUpSign}{repository.AheadBy}"); + builder.Append($"{StatusCharacterMap.ARROW_UP_SIGN}{repository.AheadBy}"); } } } else { - builder.Append(_statusCharacterMap.NoUpstreamSign); + builder.Append(StatusCharacterMap.NO_UPSTREAM_SIGN); } if (printAddStagedRemoved) @@ -92,13 +84,14 @@ public string Compress(Repository repository) builder.Append(' '); } - builder.Append(_statusCharacterMap.StashSign + repository.StashCount); + builder.Append(StatusCharacterMap.STASH_SIGN); + builder.Append(repository.StashCount); } return builder.ToString(); } - public string CompressWithBranch(Repository repository) + public static string CompressWithBranch(Repository repository) { var branch = repository.CurrentBranch; @@ -112,7 +105,7 @@ public string CompressWithBranch(Repository repository) // put commit shas in parenthesis (), shorten them and show ellipses afterwards if (repository.CurrentBranchIsDetached && branch.Length > COMMIT_SHA_DISPLAY_CHARS) { - branch = $"({branch[..COMMIT_SHA_DISPLAY_CHARS]}{_statusCharacterMap.EllipsesSign})"; + branch = $"({branch[..COMMIT_SHA_DISPLAY_CHARS]}{StatusCharacterMap.ELLIPSES_SIGN})"; } } diff --git a/src/RepoM.App/Bootstrapper.cs b/src/RepoM.App/Bootstrapper.cs index caac53dd..1590cd82 100644 --- a/src/RepoM.App/Bootstrapper.cs +++ b/src/RepoM.App/Bootstrapper.cs @@ -58,8 +58,6 @@ public static void RegisterServices(IFileSystem fileSystem) { Container.RegisterInstance(MemoryCache.Default); Container.Register(Lifestyle.Singleton); - Container.RegisterInstance(StatusCharacterMap.Instance); - Container.Register(Lifestyle.Singleton); Container.Register(Lifestyle.Singleton); Container.Register(Lifestyle.Singleton); Container.Register(Lifestyle.Singleton); diff --git a/src/RepoM.App/MainWindow.xaml.cs b/src/RepoM.App/MainWindow.xaml.cs index 4d63b62b..b05798f6 100644 --- a/src/RepoM.App/MainWindow.xaml.cs +++ b/src/RepoM.App/MainWindow.xaml.cs @@ -45,7 +45,6 @@ public partial class MainWindow private readonly IAppDataPathProvider _appDataPathProvider; public MainWindow( - StatusCharacterMap statusCharacterMap, IRepositoryInformationAggregator aggregator, IRepositoryMonitor repositoryMonitor, IRepositoryActionProvider repositoryActionProvider, @@ -101,7 +100,7 @@ public MainWindow( AssemblyName? appName = Assembly.GetEntryAssembly()?.GetName(); txtHelpCaption.Text = appName?.Name + " " + appName?.Version?.ToString(2); - txtHelp.Text = GetHelp(statusCharacterMap); + txtHelp.Text = GetHelp(); PlaceFormByTaskBarLocation(); } @@ -638,17 +637,17 @@ private void TxtFilter_Finish(object sender, EventArgs e) item?.Focus(); } - private string GetHelp(StatusCharacterMap statusCharacterMap) + private string GetHelp() { return _translationService.Translate( "Help Detail", - statusCharacterMap.IdenticalSign, - statusCharacterMap.StashSign, - statusCharacterMap.IdenticalSign, - statusCharacterMap.ArrowUpSign, - statusCharacterMap.ArrowDownSign, - statusCharacterMap.NoUpstreamSign, - statusCharacterMap.StashSign + StatusCharacterMap.IDENTICAL_SIGN, + StatusCharacterMap.STASH_SIGN, + StatusCharacterMap.IDENTICAL_SIGN, + StatusCharacterMap.ARROW_UP_SIGN, + StatusCharacterMap.ARROW_DOWN_SIGN, + StatusCharacterMap.NO_UPSTREAM_SIGN, + StatusCharacterMap.STASH_SIGN ); } diff --git a/tests/RepoM.Api.Tests/Git/StatusCompressorTests.cs b/tests/RepoM.Api.Tests/Git/StatusCompressorTests.cs index 40d8531e..02b0e9a7 100644 --- a/tests/RepoM.Api.Tests/Git/StatusCompressorTests.cs +++ b/tests/RepoM.Api.Tests/Git/StatusCompressorTests.cs @@ -1,59 +1,37 @@ namespace RepoM.Api.Tests.Git; -using System; using FluentAssertions; using RepoM.Api.Git; using Xunit; public class StatusCompressorTests { - private readonly RepositoryBuilder _builder; - private readonly StatusCharacterMap _characterMap; - private readonly StatusCompressor _compressor; + private readonly RepositoryBuilder _builder = new(); - public StatusCompressorTests() + private static string Compress(Repository repo) { - _builder = new RepositoryBuilder(); - _characterMap = StatusCharacterMap.Instance; - _compressor = new StatusCompressor(_characterMap); + return StatusCompressor.Compress(repo); } - private string Compress(Repository repo) + private static string CompressWithBranch(Repository repo) { - return _compressor.Compress(repo); + return StatusCompressor.CompressWithBranch(repo); } - private string CompressWithBranch(Repository repo) - { - return _compressor.CompressWithBranch(repo); - } - - private string Up => _characterMap.ArrowUpSign; + private static string Up => StatusCharacterMap.ARROW_UP_SIGN.ToString(); - private string Down => _characterMap.ArrowDownSign; + private static string Down => StatusCharacterMap.ARROW_DOWN_SIGN.ToString(); - private string Eq => _characterMap.IdenticalSign; + private static string Eq => StatusCharacterMap.IDENTICAL_SIGN.ToString(); - private string NoUp => _characterMap.NoUpstreamSign; + private static string NoUp => StatusCharacterMap.NO_UPSTREAM_SIGN.ToString(); - private string Ellipses => _characterMap.EllipsesSign; + private static string Ellipses => StatusCharacterMap.ELLIPSES_SIGN.ToString(); - private string StashCount => _characterMap.StashSign; + private static string StashCount => StatusCharacterMap.STASH_SIGN.ToString(); public class CompressMethod : StatusCompressorTests { - [Fact] - public void Ctor_ShouldThrow_WhenArgumentIsNull() - { - // arrange - - // act - Action act = () => _ = new StatusCompressor(null!); - - // asset - act.Should().Throw(); - } - [Fact] public void Returns_Empty_String_For_Empty_Repositories() {