-
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
3caa86d
commit f5404b1
Showing
20 changed files
with
230 additions
and
292 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,64 @@ | ||
using ByReplace.Analyzers; | ||
using ByReplace.Builders; | ||
using ByReplace.Models; | ||
using ByReplace.Printers; | ||
using ByReplace.Test.Common.ConfigMock; | ||
using ByReplace.Test.Common.FolderMock; | ||
using ByReplace.Test.ClassFixture; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace ByReplace.Test.Analyzers; | ||
|
||
public class AnalyzerAndFixerTest | ||
public class AnalyzerAndFixerTest : IClassFixture<WorkspaceFixture> | ||
{ | ||
private readonly PathCompilationSyntax _pathCompilationSyntax; | ||
private readonly BrConfiguration _brConfiguration; | ||
private readonly WorkspaceFixture _workspace; | ||
private readonly Mock<IPrint> _printMock; | ||
|
||
public AnalyzerAndFixerTest() | ||
public AnalyzerAndFixerTest(WorkspaceFixture workspace) | ||
{ | ||
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(AnalyzerAndFixerTest)) | ||
.AddMembers(rootFolder) | ||
.AddBrConfiguration(configContent) | ||
.Create(); | ||
|
||
_brConfiguration = BrConfigurationBuilder | ||
.Create() | ||
.SetPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.SetConfigPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.Build(); | ||
|
||
_workspace = workspace; | ||
_printMock = new Mock<IPrint>(); | ||
} | ||
|
||
[Fact] | ||
public void TryMatchRule_MapTheFilesThatMatchToRule_ShouldReturnFilesThatMatch() | ||
{ | ||
// Arrange | ||
var analyzer = new Analyzer(_brConfiguration, _printMock.Object); | ||
var analyzer = new Analyzer(_workspace.BrConfiguration, _printMock.Object); | ||
var analyzerAndFixer = new AnalyzerAndFixer(_printMock.Object); | ||
|
||
// Act | ||
var directoryNode = analyzer.LoadThreeFiles().Last(); | ||
analyzerAndFixer.TryMatchRule(directoryNode, _brConfiguration.Rules); | ||
analyzerAndFixer.TryMatchRule(directoryNode, _workspace.BrConfiguration.Rules); | ||
|
||
// Assert | ||
Assert.Equal(2, analyzerAndFixer.Count); | ||
|
||
Assert.Collection(analyzerAndFixer, | ||
entry => | ||
{ | ||
Assert.Equal("RootFile1.cs", entry.Key.Name); | ||
Assert.Equal(".cs", entry.Key.Extension); | ||
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); | ||
}, | ||
entry => | ||
{ | ||
Assert.Equal("RootFile2.cs", entry.Key.Name); | ||
Assert.Equal(".cs", entry.Key.Extension); | ||
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); | ||
}); | ||
entry => | ||
{ | ||
Assert.Equal("RootFile1.cs", entry.Key.Name); | ||
Assert.Equal(".cs", entry.Key.Extension); | ||
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); | ||
}, | ||
entry => | ||
{ | ||
Assert.Equal("RootFile2.cs", entry.Key.Name); | ||
Assert.Equal(".cs", entry.Key.Extension); | ||
Assert.Collection(entry.Value, rule => Assert.Equal("RuleTest", rule.Name)); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void TryMatchRule_WhenMapTheFilesThatMatchToRule_ShouldValidateLogWasCalled() | ||
{ | ||
// Arrange | ||
var analyzer = new Analyzer(_brConfiguration, _printMock.Object); | ||
var analyzer = new Analyzer(_workspace.BrConfiguration, _printMock.Object); | ||
var analyzerAndFixer = new AnalyzerAndFixer(_printMock.Object); | ||
|
||
// Act | ||
var directoryNode = analyzer.LoadThreeFiles().Last(); | ||
analyzerAndFixer.TryMatchRule(directoryNode, _brConfiguration.Rules); | ||
analyzerAndFixer.TryMatchRule(directoryNode, _workspace.BrConfiguration.Rules); | ||
|
||
// Assert | ||
_printMock.Verify(x => x.Information("[Cyan]1 rules in total match the file [Cyan]RootFile1.cs."), Times.Once); | ||
_printMock.Verify(x => x.Information("[Cyan]1 rules in total match the file [Cyan]RootFile2.cs."), 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
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
Oops, something went wrong.