-
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
4e3acb3
commit 5e2e8a1
Showing
10 changed files
with
250 additions
and
29 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
88 changes: 86 additions & 2 deletions
88
src/ByReplace.Test/Commands/Rule/OpenRule/OpenRuleCommandTest.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,90 @@ | ||
namespace ByReplace.Test.Commands.Rule.OpenRule | ||
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; | ||
|
||
public class OpenRuleCommandTest | ||
{ | ||
internal class OpenRuleCommandTest | ||
private readonly PathCompilationSyntax _pathCompilationSyntax; | ||
private readonly BrConfiguration _brConfiguration; | ||
private readonly Mock<IPrint> _printMock; | ||
private readonly Mock<IPrintBox> _printBoxMock; | ||
|
||
public OpenRuleCommandTest() | ||
{ | ||
_printMock = new Mock<IPrint>(); | ||
_printBoxMock = new Mock<IPrintBox>(); | ||
|
||
var configContent = BrContentFactory | ||
.CreateDefault() | ||
.AddConfig(BrContentFactory.ConfigNoPathDeclaration("obj", ".bin")) | ||
.AddRules( | ||
BrContentFactory | ||
.Rule("RuleOne") | ||
.WithExtensions(".cs", ".txt") | ||
.WithSkips("**\\Controllers\\*", "bin\\bin1.txt", "obj\\obj2.txt") | ||
.WithReplacement(BrContentFactory.Replacement("OldText", "NewText")), | ||
BrContentFactory | ||
.Rule("RuleTwo") | ||
.WithExtensions(".cs") | ||
.WithSkips("**\\Controllers\\*", "bin\\bin1.txt", "obj\\obj2.txt") | ||
.WithReplacement(BrContentFactory.Replacement("MyOldText", "MyNewText")) | ||
) | ||
.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(AnalyzerAndFixerTest)) | ||
.AddMembers(rootFolder) | ||
.AddBrConfiguration(configContent) | ||
.Create(); | ||
|
||
_brConfiguration = BrConfigurationBuilder | ||
.Create() | ||
.SetPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.SetConfigPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.Build(); | ||
} | ||
|
||
[Fact] | ||
public async Task Execute_WhenNotFindTheRuleOnRulesConfiguration_ShouldValidateTheLogThatShowRuleWasNotFind() | ||
{ | ||
// Arrange | ||
var command = new OpenRuleCommand(_brConfiguration, "NotConfiguratedRule", _printMock.Object, _printBoxMock.Object); | ||
|
||
// Act | ||
await command.ExecuteAsync(It.IsAny<CancellationToken>()); | ||
|
||
// Assert | ||
_printMock.Verify(c => c.Warning("Rule named NotConfiguratedRule was not found on brconfig file")); | ||
} | ||
|
||
[Fact] | ||
public async Task Execute_WhenFindTheRuleOnRulesConfiguration_ShouldValidateIfThePrintBoxWasCalled() | ||
{ | ||
// Arrange | ||
var expectedRule = _brConfiguration.Rules.Last(); | ||
var expectedPrintBox = new RuleBox(expectedRule); | ||
var command = new OpenRuleCommand(_brConfiguration, "RuleTwo", _printMock.Object, _printBoxMock.Object); | ||
|
||
// Act | ||
await command.ExecuteAsync(It.IsAny<CancellationToken>()); | ||
|
||
// Assert | ||
_printBoxMock.Verify(c => c.CreateBoxAndPrint(expectedPrintBox), Times.Once); | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
src/ByReplace.Test/Commands/Rule/OpenRule/PrintRuleBuilderTest.cs
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/ByReplace.Test/Commands/Rule/OpenRule/RuleBoxTest.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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
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; | ||
|
||
public class RuleBoxTest | ||
{ | ||
private readonly PathCompilationSyntax _pathCompilationSyntax; | ||
private readonly BrConfiguration _brConfiguration; | ||
private readonly Mock<IPrint> _printMock; | ||
|
||
public RuleBoxTest() | ||
{ | ||
_printMock = new Mock<IPrint>(); | ||
|
||
var configContent = BrContentFactory | ||
.CreateDefault() | ||
.AddConfig(BrContentFactory.ConfigNoPathDeclaration("obj", ".bin")) | ||
.AddRules(BrContentFactory | ||
.Rule("RuleOne") | ||
.WithExtensions(".cs", ".txt") | ||
.WithSkips("**\\Controllers\\*", "bin\\bin1.txt", "obj\\obj2.txt") | ||
.WithReplacement(BrContentFactory.Replacement("OldText", "NewText")), | ||
BrContentFactory | ||
.Rule("RuleTwo") | ||
.WithExtensions(".cs") | ||
.WithSkips("**\\Controllers\\*", "bin\\bin1.txt", "obj\\obj2.txt") | ||
.WithReplacement(BrContentFactory.Replacement("MyOldText", "MyNewText"))) | ||
.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(AnalyzerAndFixerTest)) | ||
.AddMembers(rootFolder) | ||
.AddBrConfiguration(configContent) | ||
.Create(); | ||
|
||
_brConfiguration = BrConfigurationBuilder | ||
.Create() | ||
.SetPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.SetConfigPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.Build(); | ||
} | ||
|
||
[Fact] | ||
public void RuleBox_WhenInstantiate_ShouldValidateTheBoxConfiguration() | ||
{ | ||
// Arrange & Act | ||
var ruleBox = new RuleBox(_brConfiguration.Rules.First()); | ||
|
||
// Assert | ||
Assert.Equal(100, ruleBox.Width); | ||
Assert.Equal(5 * 2, ruleBox.Height); | ||
Assert.Equal("Rule", ruleBox.BoxName); | ||
} | ||
|
||
[Fact] | ||
public void RuleBox_WhenInstantiate_ShouldValidateIfTwoObjectWithTheSameParametersAreEquals() | ||
{ | ||
// Arrange | ||
var ruleBoxFirst = new RuleBox(_brConfiguration.Rules.First()); | ||
var ruleBoxSecond = new RuleBox(_brConfiguration.Rules.First()); | ||
|
||
// Act | ||
var isEquals = ruleBoxFirst.Equals(ruleBoxSecond); | ||
var isEqualsLikeObject = ruleBoxFirst.Equals((object)ruleBoxSecond); | ||
var hasTheSameHashcode = ruleBoxFirst.GetHashCode() == ruleBoxSecond.GetHashCode(); | ||
|
||
// Assert | ||
Assert.Equal(ruleBoxSecond, ruleBoxFirst); | ||
Assert.True(isEquals); | ||
Assert.True(isEqualsLikeObject); | ||
Assert.True(hasTheSameHashcode); | ||
} | ||
|
||
[Fact] | ||
public void RuleBox_WhenInstantiate_ShouldValidateIfTwoObjectWithTheSameParametersAreNotEquals() | ||
{ | ||
// Arrange | ||
var ruleBoxFirst = new RuleBox(_brConfiguration.Rules.First()); | ||
var ruleBoxSecond = new RuleBox(_brConfiguration.Rules.Last()); | ||
|
||
// Act | ||
var isEquals = ruleBoxFirst.Equals(ruleBoxSecond); | ||
var isEqualsLikeObject = ruleBoxFirst.Equals((object)ruleBoxSecond); | ||
var hasTheSameHashcode = ruleBoxFirst.GetHashCode() == ruleBoxSecond.GetHashCode(); | ||
|
||
// Assert | ||
Assert.NotEqual(ruleBoxSecond, ruleBoxFirst); | ||
Assert.False(isEquals); | ||
Assert.False(isEqualsLikeObject); | ||
Assert.False(hasTheSameHashcode); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ands/Version/PrintBRVersionCommandTest.cs → ...st/Commands/Version/VersionCommandTest.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,6 @@ | ||
namespace ByReplace.Test.Commands.Version | ||
{ | ||
internal class PrintBRVersionCommandTest | ||
internal class VersionCommandTest | ||
{ | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...Commands/Version/PrintBRVersionCommand.cs → ...eplace/Commands/Version/VersionCommand.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
Oops, something went wrong.