From 4e3acb3b9330a57ff9caf01eb4b710df13ae5fdc Mon Sep 17 00:00:00 2001 From: Daniel-iel Date: Wed, 1 May 2024 19:58:09 -0300 Subject: [PATCH] add alguns testes --- .../Rule/ListRules/ListRulesParameterTest.cs | 43 +++++++- .../Rule/ListRules/RulesBoxBuilderTest.cs | 17 --- .../Commands/Rule/ListRules/RulesBoxTest.cs | 102 ++++++++++++++++++ .../Rule/ListRules/ListRulesCommand.cs | 4 +- .../{PrintRuleBuilder.cs => RuleBox.cs} | 0 5 files changed, 145 insertions(+), 21 deletions(-) delete mode 100644 src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxBuilderTest.cs create mode 100644 src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs rename src/ByReplace/Commands/Rule/OpenRule/{PrintRuleBuilder.cs => RuleBox.cs} (100%) diff --git a/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs b/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs index 38f7562..76b58d2 100644 --- a/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs +++ b/src/ByReplace.Test/Commands/Rule/ListRules/ListRulesParameterTest.cs @@ -1,12 +1,51 @@ -using Xunit; +using ByReplace.Commands.Apply.Rule; +using ByReplace.Commands.Rule.ListRules; +using ByReplace.Test.Common.Helpers; +using Cocona; +using Xunit; namespace ByReplace.Test.Commands.Rule.ListRules; public class ListRulesParameterTest { [Fact] - public void Test1() + public void ListRulesParameter_ShouldValidateTheListRulesParameterHasInheritancesFromICommandParameterSet() { + // Arrange & Act + var metadata = FileInspect.GetInterfaces(); + // Assert + Assert.NotNull(metadata); + Assert.Equal(typeof(ICommandParameterSet), metadata.First()); + } + + [Fact] + public void ListRulesParameter_ShouldValidateThePropertiesConfiguration() + { + // Arrange & Act + var metadata = FileInspect.GetProperties(); + + // Assert + Assert.Single(metadata); + Assert.Collection(metadata, + entry => + { + var attributes = entry.GetCustomAttributes(false); + + Assert.Equal(typeof(string), entry.Name.GetType()); + Assert.Equal("ConfigFile", entry.Name); + Assert.Single(attributes); + Assert.Collection(attributes, + attribute => + { + var option = (OptionAttribute)attribute; + + Assert.Equal(typeof(OptionAttribute), attribute.GetType()); + Assert.Null(option.Name); + Assert.Equal("Path of the brconfig file.", option.Description); + Assert.Collection(option.ShortNames, + entry => Assert.Equal('f', entry)); + }); + }); } } diff --git a/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxBuilderTest.cs b/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxBuilderTest.cs deleted file mode 100644 index 1b725de..0000000 --- a/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxBuilderTest.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Xunit; - -namespace ByReplace.Test.Commands.Rule.ListRules; - -public class RulesBoxBuilderTest -{ - public RulesBoxBuilderTest() - { - - } - - [Fact] - public void Test1() - { - - } -} diff --git a/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs b/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs new file mode 100644 index 0000000..875f6ed --- /dev/null +++ b/src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs @@ -0,0 +1,102 @@ +using Xunit; +using ByReplace.Commands.Rule.ListRules; +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; +using System.Collections.Immutable; + +namespace ByReplace.Test.Commands.Rule.ListRules; + +public class RulesBoxTest +{ + private readonly PathCompilationSyntax _pathCompilationSyntax; + private readonly BrConfiguration _brConfiguration; + private readonly Mock _printMock; + + public RulesBoxTest() + { + _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(AnalyzerAndFixerTest)) + .AddMembers(rootFolder) + .AddBrConfiguration(configContent) + .Create(); + + _brConfiguration = BrConfigurationBuilder + .Create() + .SetPath($"./{_pathCompilationSyntax.InternalIdentifier}") + .SetConfigPath($"./{_pathCompilationSyntax.InternalIdentifier}") + .Build(); + } + + [Fact] + public void RulesBox_WhenInstantiate_ShouldValidateTheBoxConfiguration() + { + // Arrange & Act + var rulesBox = new RulesBox(_brConfiguration.Rules); + + // Assert + Assert.Equal(100, rulesBox.Width); + Assert.Equal(_brConfiguration.Rules.Count * 2, rulesBox.Height); + Assert.Equal("Rules", rulesBox.BoxName); + } + + [Fact] + public void RulesBox_WhenInstantiate_ShouldValidateIfTwoObjectWithTheSameParametersAreEquals() + { + // Arrange + var rulesBoxFirst = new RulesBox(_brConfiguration.Rules); + var rulesBoxSecond = new RulesBox(_brConfiguration.Rules); + + // Act + var isEquals = rulesBoxFirst.Equals(rulesBoxSecond); + var isEqualsLikeObject = rulesBoxFirst.Equals((object)rulesBoxSecond); + var hasTheSameHashcode = rulesBoxFirst.GetHashCode() == rulesBoxSecond.GetHashCode(); + + // Assert + Assert.Equal(rulesBoxSecond, rulesBoxFirst); + Assert.True(isEquals); + Assert.True(isEqualsLikeObject); + Assert.True(hasTheSameHashcode); + } + + [Fact] + public void RulesBox_WhenInstantiate_ShouldValidateIfTwoObjectWithTheSameParametersAreNotEquals() + { + // Arrange + var rulesBoxFirst = new RulesBox(_brConfiguration.Rules); + var rulesBoxSecond = new RulesBox(ImmutableList.Empty); + + // Act + var isEquals = rulesBoxFirst.Equals(rulesBoxSecond); + var isEqualsLikeObject = rulesBoxFirst.Equals((object)rulesBoxSecond); + var hasTheSameHashcode = rulesBoxFirst.GetHashCode() == rulesBoxSecond.GetHashCode(); + + // Assert + Assert.NotEqual(rulesBoxSecond, rulesBoxFirst); + Assert.False(isEquals); + Assert.False(isEqualsLikeObject); + Assert.False(hasTheSameHashcode); + } +} diff --git a/src/ByReplace/Commands/Rule/ListRules/ListRulesCommand.cs b/src/ByReplace/Commands/Rule/ListRules/ListRulesCommand.cs index f6d89cd..f723e74 100644 --- a/src/ByReplace/Commands/Rule/ListRules/ListRulesCommand.cs +++ b/src/ByReplace/Commands/Rule/ListRules/ListRulesCommand.cs @@ -13,9 +13,9 @@ public ListRulesCommand(BrConfiguration configuration, IPrintBox printBox) public ValueTask ExecuteAsync(CancellationToken cancellationToken = default) { - RulesBox builder = new RulesBox(configuration.Rules); + RulesBox rulesBox = new RulesBox(configuration.Rules); - printBox.CreateBoxAndPrint(builder); + printBox.CreateBoxAndPrint(rulesBox); return ValueTask.CompletedTask; } diff --git a/src/ByReplace/Commands/Rule/OpenRule/PrintRuleBuilder.cs b/src/ByReplace/Commands/Rule/OpenRule/RuleBox.cs similarity index 100% rename from src/ByReplace/Commands/Rule/OpenRule/PrintRuleBuilder.cs rename to src/ByReplace/Commands/Rule/OpenRule/RuleBox.cs