Skip to content

Commit

Permalink
add alguns testes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-iel committed May 1, 2024
1 parent a5e69a2 commit 4e3acb3
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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<ListRulesParameter>.GetInterfaces();

// Assert
Assert.NotNull(metadata);
Assert.Equal(typeof(ICommandParameterSet), metadata.First());
}

[Fact]
public void ListRulesParameter_ShouldValidateThePropertiesConfiguration()
{
// Arrange & Act
var metadata = FileInspect<ListRulesParameter>.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));
});
});
}
}
17 changes: 0 additions & 17 deletions src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxBuilderTest.cs

This file was deleted.

102 changes: 102 additions & 0 deletions src/ByReplace.Test/Commands/Rule/ListRules/RulesBoxTest.cs
Original file line number Diff line number Diff line change
@@ -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<IPrint> _printMock;

public RulesBoxTest()
{
_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(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<Models.Rule>.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);
}
}
4 changes: 2 additions & 2 deletions src/ByReplace/Commands/Rule/ListRules/ListRulesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4e3acb3

Please sign in to comment.