-
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
a57274d
commit cad50f1
Showing
20 changed files
with
363 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ByReplace.Test.Analyzers; | ||
|
||
internal class AnalyzerRunnerTest | ||
{ | ||
} |
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,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ByReplace.Test.Analyzers; | ||
|
||
internal class AnalyzersAndFixersTest | ||
{ | ||
} |
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,69 @@ | ||
using ByReplace.Analyzers; | ||
using ByReplace.Builders; | ||
using ByReplace.Models; | ||
using ByReplace.Printers; | ||
using ByReplace.Test.Common.FolderMock; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace ByReplace.Test.Analyzers; | ||
|
||
public class AnalyzersTest | ||
{ | ||
private readonly PathCompilationSyntax _pathCompilationSyntax; | ||
private readonly BrConfiguration _brConfiguration; | ||
private readonly Mock<IPrint> _printMock; | ||
|
||
public AnalyzersTest() | ||
{ | ||
var levelOne = FolderSyntax | ||
.FolderDeclaration("OneLevel") | ||
.AddMenbers(FileSyntax.FileDeclaration("FileOne.cs", "ITest = new Test()")); | ||
|
||
var SecondOne = FolderSyntax.FolderDeclaration("SecondLevel") | ||
.AddParent(levelOne) | ||
.AddMenbers(FileSyntax.FileDeclaration("FileSecond.cs", "ITest2 = new Test()")); | ||
|
||
_pathCompilationSyntax = PathFactory | ||
.Compile(nameof(AnalyzersTest)) | ||
.AddFolders(SecondOne) | ||
.CreateThreeFolder(); | ||
|
||
_brConfiguration = BrConfigurationBuilder | ||
.Instantiate() | ||
.SetPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.SetConfigPath($"./{_pathCompilationSyntax.InternalIdentifier}") | ||
.Build(); | ||
|
||
_printMock = new Mock<IPrint>(); | ||
} | ||
|
||
[Fact] | ||
public void LoadThreeFiles_MapAllSourceThreeOfDirectory_ShouldReturnSourceFileThree() | ||
{ | ||
// Arrange | ||
var analyzer = new Analyzer(_brConfiguration, _printMock.Object); | ||
|
||
// Act | ||
var directoryNodes = analyzer.LoadThreeFiles(); | ||
|
||
// Assert | ||
Assert.Equal(3, directoryNodes.Count); | ||
Assert.Single(directoryNodes[0].Files); | ||
Assert.Single(directoryNodes[1].Files); | ||
Assert.Single(directoryNodes[2].Files); | ||
} | ||
|
||
[Fact] | ||
public void LoadThreeFiles_WhenPrintLogInformation_ShouldValidateLogWasCalled() | ||
{ | ||
// Arrange | ||
var analyzer = new Analyzer(_brConfiguration, _printMock.Object); | ||
|
||
// Act | ||
var directoryNodes = analyzer.LoadThreeFiles(); | ||
|
||
// Assert | ||
_printMock.Verify(x => x.Information("Identifying folder three files."), 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,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ByReplace.Test.Analyzers; | ||
|
||
internal class DocumentFixTest | ||
{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ByReplace.Test.Common.ConfigMock; | ||
|
||
public class ConfigFactory | ||
{ | ||
|
||
} |
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,30 @@ | ||
namespace ByReplace.Test.Common.FolderMock; | ||
|
||
internal sealed class FileSyntax | ||
{ | ||
public FileSyntax(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public FileSyntax(string name, string content) | ||
{ | ||
Name = name; | ||
Content = content; | ||
} | ||
|
||
public string Name { get; } | ||
public string Content { get; } | ||
|
||
public string Extension => System.IO.Path.GetExtension(Name); | ||
|
||
public static FileSyntax FileDeclaration(string name) | ||
{ | ||
return new FileSyntax(name); | ||
} | ||
|
||
public static FileSyntax FileDeclaration(string name, string content) | ||
{ | ||
return new FileSyntax(name, content); | ||
} | ||
} |
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,57 @@ | ||
namespace ByReplace.Test.Common.FolderMock; | ||
|
||
internal sealed class FolderSyntax | ||
{ | ||
public FolderSyntax(string name) | ||
{ | ||
Name = name; | ||
Files = new List<FileSyntax>(); | ||
} | ||
|
||
public FolderSyntax(string name, FolderSyntax parent) | ||
{ | ||
Name = name; | ||
Parent = parent; | ||
Files = new List<FileSyntax>(); | ||
} | ||
|
||
public FolderSyntax(string name, FolderSyntax parent, List<FileSyntax> files) | ||
{ | ||
Name = name; | ||
Parent = parent; | ||
Files = files; | ||
} | ||
|
||
public FolderSyntax Parent { get; private set; } | ||
|
||
public string Name { get; private set; } | ||
|
||
public List<FileSyntax> Files { get; private set; } | ||
|
||
public static FolderSyntax FolderDeclaration(string name) | ||
{ | ||
return new FolderSyntax(name); | ||
} | ||
|
||
public static FolderSyntax FolderDeclaration(string name, FolderSyntax parent) | ||
{ | ||
return new FolderSyntax(name, parent); | ||
} | ||
|
||
public static FolderSyntax FolderDeclaration(string name, FolderSyntax parent, List<FileSyntax> files) | ||
{ | ||
return new FolderSyntax(name, parent, files); | ||
} | ||
|
||
public FolderSyntax AddMenbers(FileSyntax fileSyntax) | ||
{ | ||
this.Files.Add(fileSyntax); | ||
return this; | ||
} | ||
|
||
public FolderSyntax AddParent(FolderSyntax parent) | ||
{ | ||
this.Parent = parent; | ||
return this; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/ByReplace.Test/Common/FolderMock/PathCompilationSyntax.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,82 @@ | ||
using System.Runtime.InteropServices; | ||
namespace ByReplace.Test.Common.FolderMock; | ||
|
||
internal sealed class PathCompilationSyntax | ||
{ | ||
public List<FolderSyntax> Folders = new List<FolderSyntax>(); | ||
|
||
public string InternalIdentifier { get; private set; } | ||
|
||
public PathCompilationSyntax() | ||
{ | ||
InternalIdentifier = Guid.NewGuid().ToString(); | ||
} | ||
|
||
public PathCompilationSyntax(string testCase) | ||
{ | ||
InternalIdentifier = $"{testCase}_{Guid.NewGuid()}"; | ||
} | ||
|
||
public PathCompilationSyntax AddFolders(params FolderSyntax[] foldersSyntax) | ||
{ | ||
this.Folders.AddRange(foldersSyntax); | ||
|
||
return this; | ||
} | ||
|
||
public PathCompilationSyntax AddFolder(FolderSyntax folderSyntax) | ||
{ | ||
this.Folders.Add(folderSyntax); | ||
|
||
return this; | ||
} | ||
|
||
public PathCompilationSyntax AddFolder(string name) | ||
{ | ||
this.Folders.Add(new FolderSyntax(name)); | ||
|
||
return this; | ||
} | ||
|
||
public PathCompilationSyntax CreateThreeFolder() | ||
{ | ||
foreach (ref var folder in CollectionsMarshal.AsSpan(Folders)) | ||
{ | ||
CreateThreeFolder(folder); | ||
} | ||
|
||
//TODO: Código temporário até o ConfigFactory ser implementado. | ||
File.Copy("./brconfig.json", $"./{InternalIdentifier}/brconfig.json", true); | ||
|
||
return this; | ||
} | ||
|
||
public PathCompilationSyntax CreateThreeFolder(FolderSyntax folderSyntax) | ||
{ | ||
if (folderSyntax is null) | ||
{ | ||
return this; | ||
} | ||
|
||
if (folderSyntax.Parent is not null) | ||
{ | ||
CreateThreeFolder(folderSyntax.Parent); | ||
} | ||
|
||
var dirPath = folderSyntax.Parent is not null | ||
? $"./{InternalIdentifier}/{folderSyntax.Parent.Name}/{folderSyntax.Name}" | ||
: $"./{InternalIdentifier}/{folderSyntax.Name}"; | ||
|
||
if (!Directory.Exists(dirPath)) | ||
{ | ||
Directory.CreateDirectory(dirPath); | ||
} | ||
|
||
foreach (ref var file in CollectionsMarshal.AsSpan(folderSyntax.Files)) | ||
{ | ||
File.WriteAllText($"{dirPath}/{file.Name}", file.Content); | ||
} | ||
|
||
return this; | ||
} | ||
} |
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,7 @@ | ||
namespace ByReplace.Test.Common.FolderMock; | ||
|
||
internal sealed class PathFactory | ||
{ | ||
public static PathCompilationSyntax Compile() => new PathCompilationSyntax(); | ||
public static PathCompilationSyntax Compile(string testCase) => new PathCompilationSyntax(testCase); | ||
} |
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,16 @@ | ||
{ | ||
"Path": "C:\\Users\\iel_1\\Documents\\TestLieu", | ||
"SkipDirectories": [ "bin", ".vs", "object", "git" ], | ||
"Rules": [ | ||
{ | ||
"Name": "RemoveServiceBus", | ||
"Description": "Substitui a implementação da mensageria para AwsEventBroker", | ||
"Skip": [ "Startup.cs", "Program.cs", "**/Controllers/*" ], | ||
"Extensions": [ ".cs", ".json" ], | ||
"Replacement": { | ||
"Old": [ "this._eventBus", "this.eventBus" ], | ||
"New": "this._awsEventBroker" | ||
} | ||
} | ||
] | ||
} |
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.