diff --git a/src/ByReplace.Test/ByReplace.Test.csproj b/src/ByReplace.Test/ByReplace.Test.csproj
index b206281..8c6882d 100644
--- a/src/ByReplace.Test/ByReplace.Test.csproj
+++ b/src/ByReplace.Test/ByReplace.Test.csproj
@@ -31,9 +31,6 @@
-
-
-
diff --git a/src/ByReplace.Test/Commands/Apply/Rule/ApplyRuleCommandTest.cs b/src/ByReplace.Test/Commands/Apply/Rule/ApplyRuleCommandTest.cs
index e323cc4..1d79d5a 100644
--- a/src/ByReplace.Test/Commands/Apply/Rule/ApplyRuleCommandTest.cs
+++ b/src/ByReplace.Test/Commands/Apply/Rule/ApplyRuleCommandTest.cs
@@ -2,7 +2,6 @@
using ByReplace.Commands.Apply.Rule;
using ByReplace.Models;
using ByReplace.Printers;
-using ByReplace.Test.Analyzers;
using ByReplace.Test.Common.ConfigMock;
using ByReplace.Test.Common.FolderMock;
using Moq;
@@ -37,7 +36,7 @@ public ApplyRuleCommandTest()
FileSyntax.FileDeclaration("RootFile2.cs", "ITest = new Test()"));
_pathCompilationSyntax = PathFactory
- .Compile(nameof(AnalyzerAndFixerTest))
+ .Compile(nameof(ApplyRuleCommandTest))
.AddMembers(rootFolder)
.AddBrConfiguration(configContent)
.Create();
diff --git a/src/ByReplace.Test/Commands/Apply/Rules/ApplyRulesCommandTest.cs b/src/ByReplace.Test/Commands/Apply/Rules/ApplyRulesCommandTest.cs
index ad48eb4..3590a9e 100644
--- a/src/ByReplace.Test/Commands/Apply/Rules/ApplyRulesCommandTest.cs
+++ b/src/ByReplace.Test/Commands/Apply/Rules/ApplyRulesCommandTest.cs
@@ -2,7 +2,6 @@
using ByReplace.Commands.Apply.Rules;
using ByReplace.Models;
using ByReplace.Printers;
-using ByReplace.Test.Analyzers;
using ByReplace.Test.Common.ConfigMock;
using ByReplace.Test.Common.FolderMock;
using Moq;
@@ -36,7 +35,7 @@ public ApplyRulesCommandTEst()
FileSyntax.FileDeclaration("RootFile1.cs", "ITest = new Test()"),
FileSyntax.FileDeclaration("RootFile2.cs", "ITest = new Test()"));
_pathCompilationSyntax = PathFactory
- .Compile(nameof(AnalyzerAndFixerTest))
+ .Compile(nameof(ApplyRulesCommandTEst))
.AddMembers(rootFolder)
.AddBrConfiguration(configContent)
.Create();
diff --git a/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesCommandTest.cs b/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesCommandTest.cs
index 4f8d76e..0f62e64 100644
--- a/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesCommandTest.cs
+++ b/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesCommandTest.cs
@@ -2,7 +2,6 @@
using ByReplace.Commands.Rule.ListRules;
using ByReplace.Models;
using ByReplace.Printers;
-using ByReplace.Test.Analyzers;
using ByReplace.Test.Common.ConfigMock;
using ByReplace.Test.Common.FolderMock;
using Moq;
@@ -37,7 +36,7 @@ public ListRulesCommandTest()
FileSyntax.FileDeclaration("RootFile2.cs", "ITest = new Test()"));
_pathCompilationSyntax = PathFactory
- .Compile(nameof(AnalyzerAndFixerTest))
+ .Compile(nameof(ListRulesCommandTest))
.AddMembers(rootFolder)
.AddBrConfiguration(configContent)
.Create();
diff --git a/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs b/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs
index 76b58d2..cbba7f4 100644
--- a/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs
+++ b/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs
@@ -1,5 +1,4 @@
-using ByReplace.Commands.Apply.Rule;
-using ByReplace.Commands.Rule.ListRules;
+using ByReplace.Commands.Rule.ListRules;
using ByReplace.Test.Common.Helpers;
using Cocona;
using Xunit;
diff --git a/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs b/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs
index 875f6ed..96bc87b 100644
--- a/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs
+++ b/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs
@@ -3,7 +3,6 @@
using ByReplace.Builders;
using ByReplace.Models;
using ByReplace.Printers;
-using ByReplace.Test.Analyzers;
using ByReplace.Test.Common.ConfigMock;
using ByReplace.Test.Common.FolderMock;
using Moq;
@@ -38,7 +37,7 @@ public RulesBoxTest()
FileSyntax.FileDeclaration("RootFile2.cs", "ITest = new Test()"));
_pathCompilationSyntax = PathFactory
- .Compile(nameof(AnalyzerAndFixerTest))
+ .Compile(nameof(RulesBoxTest))
.AddMembers(rootFolder)
.AddBrConfiguration(configContent)
.Create();
@@ -86,7 +85,7 @@ public void RulesBox_WhenInstantiate_ShouldValidateIfTwoObjectWithTheSameParamet
{
// Arrange
var rulesBoxFirst = new RulesBox(_brConfiguration.Rules);
- var rulesBoxSecond = new RulesBox(ImmutableList.Empty);
+ var rulesBoxSecond = new RulesBox(ImmutableList.Empty);
// Act
var isEquals = rulesBoxFirst.Equals(rulesBoxSecond);
diff --git a/src/ByReplace.Test/Commands/Rule/OpenRule/OpenRuleCommandTest.cs b/src/ByReplace.Test/Commands/Rule/OpenRule/OpenRuleCommandTest.cs
index d66d112..ecc6380 100644
--- a/src/ByReplace.Test/Commands/Rule/OpenRule/OpenRuleCommandTest.cs
+++ b/src/ByReplace.Test/Commands/Rule/OpenRule/OpenRuleCommandTest.cs
@@ -1,13 +1,10 @@
using ByReplace.Builders;
-using ByReplace.Commands.Rule.ListRules;
using ByReplace.Commands.Rule.OpenRule;
using ByReplace.Models;
using ByReplace.Printers;
-using ByReplace.Test.Analyzers;
using ByReplace.Test.Common.ConfigMock;
using ByReplace.Test.Common.FolderMock;
using Moq;
-using System.Data;
using Xunit;
namespace ByReplace.Test.Commands.Rule.OpenRule;
@@ -48,7 +45,7 @@ public OpenRuleCommandTest()
FileSyntax.FileDeclaration("RootFile2.cs", "ITest = new Test()"));
_pathCompilationSyntax = PathFactory
- .Compile(nameof(AnalyzerAndFixerTest))
+ .Compile(nameof(OpenRuleCommandTest))
.AddMembers(rootFolder)
.AddBrConfiguration(configContent)
.Create();
diff --git a/src/ByReplace.Test/Commands/Rule/OpenRule/RuleBoxTest.cs b/src/ByReplace.Test/Commands/Rule/OpenRule/RuleBoxTest.cs
index 6ed6ef6..bee1372 100644
--- a/src/ByReplace.Test/Commands/Rule/OpenRule/RuleBoxTest.cs
+++ b/src/ByReplace.Test/Commands/Rule/OpenRule/RuleBoxTest.cs
@@ -1,13 +1,10 @@
using ByReplace.Builders;
-using ByReplace.Commands.Rule.ListRules;
using ByReplace.Commands.Rule.OpenRule;
using ByReplace.Models;
using ByReplace.Printers;
-using ByReplace.Test.Analyzers;
using ByReplace.Test.Common.ConfigMock;
using ByReplace.Test.Common.FolderMock;
using Moq;
-using System.Collections.Immutable;
using Xunit;
namespace ByReplace.Test.Commands.Rule.OpenRule;
@@ -44,7 +41,7 @@ public RuleBoxTest()
FileSyntax.FileDeclaration("RootFile2.cs", "ITest = new Test()"));
_pathCompilationSyntax = PathFactory
- .Compile(nameof(AnalyzerAndFixerTest))
+ .Compile(nameof(RuleBoxTest))
.AddMembers(rootFolder)
.AddBrConfiguration(configContent)
.Create();
diff --git a/src/ByReplace.Test/Commands/TimerFinish/TimerFinishCommandTest.cs b/src/ByReplace.Test/Commands/TimerFinish/TimerFinishCommandTest.cs
index abc72ed..37365b7 100644
--- a/src/ByReplace.Test/Commands/TimerFinish/TimerFinishCommandTest.cs
+++ b/src/ByReplace.Test/Commands/TimerFinish/TimerFinishCommandTest.cs
@@ -1,6 +1,29 @@
-namespace ByReplace.Test.Commands.TimerFinish
+using ByReplace.Commands.TimerFinish;
+using ByReplace.Printers;
+using Moq;
+using Xunit;
+
+namespace ByReplace.Test.Commands.TimerFinish;
+
+public class TimerFinishCommandTest
{
- internal class TimerFinishCommandTest
+ private readonly Mock _printMock;
+
+ public TimerFinishCommandTest()
{
+ _printMock = new Mock();
+ }
+
+ [Fact]
+ public async Task ExecuteAsync_ShouldCallPrintTimerOnce_WhenExecutionFinishes()
+ {
+ // Arrange
+ var command = new TimerFinishCommand(_printMock.Object);
+
+ // Act
+ await command.ExecuteAsync();
+
+ // Assert
+ _printMock.Verify(c => c.Timer(), Times.Once);
}
}
diff --git a/src/ByReplace.Test/Commands/Version/NugetVersionTest.cs b/src/ByReplace.Test/Commands/Version/NugetVersionTest.cs
index 10fd642..9dfb194 100644
--- a/src/ByReplace.Test/Commands/Version/NugetVersionTest.cs
+++ b/src/ByReplace.Test/Commands/Version/NugetVersionTest.cs
@@ -1,6 +1,30 @@
-namespace ByReplace.Test.Commands.Version
+using ByReplace.Commands.TimerFinish;
+using ByReplace.Printers;
+using Moq;
+using Xunit;
+
+namespace ByReplace.Test.Commands.Version
{
- internal class NugetVersionTest
+ public class NugetVersionTest
{
+ public readonly Mock _printMock;
+
+ public NugetVersionTest()
+ {
+ _printMock = new Mock();
+ }
+
+ [Fact]
+ public async Task Execute_WhenCalledTimerToPrintTimeOfExecution_ShoulVerifyIfTimerWasCalledOnce()
+ {
+ // Arrange
+ var command = new TimerFinishCommand(_printMock.Object);
+
+ // Act
+ await command.ExecuteAsync(It.IsAny());
+
+ // Assert
+ _printMock.Verify(c => c.Timer(), Times.Once);
+ }
}
}
diff --git a/src/ByReplace.Test/Mappers/DirectoryThreeTest.cs b/src/ByReplace.Test/Mappers/DirectoryThreeTest.cs
new file mode 100644
index 0000000..8c828a6
--- /dev/null
+++ b/src/ByReplace.Test/Mappers/DirectoryThreeTest.cs
@@ -0,0 +1,96 @@
+using ByReplace.Builders;
+using ByReplace.Mappers;
+using ByReplace.Models;
+using ByReplace.Printers;
+using ByReplace.Test.Common.ConfigMock;
+using ByReplace.Test.Common.FolderMock;
+using Moq;
+using Xunit;
+
+namespace ByReplace.Test.Mappers;
+
+public class DirectoryThreeTest
+{
+ private readonly PathCompilationSyntax _pathCompilationSyntax;
+ private readonly BrConfiguration _brConfiguration;
+ private readonly Mock _printMock;
+
+ public DirectoryThreeTest()
+ {
+ _printMock = new Mock();
+
+ var configContent = BrContentFactory
+ .CreateDefault()
+ .AddConfig(BrContentFactory.ConfigNoPathDeclaration("obj", ".bin"))
+ .AddRules(BrContentFactory
+ .Rule("RuleTest")
+ .WithExtensions(".cs", ".txt")
+ .WithSkips("**\\Controllers\\*", "bin\\bin1.txt", "obj\\obj2.txt")
+ .WithReplacement(BrContentFactory.Replacement("Test", "Test2")))
+ .Compile();
+
+ var rootFolder = FolderSyntax
+ .FolderDeclaration("RootFolder")
+ .AddMembers(
+ FileSyntax.FileDeclaration("RootFile1.cs", "ITest = new Test()"),
+ FileSyntax.FileDeclaration("RootFile2.cs", "ITest = new Test()"));
+
+ _pathCompilationSyntax = PathFactory
+ .Compile(nameof(DirectoryThreeTest))
+ .AddMembers(rootFolder)
+ .AddBrConfiguration(configContent)
+ .Create();
+
+ _brConfiguration = BrConfigurationBuilder
+ .Create()
+ .SetPath($"./{_pathCompilationSyntax.InternalIdentifier}")
+ .SetConfigPath($"./{_pathCompilationSyntax.InternalIdentifier}")
+ .Build();
+ }
+
+ [Fact]
+ public void MapThreeSources_WhenStartTheSourceMap_ShouldReturnTheThreeFile()
+ {
+ // Arrange
+ var dirThree = new DirectoryThree(_printMock.Object);
+
+ // Act
+ var nodes = dirThree.MapThreeSources(_brConfiguration.Path);
+
+ // Assert
+ Assert.Equal(2, nodes.Count);
+ Assert.Collection(nodes,
+ entry =>
+ {
+ Assert.Single(entry.Files);
+ Assert.NotEmpty(entry.Parent);
+ Assert.NotEmpty(entry.Path);
+ Assert.Collection(entry.Files,
+ entry =>
+ {
+ Assert.Equal(".json", entry.Extension);
+ Assert.EndsWith("brconfig.json", entry.FullName);
+ Assert.Equal("brconfig.json", entry.Name);
+ });
+ },
+ entry =>
+ {
+ Assert.Equal(2, entry.Files.Count);
+ Assert.NotEmpty(entry.Parent);
+ Assert.NotEmpty(entry.Path);
+ Assert.Collection(entry.Files,
+ entry =>
+ {
+ Assert.Equal(".cs", entry.Extension);
+ Assert.EndsWith("RootFile1.cs", entry.FullName);
+ Assert.Equal("RootFile1.cs", entry.Name);
+ },
+ entry =>
+ {
+ Assert.Equal(".cs", entry.Extension);
+ Assert.EndsWith("RootFile2.cs", entry.FullName);
+ Assert.Equal("RootFile2.cs", entry.Name);
+ });
+ });
+ }
+}
diff --git a/src/ByReplace.Test/Matches/ExtensionMatchTest.cs b/src/ByReplace.Test/Matches/ExtensionMatchTest.cs
new file mode 100644
index 0000000..11756a2
--- /dev/null
+++ b/src/ByReplace.Test/Matches/ExtensionMatchTest.cs
@@ -0,0 +1,39 @@
+using ByReplace.Matches;
+using Xunit;
+
+namespace ByReplace.Test.Matches;
+
+public class ExtensionMatchTest
+{
+ [Theory]
+ [InlineData(".cs", ".cs", ".text", ".py")]
+ [InlineData(".text", ".cs", ".text", ".py")]
+ [InlineData(".py", ".cs", ".text", ".py")]
+ public void HasMatch_WhenTryMatchTheAllowExtensionFromFile_ShouldMatch(string extension, params string[] extensions)
+ {
+ // Arrange
+ var match = new ExtensionMatch(extension, extensions);
+
+ // Act
+ var hasMatch = match.HasMatch;
+
+ // Assert
+ Assert.True(hasMatch);
+ }
+
+ [Theory]
+ [InlineData(".cs", ".text", ".py")]
+ [InlineData(".text", ".cs", ".py")]
+ [InlineData(".py", ".cs", ".text")]
+ public void HasMatch_WhenTryMatchTheDenyExtensionFromFile_ShouldNotMatch(string extension, params string[] extensions)
+ {
+ // Arrange
+ var match = new ExtensionMatch(extension, extensions);
+
+ // Act
+ var hasMatch = match.HasMatch;
+
+ // Assert
+ Assert.False(hasMatch);
+ }
+}
diff --git a/src/ByReplace.Test/Matches/SkipMatchTest.cs b/src/ByReplace.Test/Matches/SkipMatchTest.cs
new file mode 100644
index 0000000..b291b6c
--- /dev/null
+++ b/src/ByReplace.Test/Matches/SkipMatchTest.cs
@@ -0,0 +1,53 @@
+using ByReplace.Mappers;
+using ByReplace.Matches;
+using Xunit;
+
+namespace ByReplace.Test.Matches;
+
+public class SkipMatchTest
+{
+ [Fact]
+ public void HasMatch_WhenTryMatchTheFileAndItNotMatchToAnyRuleToSkip_ShouldReturnFalse()
+ {
+ // Arrange
+ var fileMapperMock = new FileMapper(Guid.NewGuid(), "testFile.txt", "c://byreplace//testFile.txt", ".txt");
+
+ var match = new SkipMatch("c://byreplace//", fileMapperMock, new string[] { "Startup.cs", "Program.cs", "**/Controllers/*" });
+
+ // Act
+ var hasMatch = match.HasMatch;
+
+ // Assert
+ Assert.False(hasMatch);
+ }
+
+ [Fact]
+ public void HasMatch_WhenTryMatchSomeFileByDirectoryPath_ShouldReturnTrue()
+ {
+ // Arrange
+ var fileMapperMock = new FileMapper(Guid.NewGuid(), "testFile.txt", "c://byreplace//testFile.txt", ".txt");
+
+ var match = new SkipMatch("c://byreplace//", fileMapperMock, new string[] { "**/byreplace/*" });
+
+ // Act
+ var hasMatch = match.HasMatch;
+
+ // Assert
+ Assert.True(hasMatch);
+ }
+
+ [Fact]
+ public void HasMatch_WhenTryMatchSomeFileByDirectoryWithFileNamePath_ShouldReturnTrue()
+ {
+ // Arrange
+ var fileMapperMock = new FileMapper(Guid.NewGuid(), "testFile.txt", "c://byreplace//testFile.txt", ".txt");
+
+ var match = new SkipMatch("c://byreplace//", fileMapperMock, ["//byreplace//testFile.txt"]);
+
+ // Act
+ var hasMatch = match.HasMatch;
+
+ // Assert
+ Assert.True(hasMatch);
+ }
+}
diff --git a/src/ByReplace.Test/Models/BrConfigurationTest.cs b/src/ByReplace.Test/Models/BrConfigurationTest.cs
new file mode 100644
index 0000000..9b0a1bb
--- /dev/null
+++ b/src/ByReplace.Test/Models/BrConfigurationTest.cs
@@ -0,0 +1,39 @@
+using ByReplace.Models;
+using System.Collections.Immutable;
+using Xunit;
+
+namespace ByReplace.Test.Models;
+
+public class BrConfigurationTest
+{
+ [Fact]
+ public void BrConfiguration_WhenInstantiate_ShouldValidateThePropertiesValues()
+ {
+ // Arrange && Act
+ var config = new BrConfiguration("C://ByReplace", ["**//Controllers/*"], ImmutableList.Empty);
+
+ // Assert
+ Assert.Equal("C://ByReplace", config.Path);
+ Assert.Empty(config.Rules);
+ Assert.Single(config.SkipDirectories);
+ Assert.Collection(config.SkipDirectories, entry =>
+ {
+ Assert.Equal("**//Controllers/*", entry);
+ });
+ }
+
+ [Fact]
+ public void SetOnlyOneRule_WhenSetNewRule_ShouldReplaceOldRulesWithTheNewOne()
+ {
+ // Arrange
+ var replacement = new Replacement(["private readonly Test _test;"], "private readonly Test test;");
+ var newRule = new ByReplace.Models.Rule("name", "description", ["**//Controller/*"], [".cs", ".py"], replacement);
+ var config = new BrConfiguration("C://ByReplace", ["**//Controllers/*"], ImmutableList.Empty);
+
+ // Act
+ config.SetOnlyOneRule(newRule);
+
+ // Assert
+ Assert.Single(config.SkipDirectories);
+ }
+}
diff --git a/src/ByReplace/Analyzers/Analyzer.cs b/src/ByReplace/Analyzers/Analyzer.cs
index 5d91ebd..f39c5b1 100644
--- a/src/ByReplace/Analyzers/Analyzer.cs
+++ b/src/ByReplace/Analyzers/Analyzer.cs
@@ -17,8 +17,8 @@ internal ImmutableList LoadThreeFiles()
{
print.Information("Identifying folder three files.");
- DirectoryThree directoryThree = new DirectoryThree(brConfiguration.Path);
- directoryThree.MapThreeSources();
+ DirectoryThree directoryThree = new DirectoryThree(print);
+ directoryThree.MapThreeSources(brConfiguration.Path);
return directoryThree.Nodes.ToImmutableList();
}
diff --git a/src/ByReplace/Commands/Rule/ListRules/RulesBox.cs b/src/ByReplace/Commands/Rule/ListRules/RulesBox.cs
index 5f11bd8..1b84014 100644
--- a/src/ByReplace/Commands/Rule/ListRules/RulesBox.cs
+++ b/src/ByReplace/Commands/Rule/ListRules/RulesBox.cs
@@ -1,6 +1,4 @@
-using System.Xml.Linq;
-
-namespace ByReplace.Commands.Rule.ListRules;
+namespace ByReplace.Commands.Rule.ListRules;
internal sealed class RulesBox : IBox, IEquatable, IEqualityComparer
{
diff --git a/src/ByReplace/Commands/Rule/OpenRule/OpenRuleCommand.cs b/src/ByReplace/Commands/Rule/OpenRule/OpenRuleCommand.cs
index d790684..d8c5990 100644
--- a/src/ByReplace/Commands/Rule/OpenRule/OpenRuleCommand.cs
+++ b/src/ByReplace/Commands/Rule/OpenRule/OpenRuleCommand.cs
@@ -1,6 +1,4 @@
-using ByReplace.Printers;
-
-namespace ByReplace.Commands.Rule.OpenRule;
+namespace ByReplace.Commands.Rule.OpenRule;
internal class OpenRuleCommand : ICommand
{
diff --git a/src/ByReplace/Commands/Rule/OpenRule/RuleBox.cs b/src/ByReplace/Commands/Rule/OpenRule/RuleBox.cs
index 35bffca..7cae351 100644
--- a/src/ByReplace/Commands/Rule/OpenRule/RuleBox.cs
+++ b/src/ByReplace/Commands/Rule/OpenRule/RuleBox.cs
@@ -1,6 +1,4 @@
-using ByReplace.Commands.Rule.ListRules;
-
-namespace ByReplace.Commands.Rule.OpenRule;
+namespace ByReplace.Commands.Rule.OpenRule;
internal sealed class RuleBox : IBox, IEquatable, IEqualityComparer
{
diff --git a/src/ByReplace/Commands/Version/NugetVersion.cs b/src/ByReplace/Commands/Version/NugetVersion.cs
index 96fc10b..709e97c 100644
--- a/src/ByReplace/Commands/Version/NugetVersion.cs
+++ b/src/ByReplace/Commands/Version/NugetVersion.cs
@@ -4,17 +4,22 @@
using System.Reflection;
namespace ByReplace.Commands.Version;
-internal class NugetVersion
+internal interface INugetVersion
+{
+ Task GetByReplaceNugetVersionAsync(CancellationToken cancellationToken);
+}
+
+internal class NugetVersion : INugetVersion
{
private readonly SourceRepository _sourceRepository;
private readonly SourceCacheContext _sourceCacheContext;
- private readonly PrintConsole _printConsole;
+ private readonly IPrint _printConsole;
- public NugetVersion()
+ public NugetVersion(IPrint print)
{
+ _printConsole = print;
_sourceRepository = Repository.Factory.GetCoreV3(new PackageSource(NuGetConstants.V3FeedUrl));
_sourceCacheContext = new SourceCacheContext();
- _printConsole = new PrintConsole();
}
public async Task GetByReplaceNugetVersionAsync(CancellationToken cancellationToken)
diff --git a/src/ByReplace/Commands/Version/VersionCommand.cs b/src/ByReplace/Commands/Version/VersionCommand.cs
index 12d52f7..f1ecc43 100644
--- a/src/ByReplace/Commands/Version/VersionCommand.cs
+++ b/src/ByReplace/Commands/Version/VersionCommand.cs
@@ -2,9 +2,15 @@
internal class VersionCommand : ICommand
{
+ private readonly INugetVersion _nugetVersion;
+
+ public VersionCommand(INugetVersion nugetVersion)
+ {
+ _nugetVersion = nugetVersion;
+ }
+
public async ValueTask ExecuteAsync(CancellationToken cancellationToken)
{
- NugetVersion nugetVersion = new NugetVersion();
- await nugetVersion.GetByReplaceNugetVersionAsync(cancellationToken);
+ await _nugetVersion.GetByReplaceNugetVersionAsync(cancellationToken);
}
}
diff --git a/src/ByReplace/Exceptions/GlobalHandleException.cs b/src/ByReplace/Exceptions/GlobalHandleException.cs
index 2fafb40..08f1ca2 100644
--- a/src/ByReplace/Exceptions/GlobalHandleException.cs
+++ b/src/ByReplace/Exceptions/GlobalHandleException.cs
@@ -2,6 +2,7 @@
namespace ByReplace.Exceptions;
+[ExcludeFromCodeCoverage]
internal class GlobalHandleExceptionAttribute : CommandFilterAttribute
{
readonly IPrint print = new PrintConsole();
diff --git a/src/ByReplace/Mappers/DirectoryThree.cs b/src/ByReplace/Mappers/DirectoryThree.cs
index 4ad8ab5..b7ddfdf 100644
--- a/src/ByReplace/Mappers/DirectoryThree.cs
+++ b/src/ByReplace/Mappers/DirectoryThree.cs
@@ -2,13 +2,11 @@
public class DirectoryThree
{
- private readonly string _path;
- private readonly PrintConsole _printer;
+ private readonly IPrint _printer;
- public DirectoryThree(string path)
+ public DirectoryThree(IPrint print)
{
- _path = path;
- _printer = new PrintConsole();
+ _printer = print;
}
public record struct DirectoryNode(
@@ -18,15 +16,17 @@ public record struct DirectoryNode(
ImmutableList Files
);
- public List Nodes { get; private set; }
+ public ImmutableList Nodes { get; private set; }
- public void MapThreeSources()
+ public ImmutableList MapThreeSources(string path)
{
List nodes = new List();
- MapThreeSubFolders(_path, ref nodes);
+ MapThreeSubFolders(path, ref nodes);
- Nodes = nodes;
+ Nodes = nodes.ToImmutableList();
+
+ return Nodes;
}
private void MapThreeSubFolders(string dir, ref List nodes)
diff --git a/src/ByReplace/Mappers/FileMapper.cs b/src/ByReplace/Mappers/FileMapper.cs
index 62df035..bfb4d78 100644
--- a/src/ByReplace/Mappers/FileMapper.cs
+++ b/src/ByReplace/Mappers/FileMapper.cs
@@ -1,3 +1,4 @@
namespace ByReplace.Mappers;
+[ExcludeFromCodeCoverage]
public record struct FileMapper(Guid id, string Name, string FullName, string Extension);
\ No newline at end of file
diff --git a/src/ByReplace/Matches/SkipMatch.cs b/src/ByReplace/Matches/SkipMatch.cs
index d7e7ef7..d03da20 100644
--- a/src/ByReplace/Matches/SkipMatch.cs
+++ b/src/ByReplace/Matches/SkipMatch.cs
@@ -39,6 +39,7 @@ private bool SkipDir()
dir.Contains(SanitizePattern(c), StringComparison.InvariantCultureIgnoreCase));
}
+ [MethodImpl(MethodImplOptions.AggressiveOptimization)]
private static unsafe string SanitizePattern(string pattern)
{
int maxBufferSize = pattern.Length;
diff --git a/src/ByReplace/Models/BrConfiguration.cs b/src/ByReplace/Models/BrConfiguration.cs
index 7f19861..b878e95 100644
--- a/src/ByReplace/Models/BrConfiguration.cs
+++ b/src/ByReplace/Models/BrConfiguration.cs
@@ -1,4 +1,6 @@
-namespace ByReplace.Models;
+[assembly: InternalsVisibleTo("ByReplace.Test")]
+
+namespace ByReplace.Models;
internal class BrConfiguration
{
diff --git a/src/ByReplace/Program.cs b/src/ByReplace/Program.cs
index 7ab7a85..11ae69c 100644
--- a/src/ByReplace/Program.cs
+++ b/src/ByReplace/Program.cs
@@ -20,6 +20,8 @@
builder.Services.AddScoped();
builder.Services.AddScoped();
+builder.Services.AddScoped();
+
CoconaApp app = builder.Build();
app.UseFilter(new GlobalHandleExceptionAttribute());
@@ -28,7 +30,7 @@
app
.AddSubCommand("apply", apply =>
{
- apply.AddCommand("rule", async (ApplyRuleParameter applyRuleParameters, IPrint print) =>
+ apply.AddCommand("rule", async (ApplyRuleParameter applyRuleParameters, IPrint print, INugetVersion nugetVersion) =>
{
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
@@ -43,7 +45,7 @@
CompositeCommand compositeCommand = new CompositeCommand(new ICommand[]
{
new PrintLogoCommand(print),
- new VersionCommand(),
+ new VersionCommand(nugetVersion),
new ApplyRuleCommand(configuration, applyRuleParameters, print),
new TimerFinishCommand(print)
});
@@ -51,7 +53,7 @@
await compositeCommand.ExecuteAsync(token);
});
- apply.AddCommand("rules", async (ApplyParameter applyParameters, IPrint print) =>
+ apply.AddCommand("rules", async (ApplyParameter applyParameters, IPrint print, INugetVersion nugetVersion) =>
{
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
@@ -65,7 +67,7 @@
CompositeCommand compositeCommand = new CompositeCommand(new ICommand[]
{
new PrintLogoCommand(print),
- new VersionCommand(),
+ new VersionCommand(nugetVersion),
new ApplyRulesCommand(configuration, print),
new TimerFinishCommand(print)
});
@@ -80,7 +82,7 @@
app
.AddSubCommand("rule", rule =>
{
- rule.AddCommand("list-rules", async (ListRulesParameter listRulesParameter, IPrint print, IPrintBox printBox) =>
+ rule.AddCommand("list-rules", async (ListRulesParameter listRulesParameter, IPrint print, IPrintBox printBox, INugetVersion nugetVersion) =>
{
//Print all rule's names from config file
CancellationTokenSource source = new CancellationTokenSource();
@@ -94,7 +96,7 @@
CompositeCommand compositeCommand = new CompositeCommand(new ICommand[]
{
new PrintLogoCommand(print),
- new VersionCommand(),
+ new VersionCommand(nugetVersion),
new ListRulesCommand(configuration, printBox),
new TimerFinishCommand(print)
});
@@ -102,7 +104,7 @@
await compositeCommand.ExecuteAsync(token);
});
- rule.AddCommand("open-rule", async (OpenRuleParameter openRuleParameter, IPrint print, IPrintBox printBox) =>
+ rule.AddCommand("open-rule", async (OpenRuleParameter openRuleParameter, IPrint print, IPrintBox printBox, INugetVersion nugetVersion) =>
{
//Print rule in config file
CancellationTokenSource source = new CancellationTokenSource();
@@ -116,7 +118,7 @@
CompositeCommand compositeCommand = new CompositeCommand(new ICommand[]
{
new PrintLogoCommand(print),
- new VersionCommand(),
+ new VersionCommand(nugetVersion),
new OpenRuleCommand(configuration, openRuleParameter.Name, print, printBox),
new TimerFinishCommand(print)
});