-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e2e8a1
commit c2bc4d9
Showing
26 changed files
with
333 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 25 additions & 2 deletions
27
src/ByReplace.Test/Commands/TimerFinish/TimerFinishCommandTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IPrint> _printMock; | ||
|
||
public TimerFinishCommandTest() | ||
{ | ||
_printMock = new Mock<IPrint>(); | ||
} | ||
|
||
[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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IPrint> _printMock; | ||
|
||
public NugetVersionTest() | ||
{ | ||
_printMock = new Mock<IPrint>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Execute_WhenCalledTimerToPrintTimeOfExecution_ShoulVerifyIfTimerWasCalledOnce() | ||
{ | ||
// Arrange | ||
var command = new TimerFinishCommand(_printMock.Object); | ||
|
||
// Act | ||
await command.ExecuteAsync(It.IsAny<CancellationToken>()); | ||
|
||
// Assert | ||
_printMock.Verify(c => c.Timer(), Times.Once); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IPrint> _printMock; | ||
|
||
public DirectoryThreeTest() | ||
{ | ||
_printMock = new Mock<IPrint>(); | ||
|
||
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); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.